| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 67073c6 | 2021-03-01 09:18:21 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term * |
James Smart | 4ae2ebd | 2018-06-26 08:24:31 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 25 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <linux/pci.h> |
| 28 | #include <linux/kthread.h> |
| 29 | #include <linux/interrupt.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 30 | #include <linux/lockdep.h> |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 31 | #include <linux/utsname.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 33 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
| 36 | #include <scsi/scsi_transport_fc.h> |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 37 | #include <scsi/fc/fc_fs.h> |
| 38 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 41 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_disc.h" |
| 43 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 46 | #include "lpfc_scsi.h" |
| 47 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc_logmsg.h" |
| 49 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 50 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 51 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | |
| 53 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 54 | static uint8_t lpfcAlpaArray[] = { |
| 55 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 56 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 57 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 58 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 59 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 60 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 61 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 62 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 63 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 64 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 65 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 66 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 67 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 68 | }; |
| 69 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 70 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 71 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 72 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 73 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 74 | static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *); |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 75 | static void lpfc_check_inactive_vmid(struct lpfc_hba *phba); |
Gaurav Srivastava | 0c4792c | 2021-06-08 10:05:55 +0530 | [diff] [blame] | 76 | static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 77 | |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 78 | static int |
| 79 | lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp) |
| 80 | { |
| 81 | if (ndlp->nlp_fc4_type || |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame] | 82 | ndlp->nlp_type & NLP_FABRIC) |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 83 | return 1; |
| 84 | return 0; |
| 85 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 86 | /* The source of a terminate rport I/O is either a dev_loss_tmo |
| 87 | * event or a call to fc_remove_host. While the rport should be |
| 88 | * valid during these downcalls, the transport can call twice |
| 89 | * in a single event. This routine provides somoe protection |
| 90 | * as the NDLP isn't really free, just released to the pool. |
| 91 | */ |
| 92 | static int |
| 93 | lpfc_rport_invalid(struct fc_rport *rport) |
| 94 | { |
| 95 | struct lpfc_rport_data *rdata; |
| 96 | struct lpfc_nodelist *ndlp; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 97 | |
| 98 | if (!rport) { |
| 99 | pr_err("**** %s: NULL rport, exit.\n", __func__); |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | |
| 103 | rdata = rport->dd_data; |
| 104 | if (!rdata) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 105 | pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n", |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 106 | __func__, rport, rport->scsi_target_id); |
| 107 | return -EINVAL; |
| 108 | } |
| 109 | |
| 110 | ndlp = rdata->pnode; |
| 111 | if (!rdata->pnode) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 112 | pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n", |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 113 | __func__, rport, rport->scsi_target_id); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 117 | if (!ndlp->vport) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 118 | pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px " |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 119 | "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport, |
| 120 | rport->scsi_target_id); |
| 121 | return -EINVAL; |
| 122 | } |
| 123 | return 0; |
| 124 | } |
| 125 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 126 | void |
| 127 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 129 | struct lpfc_rport_data *rdata; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 130 | struct lpfc_nodelist *ndlp; |
| 131 | struct lpfc_vport *vport; |
| 132 | |
| 133 | if (lpfc_rport_invalid(rport)) |
| 134 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 136 | rdata = rport->dd_data; |
| 137 | ndlp = rdata->pnode; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 138 | vport = ndlp->vport; |
| 139 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 140 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 141 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 142 | |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 143 | if (ndlp->nlp_sid != NLP_NO_SID) |
| 144 | lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * This function will be called when dev_loss_tmo fire. |
| 149 | */ |
| 150 | void |
| 151 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 152 | { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 153 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 155 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 156 | struct lpfc_work_evt *evtp; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 157 | unsigned long iflags; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 158 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 159 | ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 160 | if (!ndlp) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 161 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 162 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 163 | vport = ndlp->vport; |
| 164 | phba = vport->phba; |
| 165 | |
| 166 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 167 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 168 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 169 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 170 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 171 | "3181 dev_loss_callbk x%06x, rport x%px flg x%x " |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 172 | "load_flag x%x refcnt %d\n", |
| 173 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag, |
| 174 | vport->load_flag, kref_read(&ndlp->kref)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 175 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 176 | /* Don't schedule a worker thread event if the vport is going down. |
| 177 | * The teardown process cleans up the node via lpfc_drop_node. |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 178 | */ |
| 179 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 180 | ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 181 | ndlp->rport = NULL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 182 | |
| 183 | ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; |
| 184 | |
| 185 | /* Remove the node reference from remote_port_add now. |
| 186 | * The driver will not call remote_port_delete. |
| 187 | */ |
| 188 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 189 | return; |
| 190 | } |
| 191 | |
| 192 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 193 | return; |
| 194 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 195 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 196 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 197 | "6789 rport name %llx != node port name %llx", |
| 198 | rport->port_name, |
| 199 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 200 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 201 | evtp = &ndlp->dev_loss_evt; |
| 202 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 203 | if (!list_empty(&evtp->evt_listp)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 204 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 205 | "6790 rport name %llx dev_loss_evt pending\n", |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 206 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 207 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 208 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 209 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 210 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 211 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 212 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 213 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 214 | /* |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 215 | * The backend does not expect any more calls associated with this |
| 216 | * rport. Remove the association between rport and ndlp. |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 217 | */ |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 218 | ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 219 | ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL; |
| 220 | ndlp->rport = NULL; |
| 221 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 222 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 223 | /* We need to hold the node by incrementing the reference |
| 224 | * count until this queued work is done |
| 225 | */ |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 226 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 227 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 228 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 229 | if (evtp->evt_arg1) { |
| 230 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 231 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 232 | lpfc_worker_wake_up(phba); |
| 233 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 234 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 235 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 239 | /** |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 240 | * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport |
| 241 | * @vport: Pointer to vport context object. |
| 242 | * |
| 243 | * This function checks for idle VMID entries related to a particular vport. If |
| 244 | * found unused/idle, free them accordingly. |
| 245 | **/ |
| 246 | static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport) |
| 247 | { |
| 248 | u16 keep; |
| 249 | u32 difftime = 0, r, bucket; |
| 250 | u64 *lta; |
| 251 | int cpu; |
| 252 | struct lpfc_vmid *vmp; |
| 253 | |
| 254 | write_lock(&vport->vmid_lock); |
| 255 | |
| 256 | if (!vport->cur_vmid_cnt) |
| 257 | goto out; |
| 258 | |
| 259 | /* iterate through the table */ |
| 260 | hash_for_each(vport->hash_table, bucket, vmp, hnode) { |
| 261 | keep = 0; |
| 262 | if (vmp->flag & LPFC_VMID_REGISTERED) { |
| 263 | /* check if the particular VMID is in use */ |
| 264 | /* for all available per cpu variable */ |
| 265 | for_each_possible_cpu(cpu) { |
| 266 | /* if last access time is less than timeout */ |
| 267 | lta = per_cpu_ptr(vmp->last_io_time, cpu); |
| 268 | if (!lta) |
| 269 | continue; |
| 270 | difftime = (jiffies) - (*lta); |
| 271 | if ((vport->vmid_inactivity_timeout * |
| 272 | JIFFIES_PER_HR) > difftime) { |
| 273 | keep = 1; |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /* if none of the cpus have been used by the vm, */ |
| 279 | /* remove the entry if already registered */ |
| 280 | if (!keep) { |
| 281 | /* mark the entry for deregistration */ |
| 282 | vmp->flag = LPFC_VMID_DE_REGISTER; |
| 283 | write_unlock(&vport->vmid_lock); |
| 284 | if (vport->vmid_priority_tagging) |
| 285 | r = lpfc_vmid_uvem(vport, vmp, false); |
| 286 | else |
| 287 | r = lpfc_vmid_cmd(vport, |
| 288 | SLI_CTAS_DAPP_IDENT, |
| 289 | vmp); |
| 290 | |
| 291 | /* decrement number of active vms and mark */ |
| 292 | /* entry in slot as free */ |
| 293 | write_lock(&vport->vmid_lock); |
| 294 | if (!r) { |
| 295 | struct lpfc_vmid *ht = vmp; |
| 296 | |
| 297 | vport->cur_vmid_cnt--; |
| 298 | ht->flag = LPFC_VMID_SLOT_FREE; |
| 299 | free_percpu(ht->last_io_time); |
| 300 | ht->last_io_time = NULL; |
| 301 | hash_del(&ht->hnode); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | out: |
| 307 | write_unlock(&vport->vmid_lock); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * lpfc_check_inactive_vmid - VMID inactivity checker |
| 312 | * @phba: Pointer to hba context object. |
| 313 | * |
| 314 | * This function is called from the worker thread to determine if an entry in |
| 315 | * the VMID table can be released since there was no I/O activity seen from that |
| 316 | * particular VM for the specified time. When this happens, the entry in the |
| 317 | * table is released and also the resources on the switch cleared. |
| 318 | **/ |
| 319 | |
| 320 | static void lpfc_check_inactive_vmid(struct lpfc_hba *phba) |
| 321 | { |
| 322 | struct lpfc_vport *vport; |
| 323 | struct lpfc_vport **vports; |
| 324 | int i; |
| 325 | |
| 326 | vports = lpfc_create_vport_work_array(phba); |
| 327 | if (!vports) |
| 328 | return; |
| 329 | |
| 330 | for (i = 0; i <= phba->max_vports; i++) { |
| 331 | if ((!vports[i]) && (i == 0)) |
| 332 | vport = phba->pport; |
| 333 | else |
| 334 | vport = vports[i]; |
| 335 | if (!vport) |
| 336 | break; |
| 337 | |
| 338 | lpfc_check_inactive_vmid_one(vport); |
| 339 | } |
| 340 | lpfc_destroy_vport_work_array(phba, vports); |
| 341 | } |
| 342 | |
| 343 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 344 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 345 | * @ndlp: Pointer to remote node object. |
| 346 | * |
| 347 | * This function is called from the worker thread when devloss timeout timer |
| 348 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 349 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 350 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 351 | * when devloss timeout happened to this @ndlp. |
| 352 | **/ |
| 353 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 354 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 355 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 356 | struct lpfc_vport *vport; |
| 357 | struct lpfc_hba *phba; |
| 358 | uint8_t *name; |
| 359 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 360 | int fcf_inuse = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 361 | unsigned long iflags; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 362 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 363 | vport = ndlp->vport; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 364 | name = (uint8_t *)&ndlp->nlp_portname; |
| 365 | phba = vport->phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 366 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 367 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 368 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 369 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 370 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 371 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 372 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 373 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 374 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 375 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 376 | ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 377 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 378 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 379 | "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n", |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 380 | __func__, ndlp->nlp_DID, ndlp->nlp_flag, |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 381 | ndlp->fc4_xpt_flags, kref_read(&ndlp->kref)); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 382 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 383 | /* If the driver is recovering the rport, ignore devloss. */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 384 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 385 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 386 | "0284 Devloss timeout Ignored on " |
| 387 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 388 | "NPort x%x\n", |
| 389 | *name, *(name+1), *(name+2), *(name+3), |
| 390 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 391 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 392 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 393 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 394 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 395 | /* Fabric nodes are done. */ |
| 396 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 397 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 398 | return fcf_inuse; |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 399 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 400 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 401 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 402 | warn_on = 1; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 403 | lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 405 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 406 | if (warn_on) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 407 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 408 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 409 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 410 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 411 | *name, *(name+1), *(name+2), *(name+3), |
| 412 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 413 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 414 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 415 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 416 | lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 417 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 418 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 419 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 420 | *name, *(name+1), *(name+2), *(name+3), |
| 421 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 422 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 423 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 424 | } |
| 425 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 426 | if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 427 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 428 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 429 | return fcf_inuse; |
| 430 | } |
| 431 | |
Gaurav Srivastava | 0c4792c | 2021-06-08 10:05:55 +0530 | [diff] [blame] | 432 | static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba) |
| 433 | { |
| 434 | struct lpfc_vport *vport; |
| 435 | struct lpfc_vport **vports; |
| 436 | int i; |
| 437 | |
| 438 | vports = lpfc_create_vport_work_array(phba); |
| 439 | if (!vports) |
| 440 | return; |
| 441 | |
| 442 | for (i = 0; i <= phba->max_vports; i++) { |
| 443 | if ((!vports[i]) && (i == 0)) |
| 444 | vport = phba->pport; |
| 445 | else |
| 446 | vport = vports[i]; |
| 447 | if (!vport) |
| 448 | break; |
| 449 | |
| 450 | if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) { |
| 451 | if (!lpfc_issue_els_qfpa(vport)) |
| 452 | vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA; |
| 453 | } |
| 454 | } |
| 455 | lpfc_destroy_vport_work_array(phba, vports); |
| 456 | } |
| 457 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 458 | /** |
| 459 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 460 | * @phba: Pointer to hba context object. |
| 461 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 462 | * @nlp_did: remote node identifer with devloss timeout. |
| 463 | * |
| 464 | * This function is called from the worker thread after invoking devloss |
| 465 | * timeout handler and releasing the reference count for the ndlp with |
| 466 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 467 | * timeout of the last remote node which had been in use of FCF, when this |
| 468 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 469 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 470 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 471 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 472 | * engine is in FCF discovery process, the devloss timeout state shall |
| 473 | * be set for either the FCF table scan process or roundrobin failover |
| 474 | * process to unregister the in-use FCF. |
| 475 | **/ |
| 476 | static void |
| 477 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 478 | uint32_t nlp_did) |
| 479 | { |
| 480 | /* If devloss timeout happened to a remote node when FCF had no |
| 481 | * longer been in-use, do nothing. |
| 482 | */ |
| 483 | if (!fcf_inuse) |
| 484 | return; |
| 485 | |
| 486 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 487 | spin_lock_irq(&phba->hbalock); |
| 488 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 489 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 490 | spin_unlock_irq(&phba->hbalock); |
| 491 | return; |
| 492 | } |
| 493 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 494 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 495 | "2847 Last remote node (x%x) using " |
| 496 | "FCF devloss tmo\n", nlp_did); |
| 497 | } |
| 498 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 499 | spin_unlock_irq(&phba->hbalock); |
| 500 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 501 | "2868 Devloss tmo to FCF rediscovery " |
| 502 | "in progress\n"); |
| 503 | return; |
| 504 | } |
| 505 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 506 | spin_unlock_irq(&phba->hbalock); |
| 507 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 508 | "2869 Devloss tmo to idle FIP engine, " |
| 509 | "unreg in-use FCF and rescan.\n"); |
| 510 | /* Unregister in-use FCF and rescan */ |
| 511 | lpfc_unregister_fcf_rescan(phba); |
| 512 | return; |
| 513 | } |
| 514 | spin_unlock_irq(&phba->hbalock); |
| 515 | if (phba->hba_flag & FCF_TS_INPROG) |
| 516 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 517 | "2870 FCF table scan in progress\n"); |
| 518 | if (phba->hba_flag & FCF_RR_INPROG) |
| 519 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 520 | "2871 FLOGI roundrobin FCF failover " |
| 521 | "in progress\n"); |
| 522 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 523 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 524 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 525 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 526 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 527 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 528 | * @phba: Pointer to hba context object. |
| 529 | * |
| 530 | * This function is called from the functions which need to post |
| 531 | * events from interrupt context. This function allocates data |
| 532 | * structure required for posting event. It also keeps track of |
| 533 | * number of events pending and prevent event storm when there are |
| 534 | * too many events. |
| 535 | **/ |
| 536 | struct lpfc_fast_path_event * |
| 537 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 538 | struct lpfc_fast_path_event *ret; |
| 539 | |
| 540 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 541 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 542 | return NULL; |
| 543 | |
| 544 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 545 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 546 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 547 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 548 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 549 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 550 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 551 | return ret; |
| 552 | } |
| 553 | |
| 554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 555 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 556 | * @phba: Pointer to hba context object. |
| 557 | * @evt: Event object which need to be freed. |
| 558 | * |
| 559 | * This function frees the data structure required for posting |
| 560 | * events. |
| 561 | **/ |
| 562 | void |
| 563 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 564 | struct lpfc_fast_path_event *evt) { |
| 565 | |
| 566 | atomic_dec(&phba->fast_event_count); |
| 567 | kfree(evt); |
| 568 | } |
| 569 | |
| 570 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 571 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 572 | * @phba: Pointer to hba context object. |
| 573 | * @evtp: Event data structure. |
| 574 | * |
| 575 | * This function is called from worker thread, when the interrupt |
| 576 | * context need to post an event. This function posts the event |
| 577 | * to fc transport netlink interface. |
| 578 | **/ |
| 579 | static void |
| 580 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 581 | struct lpfc_work_evt *evtp) |
| 582 | { |
| 583 | unsigned long evt_category, evt_sub_category; |
| 584 | struct lpfc_fast_path_event *fast_evt_data; |
| 585 | char *evt_data; |
| 586 | uint32_t evt_data_size; |
| 587 | struct Scsi_Host *shost; |
| 588 | |
| 589 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 590 | work_evt); |
| 591 | |
| 592 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 593 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 594 | fabric_evt.subcategory; |
| 595 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 596 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 597 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 598 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 599 | evt_data_size = sizeof(fast_evt_data->un. |
| 600 | read_check_error); |
| 601 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 602 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 603 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 604 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 605 | } else { |
| 606 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 607 | return; |
| 608 | } |
| 609 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 610 | switch (evt_sub_category) { |
| 611 | case LPFC_EVENT_QFULL: |
| 612 | case LPFC_EVENT_DEVBSY: |
| 613 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 614 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 615 | break; |
| 616 | case LPFC_EVENT_CHECK_COND: |
| 617 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 618 | evt_data_size = sizeof(fast_evt_data->un. |
| 619 | check_cond_evt); |
| 620 | break; |
| 621 | case LPFC_EVENT_VARQUEDEPTH: |
| 622 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 623 | evt_data_size = sizeof(fast_evt_data->un. |
| 624 | queue_depth_evt); |
| 625 | break; |
| 626 | default: |
| 627 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 628 | return; |
| 629 | } |
| 630 | } else { |
| 631 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 632 | return; |
| 633 | } |
| 634 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 635 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 636 | fc_host_post_vendor_event(shost, |
| 637 | fc_get_event_number(), |
| 638 | evt_data_size, |
| 639 | evt_data, |
| 640 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 641 | |
| 642 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 643 | return; |
| 644 | } |
| 645 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 647 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | { |
| 649 | struct lpfc_work_evt *evtp = NULL; |
| 650 | struct lpfc_nodelist *ndlp; |
| 651 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 652 | int fcf_inuse; |
| 653 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | spin_lock_irq(&phba->hbalock); |
| 656 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 658 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 661 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 663 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 664 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 665 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 666 | /* decrement the node reference count held |
| 667 | * for this queued work |
| 668 | */ |
| 669 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 670 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 671 | case LPFC_EVT_DEV_LOSS: |
| 672 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 673 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 674 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 675 | /* decrement the node reference count held for |
| 676 | * this queued work |
| 677 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 678 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 679 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 680 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 681 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 682 | fcf_inuse, |
| 683 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 684 | break; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 685 | case LPFC_EVT_RECOVER_PORT: |
| 686 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
| 687 | lpfc_sli_abts_recover_port(ndlp->vport, ndlp); |
| 688 | free_evt = 0; |
| 689 | /* decrement the node reference count held for |
| 690 | * this queued work |
| 691 | */ |
| 692 | lpfc_nlp_put(ndlp); |
| 693 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 695 | if (phba->link_state < LPFC_LINK_DOWN) |
| 696 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 697 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 698 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 699 | complete((struct completion *)(evtp->evt_arg2)); |
| 700 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 701 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 702 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 703 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 704 | *(int *)(evtp->evt_arg1) = 0; |
| 705 | complete((struct completion *)(evtp->evt_arg2)); |
| 706 | break; |
| 707 | case LPFC_EVT_OFFLINE: |
| 708 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 709 | lpfc_sli_brdrestart(phba); |
| 710 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 711 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 712 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 713 | complete((struct completion *)(evtp->evt_arg2)); |
| 714 | break; |
| 715 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 716 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 717 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 718 | lpfc_sli_brdreset(phba); |
| 719 | lpfc_hba_down_post(phba); |
| 720 | *(int *)(evtp->evt_arg1) = |
| 721 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 722 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 723 | complete((struct completion *)(evtp->evt_arg2)); |
| 724 | break; |
| 725 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 726 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 727 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 728 | = (phba->pport->stopped) |
| 729 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 730 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | complete((struct completion *)(evtp->evt_arg2)); |
| 732 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 733 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 734 | lpfc_send_fastpath_evt(phba, evtp); |
| 735 | free_evt = 0; |
| 736 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 737 | case LPFC_EVT_RESET_HBA: |
| 738 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 739 | lpfc_reset_hba(phba); |
| 740 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 741 | } |
| 742 | if (free_evt) |
| 743 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 744 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 746 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | |
| 748 | } |
| 749 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 750 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 751 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | { |
| 753 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 754 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 755 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 756 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 757 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 759 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | ha_copy = phba->work_ha; |
| 761 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 762 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 764 | /* First, try to post the next mailbox command to SLI4 device */ |
| 765 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 766 | lpfc_sli4_post_async_mbox(phba); |
| 767 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 768 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 769 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | lpfc_handle_eratt(phba); |
| 771 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 772 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | lpfc_sli_handle_mb_event(phba); |
| 774 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 775 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 777 | |
Gaurav Srivastava | 0c4792c | 2021-06-08 10:05:55 +0530 | [diff] [blame] | 778 | /* Handle VMID Events */ |
| 779 | if (lpfc_is_vmid_enabled(phba)) { |
| 780 | if (phba->pport->work_port_events & |
| 781 | WORKER_CHECK_VMID_ISSUE_QFPA) { |
| 782 | lpfc_check_vmid_qfpa_issue(phba); |
| 783 | phba->pport->work_port_events &= |
| 784 | ~WORKER_CHECK_VMID_ISSUE_QFPA; |
| 785 | } |
| 786 | if (phba->pport->work_port_events & |
| 787 | WORKER_CHECK_INACTIVE_VMID) { |
| 788 | lpfc_check_inactive_vmid(phba); |
| 789 | phba->pport->work_port_events &= |
| 790 | ~WORKER_CHECK_INACTIVE_VMID; |
| 791 | } |
| 792 | } |
| 793 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 794 | /* Process SLI4 events */ |
| 795 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 796 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 797 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 798 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 799 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 800 | if (phba->hba_flag & ASYNC_EVENT) |
| 801 | lpfc_sli4_async_event_proc(phba); |
| 802 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 803 | spin_lock_irq(&phba->hbalock); |
| 804 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 805 | spin_unlock_irq(&phba->hbalock); |
| 806 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 807 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 808 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 809 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 810 | } |
| 811 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 812 | vports = lpfc_create_vport_work_array(phba); |
| 813 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 814 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 815 | /* |
| 816 | * We could have no vports in array if unloading, so if |
| 817 | * this happens then just use the pport |
| 818 | */ |
| 819 | if (vports[i] == NULL && i == 0) |
| 820 | vport = phba->pport; |
| 821 | else |
| 822 | vport = vports[i]; |
| 823 | if (vport == NULL) |
| 824 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 825 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 826 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 827 | vport->work_port_events &= ~work_port_events; |
| 828 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 829 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 830 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 831 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 832 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 833 | if (work_port_events & WORKER_HB_TMO) |
| 834 | lpfc_hb_timeout_handler(phba); |
| 835 | if (work_port_events & WORKER_MBOX_TMO) |
| 836 | lpfc_mbox_timeout_handler(phba); |
| 837 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 838 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 839 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 840 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 841 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 842 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 843 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 844 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 846 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 847 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 848 | status >>= (4*LPFC_ELS_RING); |
James Smart | 0c9c6a7 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 849 | if (pring && (status & HA_RXMASK || |
| 850 | pring->flag & LPFC_DEFERRED_RING_EVENT || |
| 851 | phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 852 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 853 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 161df4f0 | 2018-01-30 15:58:54 -0800 | [diff] [blame] | 854 | /* Preserve legacy behavior. */ |
| 855 | if (!(phba->hba_flag & HBA_SP_QUEUE_EVT)) |
| 856 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 857 | } else { |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 858 | /* Driver could have abort request completed in queue |
| 859 | * when link goes down. Allow for this transition. |
| 860 | */ |
| 861 | if (phba->link_state >= LPFC_LINK_DOWN || |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 862 | phba->link_flag & LS_MDS_LOOPBACK) { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 863 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 864 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 865 | (status & |
| 866 | HA_RXMASK)); |
| 867 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 868 | } |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 869 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 870 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 871 | /* |
| 872 | * Turn on Ring interrupts |
| 873 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 874 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 875 | spin_lock_irq(&phba->hbalock); |
| 876 | control = readl(phba->HCregaddr); |
| 877 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 878 | lpfc_debugfs_slow_ring_trc(phba, |
| 879 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 880 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 881 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 882 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 883 | writel(control, phba->HCregaddr); |
| 884 | readl(phba->HCregaddr); /* flush */ |
| 885 | } else { |
| 886 | lpfc_debugfs_slow_ring_trc(phba, |
| 887 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 888 | control, ha_copy, 0); |
| 889 | } |
| 890 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | } |
| 892 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 893 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | } |
| 895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | int |
| 897 | lpfc_do_work(void *p) |
| 898 | { |
| 899 | struct lpfc_hba *phba = p; |
| 900 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 902 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 903 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 904 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 906 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 907 | /* wait and check worker queue activities */ |
| 908 | rc = wait_event_interruptible(phba->work_waitq, |
| 909 | (test_and_clear_bit(LPFC_DATA_READY, |
| 910 | &phba->data_flags) |
| 911 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 912 | /* Signal wakeup shall terminate the worker thread */ |
| 913 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 914 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 915 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 917 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 919 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 922 | phba->worker_thread = NULL; |
| 923 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 924 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * This is only called to handle FC worker events. Since this a rare |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 930 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | * embedding it in the IOCB. |
| 932 | */ |
| 933 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 934 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | uint32_t evt) |
| 936 | { |
| 937 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 938 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | |
| 940 | /* |
| 941 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 942 | * be queued to worker thread for processing |
| 943 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 944 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | if (!evtp) |
| 946 | return 0; |
| 947 | |
| 948 | evtp->evt_arg1 = arg1; |
| 949 | evtp->evt_arg2 = arg2; |
| 950 | evtp->evt = evt; |
| 951 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 952 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 953 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 954 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 956 | lpfc_worker_wake_up(phba); |
| 957 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | return 1; |
| 959 | } |
| 960 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | void |
| 962 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 963 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 964 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | struct lpfc_hba *phba = vport->phba; |
| 966 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | |
| 968 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 969 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 970 | continue; |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 971 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 972 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 973 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 974 | ((ndlp->nlp_DID == NameServer_DID) || |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame] | 975 | (ndlp->nlp_DID == FDMI_DID) || |
| 976 | (ndlp->nlp_DID == Fabric_Cntl_DID)))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 977 | lpfc_unreg_rpi(vport, ndlp); |
| 978 | |
| 979 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 980 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 981 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 982 | continue; |
James Smart | 4c2805a | 2020-03-31 09:50:10 -0700 | [diff] [blame] | 983 | |
| 984 | /* Notify transport of connectivity loss to trigger cleanup. */ |
| 985 | if (phba->nvmet_support && |
| 986 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
| 987 | lpfc_nvmet_invalidate_host(phba, ndlp); |
| 988 | |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 989 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 990 | remove |
| 991 | ? NLP_EVT_DEVICE_RM |
| 992 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 993 | } |
| 994 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 995 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 996 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 997 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 998 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1000 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1004 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1005 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1006 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 1007 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 1008 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1009 | /* Cleanup any outstanding received buffers */ |
| 1010 | lpfc_cleanup_rcv_buffers(vport); |
| 1011 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1012 | /* Cleanup any outstanding RSCN activity */ |
| 1013 | lpfc_els_flush_rscn(vport); |
| 1014 | |
| 1015 | /* Cleanup any outstanding ELS commands */ |
| 1016 | lpfc_els_flush_cmd(vport); |
| 1017 | |
| 1018 | lpfc_cleanup_rpis(vport, 0); |
| 1019 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1020 | /* Turn off discovery timer if its running */ |
| 1021 | lpfc_can_disctmo(vport); |
| 1022 | } |
| 1023 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1024 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1025 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 1026 | { |
| 1027 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1028 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1029 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1030 | fc_host_post_event(shost, fc_get_event_number(), |
| 1031 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1032 | |
| 1033 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1034 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 1035 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 1036 | |
| 1037 | lpfc_port_link_failure(vport); |
| 1038 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 1039 | /* Stop delayed Nport discovery */ |
| 1040 | spin_lock_irq(shost->host_lock); |
| 1041 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 1042 | spin_unlock_irq(shost->host_lock); |
| 1043 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1044 | } |
| 1045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1047 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | struct lpfc_vport *vport = phba->pport; |
| 1050 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1051 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1052 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1053 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1054 | |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 1055 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1056 | return 0; |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 1057 | |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 1058 | /* Block all SCSI stack I/Os */ |
| 1059 | lpfc_scsi_dev_block(phba); |
| 1060 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1061 | phba->defer_flogi_acc_flag = false; |
| 1062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1064 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 1065 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1066 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1067 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 1068 | if (phba->sli4_hba.conf_trunk) { |
| 1069 | phba->trunk_link.link0.state = 0; |
| 1070 | phba->trunk_link.link1.state = 0; |
| 1071 | phba->trunk_link.link2.state = 0; |
| 1072 | phba->trunk_link.link3.state = 0; |
James Smart | 845d032 | 2019-08-14 16:57:01 -0700 | [diff] [blame] | 1073 | phba->sli4_hba.link_state.logical_speed = |
| 1074 | LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 1075 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 1076 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1077 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 1078 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1079 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1080 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1081 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1082 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1083 | /* Issue a LINK DOWN event to all nodes */ |
| 1084 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1085 | |
| 1086 | vports[i]->fc_myDID = 0; |
| 1087 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1088 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 1089 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 1090 | if (phba->nvmet_support) |
| 1091 | lpfc_nvmet_update_targetport(phba); |
| 1092 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 1093 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 1094 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1095 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1096 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1097 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 1098 | |
| 1099 | /* Clean up any SLI3 firmware default rpi's */ |
| 1100 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 1101 | goto skip_unreg_did; |
| 1102 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1104 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1105 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1106 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1107 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1108 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 1114 | skip_unreg_did: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1116 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1117 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1118 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1119 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1120 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1121 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1122 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1123 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1124 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | } |
| 1126 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1128 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1129 | phba->pport->rcv_flogi_cnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1130 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1131 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1132 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | } |
| 1134 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1135 | static void |
| 1136 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1137 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1138 | struct lpfc_nodelist *ndlp; |
| 1139 | |
| 1140 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | a3da825 | 2018-03-05 12:04:06 -0800 | [diff] [blame] | 1141 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1142 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1143 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1144 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1145 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1146 | /* On Linkup its safe to clean up the ndlp |
| 1147 | * from Fabric connections. |
| 1148 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1149 | if (ndlp->nlp_DID != Fabric_DID) |
| 1150 | lpfc_unreg_rpi(vport, ndlp); |
| 1151 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 1152 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1153 | /* Fail outstanding IO now since device is |
| 1154 | * marked for PLOGI. |
| 1155 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1156 | lpfc_unreg_rpi(vport, ndlp); |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | static void |
| 1162 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 1163 | { |
| 1164 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1165 | struct lpfc_hba *phba = vport->phba; |
| 1166 | |
| 1167 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 1168 | return; |
| 1169 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1170 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1171 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 1172 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 1173 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1174 | /* If NPIV is not enabled, only bring the physical port up */ |
| 1175 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1176 | (vport != phba->pport)) |
| 1177 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1179 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1180 | fc_host_post_event(shost, fc_get_event_number(), |
| 1181 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1182 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1183 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1184 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1185 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1186 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1187 | vport->fc_ns_retry = 0; |
| 1188 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 1190 | lpfc_linkup_cleanup_nodes(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static int |
| 1194 | lpfc_linkup(struct lpfc_hba *phba) |
| 1195 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1196 | struct lpfc_vport **vports; |
| 1197 | int i; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1198 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1199 | |
| 1200 | phba->link_state = LPFC_LINK_UP; |
| 1201 | |
| 1202 | /* Unblock fabric iocbs if they are blocked */ |
| 1203 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1204 | del_timer_sync(&phba->fabric_block_timer); |
| 1205 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1206 | vports = lpfc_create_vport_work_array(phba); |
| 1207 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1208 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1209 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1210 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1212 | /* Clear the pport flogi counter in case the link down was |
| 1213 | * absorbed without an ACQE. No lock here - in worker thread |
| 1214 | * and discovery is synchronized. |
| 1215 | */ |
| 1216 | spin_lock_irq(shost->host_lock); |
| 1217 | phba->pport->rcv_flogi_cnt = 0; |
| 1218 | spin_unlock_irq(shost->host_lock); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1219 | |
| 1220 | /* reinitialize initial FLOGI flag */ |
| 1221 | phba->hba_flag &= ~(HBA_FLOGI_ISSUED); |
| 1222 | phba->defer_flogi_acc_flag = false; |
| 1223 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | /* |
| 1228 | * This routine handles processing a CLEAR_LA mailbox |
| 1229 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1230 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1231 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1233 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1234 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1236 | struct lpfc_vport *vport = pmb->vport; |
| 1237 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1238 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1239 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1240 | uint32_t control; |
| 1241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1242 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1243 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1244 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | |
| 1246 | /* Check for error */ |
| 1247 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1248 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1249 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1250 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1251 | "state x%x\n", |
| 1252 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1253 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | goto out; |
| 1255 | } |
| 1256 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1257 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1258 | phba->link_state = LPFC_HBA_READY; |
| 1259 | |
| 1260 | spin_lock_irq(&phba->hbalock); |
| 1261 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1262 | control = readl(phba->HCregaddr); |
| 1263 | control |= HC_LAINT_ENA; |
| 1264 | writel(control, phba->HCregaddr); |
| 1265 | readl(phba->HCregaddr); /* flush */ |
| 1266 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1267 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1268 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | out: |
| 1271 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1273 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1274 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1277 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1278 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | |
| 1282 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1283 | |
| 1284 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1286 | control = readl(phba->HCregaddr); |
| 1287 | control |= HC_LAINT_ENA; |
| 1288 | writel(control, phba->HCregaddr); |
| 1289 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1290 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | |
| 1292 | return; |
| 1293 | } |
| 1294 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1295 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1296 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1298 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1299 | LPFC_MBOXQ_t *sparam_mb; |
| 1300 | struct lpfc_dmabuf *sparam_mp; |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1301 | u16 status = pmb->u.mb.mbxStatus; |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1302 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1304 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1305 | |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1306 | if (status) |
| 1307 | goto out; |
| 1308 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1309 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1310 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1311 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1312 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1313 | return; |
| 1314 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1315 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1316 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1317 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1318 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1319 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1320 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1321 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1322 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1323 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1324 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1326 | /* Start discovery by sending a FLOGI. port_state is identically |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1327 | * LPFC_FLOGI while waiting for FLOGI cmpl. |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1328 | */ |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1329 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1330 | /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if |
| 1331 | * bb-credit recovery is in place. |
| 1332 | */ |
| 1333 | if (phba->bbcredit_support && phba->cfg_enable_bbcr && |
| 1334 | !(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 1335 | sparam_mb = mempool_alloc(phba->mbox_mem_pool, |
| 1336 | GFP_KERNEL); |
| 1337 | if (!sparam_mb) |
| 1338 | goto sparam_out; |
| 1339 | |
| 1340 | rc = lpfc_read_sparam(phba, sparam_mb, 0); |
| 1341 | if (rc) { |
| 1342 | mempool_free(sparam_mb, phba->mbox_mem_pool); |
| 1343 | goto sparam_out; |
| 1344 | } |
| 1345 | sparam_mb->vport = vport; |
| 1346 | sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 1347 | rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT); |
| 1348 | if (rc == MBX_NOT_FINISHED) { |
| 1349 | sparam_mp = (struct lpfc_dmabuf *) |
| 1350 | sparam_mb->ctx_buf; |
| 1351 | lpfc_mbuf_free(phba, sparam_mp->virt, |
| 1352 | sparam_mp->phys); |
| 1353 | kfree(sparam_mp); |
| 1354 | sparam_mb->ctx_buf = NULL; |
| 1355 | mempool_free(sparam_mb, phba->mbox_mem_pool); |
| 1356 | goto sparam_out; |
| 1357 | } |
| 1358 | |
| 1359 | phba->hba_flag |= HBA_DEFER_FLOGI; |
| 1360 | } else { |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1361 | lpfc_initial_flogi(vport); |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1362 | } |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1363 | } else { |
| 1364 | if (vport->fc_flag & FC_PT2PT) |
| 1365 | lpfc_disc_start(vport); |
| 1366 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1367 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | |
| 1369 | out: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1370 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1371 | "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n", |
| 1372 | status, vport->port_state); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1373 | |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1374 | sparam_out: |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1375 | lpfc_linkdown(phba); |
| 1376 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1377 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1378 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1379 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1381 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | return; |
| 1383 | } |
| 1384 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1385 | /** |
| 1386 | * lpfc_sli4_clear_fcf_rr_bmask |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1387 | * @phba: pointer to the struct lpfc_hba for this port. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1388 | * This fucnction resets the round robin bit mask and clears the |
| 1389 | * fcf priority list. The list deletions are done while holding the |
| 1390 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1391 | * from the lpfc_fcf_pri record. |
| 1392 | **/ |
| 1393 | void |
| 1394 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1395 | { |
| 1396 | struct lpfc_fcf_pri *fcf_pri; |
| 1397 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1398 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1399 | spin_lock_irq(&phba->hbalock); |
| 1400 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1401 | &phba->fcf.fcf_pri_list, list) { |
| 1402 | list_del_init(&fcf_pri->list); |
| 1403 | fcf_pri->fcf_rec.flag = 0; |
| 1404 | } |
| 1405 | spin_unlock_irq(&phba->hbalock); |
| 1406 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1408 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1409 | { |
| 1410 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1411 | |
| 1412 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1413 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1414 | "2017 REG_FCFI mbxStatus error x%x " |
| 1415 | "HBA state x%x\n", mboxq->u.mb.mbxStatus, |
| 1416 | vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1417 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1421 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1422 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1423 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1424 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1425 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1426 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1427 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1428 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1429 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1430 | goto fail_out; |
| 1431 | |
| 1432 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1433 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1434 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1435 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1436 | if (vport->port_state != LPFC_FLOGI) { |
| 1437 | phba->hba_flag |= FCF_RR_INPROG; |
| 1438 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1439 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1440 | goto out; |
| 1441 | } |
| 1442 | spin_unlock_irq(&phba->hbalock); |
| 1443 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1444 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1445 | fail_out: |
| 1446 | spin_lock_irq(&phba->hbalock); |
| 1447 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1448 | spin_unlock_irq(&phba->hbalock); |
| 1449 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1450 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1455 | * @fab_name: pointer to fabric name. |
| 1456 | * @new_fcf_record: pointer to fcf record. |
| 1457 | * |
| 1458 | * This routine compare the fcf record's fabric name with provided |
| 1459 | * fabric name. If the fabric name are identical this function |
| 1460 | * returns 1 else return 0. |
| 1461 | **/ |
| 1462 | static uint32_t |
| 1463 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1464 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1465 | if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1466 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1467 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1468 | return 0; |
| 1469 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1470 | return 0; |
| 1471 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1472 | return 0; |
| 1473 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1474 | return 0; |
| 1475 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1476 | return 0; |
| 1477 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1478 | return 0; |
| 1479 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1480 | return 0; |
| 1481 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1485 | * lpfc_sw_name_match - Check if the fcf switch name match. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1486 | * @sw_name: pointer to switch name. |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1487 | * @new_fcf_record: pointer to fcf record. |
| 1488 | * |
| 1489 | * This routine compare the fcf record's switch name with provided |
| 1490 | * switch name. If the switch name are identical this function |
| 1491 | * returns 1 else return 0. |
| 1492 | **/ |
| 1493 | static uint32_t |
| 1494 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1495 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1496 | if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1497 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1498 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1499 | return 0; |
| 1500 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1501 | return 0; |
| 1502 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1503 | return 0; |
| 1504 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1505 | return 0; |
| 1506 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1507 | return 0; |
| 1508 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1509 | return 0; |
| 1510 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1511 | return 0; |
| 1512 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1516 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1517 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1518 | * @new_fcf_record: pointer to fcf record. |
| 1519 | * |
| 1520 | * This routine compare the fcf record's mac address with HBA's |
| 1521 | * FCF mac address. If the mac addresses are identical this function |
| 1522 | * returns 1 else return 0. |
| 1523 | **/ |
| 1524 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1525 | lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1526 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1527 | if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1528 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1529 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1530 | return 0; |
| 1531 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1532 | return 0; |
| 1533 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1534 | return 0; |
| 1535 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1536 | return 0; |
| 1537 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1538 | return 0; |
| 1539 | return 1; |
| 1540 | } |
| 1541 | |
| 1542 | static bool |
| 1543 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1544 | { |
| 1545 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1549 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1550 | * @phba: pointer to lpfc hba data structure. |
| 1551 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1552 | * @new_fcf_record: pointer to hba fcf record. |
| 1553 | * |
| 1554 | * This routine updates the driver FCF priority record from the new HBA FCF |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1555 | * record. The hbalock is asserted held in the code path calling this |
| 1556 | * routine. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1557 | **/ |
| 1558 | static void |
| 1559 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1560 | struct fcf_record *new_fcf_record |
| 1561 | ) |
| 1562 | { |
| 1563 | struct lpfc_fcf_pri *fcf_pri; |
| 1564 | |
| 1565 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1566 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1567 | /* FCF record priority */ |
| 1568 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1569 | |
| 1570 | } |
| 1571 | |
| 1572 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1573 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1574 | * @fcf_rec: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1575 | * @new_fcf_record: pointer to fcf record. |
| 1576 | * |
| 1577 | * This routine copies the FCF information from the FCF |
| 1578 | * record to lpfc_hba data structure. |
| 1579 | **/ |
| 1580 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1581 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1582 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1583 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1584 | /* Fabric name */ |
| 1585 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1586 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1587 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1588 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1589 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1590 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1591 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1592 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1593 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1594 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1595 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1596 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1597 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1598 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1599 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1600 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1601 | /* Mac address */ |
| 1602 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1603 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1604 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1605 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1606 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1607 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1608 | /* FCF record index */ |
| 1609 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1610 | /* FCF record priority */ |
| 1611 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1612 | /* Switch name */ |
| 1613 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1614 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1615 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1616 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1617 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1618 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1619 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1620 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1621 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1622 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1623 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1624 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1625 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1626 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1627 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1628 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | /** |
Lee Jones | 3884ce1 | 2021-03-03 14:46:28 +0000 | [diff] [blame] | 1632 | * __lpfc_update_fcf_record - Update driver fcf record |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1633 | * @phba: pointer to lpfc hba data structure. |
| 1634 | * @fcf_rec: pointer to driver fcf record. |
| 1635 | * @new_fcf_record: pointer to hba fcf record. |
| 1636 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1637 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1638 | * @flag: flag bits to be set to the driver fcf record. |
| 1639 | * |
| 1640 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1641 | * together with the address mode, vlan_id, and other informations. This |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1642 | * routine is called with the hbalock held. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1643 | **/ |
| 1644 | static void |
| 1645 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1646 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1647 | uint16_t vlan_id, uint32_t flag) |
| 1648 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1649 | lockdep_assert_held(&phba->hbalock); |
| 1650 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1651 | /* Copy the fields from the HBA's FCF record */ |
| 1652 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1653 | /* Update other fields of driver FCF record */ |
| 1654 | fcf_rec->addr_mode = addr_mode; |
| 1655 | fcf_rec->vlan_id = vlan_id; |
| 1656 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1657 | __lpfc_update_fcf_record_pri(phba, |
| 1658 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1659 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1663 | * lpfc_register_fcf - Register the FCF with hba. |
| 1664 | * @phba: pointer to lpfc hba data structure. |
| 1665 | * |
| 1666 | * This routine issues a register fcfi mailbox command to register |
| 1667 | * the fcf with HBA. |
| 1668 | **/ |
| 1669 | static void |
| 1670 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1671 | { |
| 1672 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1673 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1674 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1675 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1676 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1677 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1678 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1679 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | /* The FCF is already registered, start discovery */ |
| 1684 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1685 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1686 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1687 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1688 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1689 | phba->hba_flag |= FCF_RR_INPROG; |
| 1690 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1691 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1692 | return; |
| 1693 | } |
| 1694 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1695 | return; |
| 1696 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1697 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1698 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1699 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1700 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1701 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1702 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1703 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1704 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1705 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1706 | |
| 1707 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1708 | fcf_mbxq->vport = phba->pport; |
| 1709 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1710 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1711 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1712 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1713 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1714 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1715 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1716 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1717 | |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1723 | * @phba: pointer to lpfc hba data structure. |
| 1724 | * @new_fcf_record: pointer to fcf record. |
| 1725 | * @boot_flag: Indicates if this record used by boot bios. |
| 1726 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1727 | * @vlan_id: The vlan id to be used as vlan tagging by this FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1728 | * |
| 1729 | * This routine compare the fcf record with connect list obtained from the |
| 1730 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1731 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1732 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1733 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1734 | * used for this FCF when the function returns. |
| 1735 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1736 | * set in the vlan_id on return of the function. If not VLAN tagging need to |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1737 | * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1738 | **/ |
| 1739 | static int |
| 1740 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1741 | struct fcf_record *new_fcf_record, |
| 1742 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1743 | uint16_t *vlan_id) |
| 1744 | { |
| 1745 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1746 | int i, j, fcf_vlan_id = 0; |
| 1747 | |
| 1748 | /* Find the lowest VLAN id in the FCF record */ |
| 1749 | for (i = 0; i < 512; i++) { |
| 1750 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1751 | fcf_vlan_id = i * 8; |
| 1752 | j = 0; |
| 1753 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1754 | j++; |
| 1755 | fcf_vlan_id++; |
| 1756 | } |
| 1757 | break; |
| 1758 | } |
| 1759 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1760 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1761 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1762 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1763 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1764 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1765 | return 0; |
| 1766 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1767 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1768 | *boot_flag = 0; |
| 1769 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1770 | new_fcf_record); |
| 1771 | if (phba->valid_vlan) |
| 1772 | *vlan_id = phba->vlan_id; |
| 1773 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1774 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1775 | return 1; |
| 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | * If there are no FCF connection table entry, driver connect to all |
| 1780 | * FCFs. |
| 1781 | */ |
| 1782 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1783 | *boot_flag = 0; |
| 1784 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1785 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1786 | |
| 1787 | /* |
| 1788 | * When there are no FCF connect entries, use driver's default |
| 1789 | * addressing mode - FPMA. |
| 1790 | */ |
| 1791 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1792 | *addr_mode = LPFC_FCF_FPMA; |
| 1793 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1794 | /* If FCF record report a vlan id use that vlan id */ |
| 1795 | if (fcf_vlan_id) |
| 1796 | *vlan_id = fcf_vlan_id; |
| 1797 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1798 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
| 1801 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1802 | list_for_each_entry(conn_entry, |
| 1803 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1804 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1805 | continue; |
| 1806 | |
| 1807 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1808 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1809 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1810 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1811 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1812 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1813 | new_fcf_record)) |
| 1814 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1815 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1816 | /* |
| 1817 | * If the vlan bit map does not have the bit set for the |
| 1818 | * vlan id to be used, then it is not a match. |
| 1819 | */ |
| 1820 | if (!(new_fcf_record->vlan_bitmap |
| 1821 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1822 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1823 | continue; |
| 1824 | } |
| 1825 | |
| 1826 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1827 | * If connection record does not support any addressing mode, |
| 1828 | * skip the FCF record. |
| 1829 | */ |
| 1830 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1831 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1832 | continue; |
| 1833 | |
| 1834 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1835 | * Check if the connection record specifies a required |
| 1836 | * addressing mode. |
| 1837 | */ |
| 1838 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1839 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1840 | |
| 1841 | /* |
| 1842 | * If SPMA required but FCF not support this continue. |
| 1843 | */ |
| 1844 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1845 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1846 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1847 | continue; |
| 1848 | |
| 1849 | /* |
| 1850 | * If FPMA required but FCF not support this continue. |
| 1851 | */ |
| 1852 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1853 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1854 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1855 | continue; |
| 1856 | } |
| 1857 | |
| 1858 | /* |
| 1859 | * This fcf record matches filtering criteria. |
| 1860 | */ |
| 1861 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1862 | *boot_flag = 1; |
| 1863 | else |
| 1864 | *boot_flag = 0; |
| 1865 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1866 | /* |
| 1867 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1868 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1869 | * by FCF, allow fabric to pick the addressing mode. |
| 1870 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1871 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1872 | new_fcf_record); |
| 1873 | /* |
| 1874 | * If the user specified a required address mode, assign that |
| 1875 | * address mode |
| 1876 | */ |
| 1877 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1878 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1879 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1880 | FCFCNCT_AM_SPMA) ? |
| 1881 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1882 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1883 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1884 | * addr mode only if FCF support the addr_mode. |
| 1885 | */ |
| 1886 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1887 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1888 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1889 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1890 | *addr_mode = LPFC_FCF_SPMA; |
| 1891 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1892 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1893 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1894 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1895 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1896 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1897 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1898 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1899 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1900 | /* |
| 1901 | * If no vlan id is specified in connect list, use the vlan id |
| 1902 | * in the FCF record |
| 1903 | */ |
| 1904 | else if (fcf_vlan_id) |
| 1905 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1906 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1907 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1908 | |
| 1909 | return 1; |
| 1910 | } |
| 1911 | |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
| 1915 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1916 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1917 | * @phba: pointer to lpfc hba data structure. |
| 1918 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1919 | * |
| 1920 | * This function check if there is any fcoe event pending while driver |
| 1921 | * scan FCF entries. If there is any pending event, it will restart the |
| 1922 | * FCF saning and return 1 else return 0. |
| 1923 | */ |
| 1924 | int |
| 1925 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1926 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1927 | /* |
| 1928 | * If the Link is up and no FCoE events while in the |
| 1929 | * FCF discovery, no need to restart FCF discovery. |
| 1930 | */ |
| 1931 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1932 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1933 | return 0; |
| 1934 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1935 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1936 | "2768 Pending link or FCF event during current " |
| 1937 | "handling of the previous event: link_state:x%x, " |
| 1938 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1939 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1940 | phba->fcoe_eventtag); |
| 1941 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1942 | spin_lock_irq(&phba->hbalock); |
| 1943 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1944 | spin_unlock_irq(&phba->hbalock); |
| 1945 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1946 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1947 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1948 | "2780 Restart FCF table scan due to " |
| 1949 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1950 | "evt_tag_current:x%x\n", |
| 1951 | phba->fcoe_eventtag_at_fcf_scan, |
| 1952 | phba->fcoe_eventtag); |
| 1953 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1954 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1955 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1956 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1957 | * flag |
| 1958 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1959 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1960 | "2833 Stop FCF discovery process due to link " |
| 1961 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1962 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1963 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1964 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1965 | spin_unlock_irq(&phba->hbalock); |
| 1966 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1967 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1968 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1969 | if (unreg_fcf) { |
| 1970 | spin_lock_irq(&phba->hbalock); |
| 1971 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1972 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1973 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1974 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1975 | return 1; |
| 1976 | } |
| 1977 | |
| 1978 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1979 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1980 | * @phba: pointer to lpfc hba data structure. |
| 1981 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1982 | * |
| 1983 | * This function makes an running random selection decision on FCF record to |
| 1984 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1985 | * probability. To perform integer manunipulation of random numbers with |
| 1986 | * size unit32_t, the lower 16 bits of the 32-bit random number returned |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1987 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1988 | * |
| 1989 | * Returns true when outcome is for the newly read FCF record should be |
| 1990 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1991 | * chosen FCF record. |
| 1992 | **/ |
| 1993 | static bool |
| 1994 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1995 | { |
| 1996 | uint32_t rand_num; |
| 1997 | |
| 1998 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1999 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2000 | |
| 2001 | /* Decision with probability 1/fcf_cnt */ |
| 2002 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 2003 | return true; |
| 2004 | else |
| 2005 | return false; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2009 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2010 | * @phba: pointer to lpfc hba data structure. |
| 2011 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2012 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2013 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2014 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 2015 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 2016 | * SGE parsing, and endianness swapping. |
| 2017 | * |
| 2018 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 2019 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2020 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2021 | static struct fcf_record * |
| 2022 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 2023 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2024 | { |
| 2025 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2026 | struct lpfc_mbx_sge sge; |
| 2027 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 2028 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2029 | union lpfc_sli4_cfg_shdr *shdr; |
| 2030 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2031 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2032 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 2033 | * routine only uses a single SGE. |
| 2034 | */ |
| 2035 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2036 | if (unlikely(!mboxq->sge_array)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2037 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2038 | "2524 Failed to get the non-embedded SGE " |
| 2039 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2040 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2041 | } |
| 2042 | virt_addr = mboxq->sge_array->addr[0]; |
| 2043 | |
| 2044 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 2045 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 2046 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2047 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 2048 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2049 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2050 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 2051 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 2052 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2053 | lpfc_printf_log(phba, KERN_ERR, |
| 2054 | LOG_TRACE_EVENT, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2055 | "2726 READ_FCF_RECORD Indicates empty " |
| 2056 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2057 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2058 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2059 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2060 | "with status x%x add_status x%x, " |
| 2061 | "mbx\n", shdr_status, shdr_add_status); |
| 2062 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2063 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2064 | |
| 2065 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2066 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 2067 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 2068 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2069 | *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2070 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 2071 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 2072 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 2073 | offsetof(struct fcf_record, vlan_bitmap)); |
| 2074 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 2075 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2076 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2077 | return new_fcf_record; |
| 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 2082 | * @phba: pointer to lpfc hba data structure. |
| 2083 | * @fcf_record: pointer to the fcf record. |
| 2084 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 2085 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 2086 | * |
| 2087 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 2088 | * enabled. |
| 2089 | **/ |
| 2090 | static void |
| 2091 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 2092 | struct fcf_record *fcf_record, |
| 2093 | uint16_t vlan_id, |
| 2094 | uint16_t next_fcf_index) |
| 2095 | { |
| 2096 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2097 | "2764 READ_FCF_RECORD:\n" |
| 2098 | "\tFCF_Index : x%x\n" |
| 2099 | "\tFCF_Avail : x%x\n" |
| 2100 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2101 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2102 | "\tFIP_Priority : x%x\n" |
| 2103 | "\tMAC_Provider : x%x\n" |
| 2104 | "\tLowest VLANID : x%x\n" |
| 2105 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 2106 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 2107 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 2108 | "\tNext_FCF_Index: x%x\n", |
| 2109 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 2110 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 2111 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2112 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2113 | fcf_record->fip_priority, |
| 2114 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 2115 | vlan_id, |
| 2116 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 2117 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 2118 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 2119 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 2120 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 2121 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 2122 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 2123 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 2124 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 2125 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 2126 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 2127 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 2128 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 2129 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 2130 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 2131 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 2132 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 2133 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 2134 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 2135 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 2136 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 2137 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 2138 | next_fcf_index); |
| 2139 | } |
| 2140 | |
| 2141 | /** |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2142 | * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2143 | * @phba: pointer to lpfc hba data structure. |
| 2144 | * @fcf_rec: pointer to an existing FCF record. |
| 2145 | * @new_fcf_record: pointer to a new FCF record. |
| 2146 | * @new_vlan_id: vlan id from the new FCF record. |
| 2147 | * |
| 2148 | * This function performs matching test of a new FCF record against an existing |
| 2149 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 2150 | * will not be used as part of the FCF record matching criteria. |
| 2151 | * |
| 2152 | * Returns true if all the fields matching, otherwise returns false. |
| 2153 | */ |
| 2154 | static bool |
| 2155 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 2156 | struct lpfc_fcf_rec *fcf_rec, |
| 2157 | struct fcf_record *new_fcf_record, |
| 2158 | uint16_t new_vlan_id) |
| 2159 | { |
| 2160 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 2161 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 2162 | return false; |
| 2163 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 2164 | return false; |
| 2165 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 2166 | return false; |
| 2167 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 2168 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2169 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 2170 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2171 | return true; |
| 2172 | } |
| 2173 | |
| 2174 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2175 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 2176 | * @vport: Pointer to vport object. |
| 2177 | * @fcf_index: index to next fcf. |
| 2178 | * |
| 2179 | * This function processing the roundrobin fcf failover to next fcf index. |
| 2180 | * When this function is invoked, there will be a current fcf registered |
| 2181 | * for flogi. |
| 2182 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 2183 | * 1 for stop flogi on currently registered fcf; |
| 2184 | */ |
| 2185 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 2186 | { |
| 2187 | struct lpfc_hba *phba = vport->phba; |
| 2188 | int rc; |
| 2189 | |
| 2190 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 2191 | spin_lock_irq(&phba->hbalock); |
| 2192 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2193 | spin_unlock_irq(&phba->hbalock); |
| 2194 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2195 | "2872 Devloss tmo with no eligible " |
| 2196 | "FCF, unregister in-use FCF (x%x) " |
| 2197 | "and rescan FCF table\n", |
| 2198 | phba->fcf.current_rec.fcf_indx); |
| 2199 | lpfc_unregister_fcf_rescan(phba); |
| 2200 | goto stop_flogi_current_fcf; |
| 2201 | } |
| 2202 | /* Mark the end to FLOGI roundrobin failover */ |
| 2203 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 2204 | /* Allow action to new fcf asynchronous event */ |
| 2205 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 2206 | spin_unlock_irq(&phba->hbalock); |
| 2207 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2208 | "2865 No FCF available, stop roundrobin FCF " |
| 2209 | "failover and change port state:x%x/x%x\n", |
| 2210 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 2211 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 2212 | |
| 2213 | if (!phba->fcf.fcf_redisc_attempted) { |
| 2214 | lpfc_unregister_fcf(phba); |
| 2215 | |
| 2216 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 2217 | if (!rc) { |
| 2218 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2219 | "3195 Rediscover FCF table\n"); |
| 2220 | phba->fcf.fcf_redisc_attempted = 1; |
| 2221 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 2222 | } else { |
| 2223 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2224 | "3196 Rediscover FCF table " |
| 2225 | "failed. Status:x%x\n", rc); |
| 2226 | } |
| 2227 | } else { |
| 2228 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2229 | "3197 Already rediscover FCF table " |
| 2230 | "attempted. No more retry\n"); |
| 2231 | } |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2232 | goto stop_flogi_current_fcf; |
| 2233 | } else { |
| 2234 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 2235 | "2794 Try FLOGI roundrobin FCF failover to " |
| 2236 | "(x%x)\n", fcf_index); |
| 2237 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 2238 | if (rc) |
| 2239 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 2240 | "2761 FLOGI roundrobin FCF failover " |
| 2241 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 2242 | rc, phba->fcf.current_rec.fcf_indx); |
| 2243 | else |
| 2244 | goto stop_flogi_current_fcf; |
| 2245 | } |
| 2246 | return 0; |
| 2247 | |
| 2248 | stop_flogi_current_fcf: |
| 2249 | lpfc_can_disctmo(vport); |
| 2250 | return 1; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2254 | * lpfc_sli4_fcf_pri_list_del |
| 2255 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2256 | * @fcf_index: the index of the fcf record to delete |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2257 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2258 | * If it is one the list then it is removed from the list, and the flag |
| 2259 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2260 | * record from the list. |
| 2261 | **/ |
| 2262 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2263 | uint16_t fcf_index) |
| 2264 | { |
| 2265 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2266 | |
| 2267 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2268 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2269 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2270 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2271 | new_fcf_pri->fcf_rec.flag); |
| 2272 | spin_lock_irq(&phba->hbalock); |
| 2273 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2274 | if (phba->fcf.current_rec.priority == |
| 2275 | new_fcf_pri->fcf_rec.priority) |
| 2276 | phba->fcf.eligible_fcf_cnt--; |
| 2277 | list_del_init(&new_fcf_pri->list); |
| 2278 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2279 | } |
| 2280 | spin_unlock_irq(&phba->hbalock); |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * lpfc_sli4_set_fcf_flogi_fail |
| 2285 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2286 | * @fcf_index: the index of the fcf record to update |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2287 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2288 | * flag so the the round robin slection for the particular priority level |
| 2289 | * will try a different fcf record that does not have this bit set. |
| 2290 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2291 | * adding it to the priority list. |
| 2292 | **/ |
| 2293 | void |
| 2294 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2295 | { |
| 2296 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2297 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2298 | spin_lock_irq(&phba->hbalock); |
| 2299 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2300 | spin_unlock_irq(&phba->hbalock); |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * lpfc_sli4_fcf_pri_list_add |
| 2305 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2306 | * @fcf_index: the index of the fcf record to add |
| 2307 | * @new_fcf_record: pointer to a new FCF record. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2308 | * This routine checks the priority of the fcf_index to be added. |
| 2309 | * If it is a lower priority than the current head of the fcf_pri list |
| 2310 | * then it is added to the list in the right order. |
| 2311 | * If it is the same priority as the current head of the list then it |
| 2312 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2313 | * If the fcf_index to be added is of a higher priority than the current |
| 2314 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2315 | * rr_bmask and it is added to the head of the list. |
| 2316 | * returns: |
| 2317 | * 0=success 1=failure |
| 2318 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2319 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2320 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2321 | struct fcf_record *new_fcf_record) |
| 2322 | { |
| 2323 | uint16_t current_fcf_pri; |
| 2324 | uint16_t last_index; |
| 2325 | struct lpfc_fcf_pri *fcf_pri; |
| 2326 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2327 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2328 | int ret; |
| 2329 | |
| 2330 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2331 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2332 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2333 | fcf_index, new_fcf_record->fip_priority, |
| 2334 | new_fcf_pri->fcf_rec.flag); |
| 2335 | spin_lock_irq(&phba->hbalock); |
| 2336 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2337 | list_del_init(&new_fcf_pri->list); |
| 2338 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2339 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2340 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2341 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2342 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2343 | new_fcf_pri->fcf_rec.fcf_index); |
| 2344 | goto out; |
| 2345 | } |
| 2346 | |
| 2347 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2348 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2349 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2350 | ret = 0; /* Empty rr list */ |
| 2351 | goto out; |
| 2352 | } |
| 2353 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2354 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2355 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2356 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2357 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2358 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2359 | /* fcfs_at_this_priority_level = 1; */ |
| 2360 | phba->fcf.eligible_fcf_cnt = 1; |
| 2361 | } else |
| 2362 | /* fcfs_at_this_priority_level++; */ |
| 2363 | phba->fcf.eligible_fcf_cnt++; |
| 2364 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2365 | new_fcf_pri->fcf_rec.fcf_index); |
| 2366 | goto out; |
| 2367 | } |
| 2368 | |
| 2369 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2370 | &phba->fcf.fcf_pri_list, list) { |
| 2371 | if (new_fcf_pri->fcf_rec.priority <= |
| 2372 | fcf_pri->fcf_rec.priority) { |
| 2373 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2374 | list_add(&new_fcf_pri->list, |
| 2375 | &phba->fcf.fcf_pri_list); |
| 2376 | else |
| 2377 | list_add(&new_fcf_pri->list, |
| 2378 | &((struct lpfc_fcf_pri *) |
| 2379 | fcf_pri->list.prev)->list); |
| 2380 | ret = 0; |
| 2381 | goto out; |
| 2382 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2383 | || new_fcf_pri->fcf_rec.priority < |
| 2384 | next_fcf_pri->fcf_rec.priority) { |
| 2385 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2386 | ret = 0; |
| 2387 | goto out; |
| 2388 | } |
| 2389 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2390 | continue; |
| 2391 | |
| 2392 | } |
| 2393 | ret = 1; |
| 2394 | out: |
| 2395 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2396 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2397 | spin_unlock_irq(&phba->hbalock); |
| 2398 | return ret; |
| 2399 | } |
| 2400 | |
| 2401 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2402 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2403 | * @phba: pointer to lpfc hba data structure. |
| 2404 | * @mboxq: pointer to mailbox object. |
| 2405 | * |
| 2406 | * This function iterates through all the fcf records available in |
| 2407 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2408 | * the FCF for discovery it registers the FCF record and kicks start |
| 2409 | * discovery. |
| 2410 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2411 | * use an FCF record which matches fabric name and mac address of the |
| 2412 | * currently used FCF record. |
| 2413 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2414 | * used by BOOT_BIOS. |
| 2415 | */ |
| 2416 | void |
| 2417 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2418 | { |
| 2419 | struct fcf_record *new_fcf_record; |
| 2420 | uint32_t boot_flag, addr_mode; |
| 2421 | uint16_t fcf_index, next_fcf_index; |
| 2422 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2423 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2424 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2425 | int rc; |
| 2426 | |
| 2427 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2428 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2429 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2434 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2435 | &next_fcf_index); |
| 2436 | if (!new_fcf_record) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2437 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2438 | "2765 Mailbox command READ_FCF_RECORD " |
| 2439 | "failed to retrieve a FCF record.\n"); |
| 2440 | /* Let next new FCF event trigger fast failover */ |
| 2441 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2442 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2443 | spin_unlock_irq(&phba->hbalock); |
| 2444 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2445 | return; |
| 2446 | } |
| 2447 | |
| 2448 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2449 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2450 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2451 | |
| 2452 | /* Log the FCF record information if turned on */ |
| 2453 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2454 | next_fcf_index); |
| 2455 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2456 | /* |
| 2457 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2458 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2459 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2460 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2461 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2462 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2463 | bf_get(lpfc_fcf_record_fcf_index, |
| 2464 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2465 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2466 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2467 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2468 | bf_get(lpfc_fcf_record_fcf_index, |
| 2469 | new_fcf_record), |
| 2470 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2471 | new_fcf_record), |
| 2472 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2473 | new_fcf_record), |
| 2474 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2475 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2476 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2477 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2478 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2479 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2480 | phba->fcf.current_rec.fcf_indx) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2481 | lpfc_printf_log(phba, KERN_ERR, |
| 2482 | LOG_TRACE_EVENT, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2483 | "2862 FCF (x%x) matches property " |
| 2484 | "of in-use FCF (x%x)\n", |
| 2485 | bf_get(lpfc_fcf_record_fcf_index, |
| 2486 | new_fcf_record), |
| 2487 | phba->fcf.current_rec.fcf_indx); |
| 2488 | goto read_next_fcf; |
| 2489 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2490 | /* |
| 2491 | * In case the current in-use FCF record becomes |
| 2492 | * invalid/unavailable during FCF discovery that |
| 2493 | * was not triggered by fast FCF failover process, |
| 2494 | * treat it as fast FCF failover. |
| 2495 | */ |
| 2496 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2497 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2498 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2499 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2500 | "(x%x), enter FCF failover " |
| 2501 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2502 | phba->fcf.current_rec.fcf_indx); |
| 2503 | spin_lock_irq(&phba->hbalock); |
| 2504 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2505 | spin_unlock_irq(&phba->hbalock); |
| 2506 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2507 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2508 | LPFC_FCOE_FCF_GET_FIRST); |
| 2509 | return; |
| 2510 | } |
| 2511 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2512 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2513 | } else { |
| 2514 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2515 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2516 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2517 | if (rc) |
| 2518 | goto read_next_fcf; |
| 2519 | } |
| 2520 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2521 | /* |
| 2522 | * If this is not the first FCF discovery of the HBA, use last |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2523 | * FCF record for the discovery. The condition that a rescan |
| 2524 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2525 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2526 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2527 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2528 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2529 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2530 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2531 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2532 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2533 | phba->fcf.current_rec.fcf_indx) { |
| 2534 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2535 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2536 | /* Stop FCF redisc wait timer */ |
| 2537 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2538 | phba); |
| 2539 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2540 | /* Fast failover, mark completed */ |
| 2541 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2542 | spin_unlock_irq(&phba->hbalock); |
| 2543 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2544 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2545 | "FCF (x%x), port_state:x%x, " |
| 2546 | "fc_flag:x%x\n", |
| 2547 | phba->fcf.current_rec.fcf_indx, |
| 2548 | phba->pport->port_state, |
| 2549 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2550 | goto out; |
| 2551 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2552 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2553 | "2863 New FCF (x%x) matches " |
| 2554 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2555 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2556 | new_fcf_record), |
| 2557 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2558 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2559 | /* |
| 2560 | * Read next FCF record from HBA searching for the matching |
| 2561 | * with in-use record only if not during the fast failover |
| 2562 | * period. In case of fast failover period, it shall try to |
| 2563 | * determine whether the FCF record just read should be the |
| 2564 | * next candidate. |
| 2565 | */ |
| 2566 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2567 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2568 | goto read_next_fcf; |
| 2569 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2570 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2571 | /* |
| 2572 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2573 | * period; otherwise, update on current FCF record. |
| 2574 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2575 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2576 | fcf_rec = &phba->fcf.failover_rec; |
| 2577 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2578 | fcf_rec = &phba->fcf.current_rec; |
| 2579 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2580 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2581 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2582 | * If the driver FCF record does not have boot flag |
| 2583 | * set and new hba fcf record has boot flag set, use |
| 2584 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2585 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2586 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2587 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2588 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2589 | "2837 Update current FCF record " |
| 2590 | "(x%x) with new FCF record (x%x)\n", |
| 2591 | fcf_rec->fcf_indx, |
| 2592 | bf_get(lpfc_fcf_record_fcf_index, |
| 2593 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2594 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2595 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2596 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2597 | goto read_next_fcf; |
| 2598 | } |
| 2599 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2600 | * If the driver FCF record has boot flag set and the |
| 2601 | * new hba FCF record does not have boot flag, read |
| 2602 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2603 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2604 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2605 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2606 | goto read_next_fcf; |
| 2607 | } |
| 2608 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2609 | * If the new hba FCF record has lower priority value |
| 2610 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2611 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2612 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2613 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2614 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2615 | "2838 Update current FCF record " |
| 2616 | "(x%x) with new FCF record (x%x)\n", |
| 2617 | fcf_rec->fcf_indx, |
| 2618 | bf_get(lpfc_fcf_record_fcf_index, |
| 2619 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2620 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2621 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2622 | /* Reset running random FCF selection count */ |
| 2623 | phba->fcf.eligible_fcf_cnt = 1; |
| 2624 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2625 | /* Update running random FCF selection count */ |
| 2626 | phba->fcf.eligible_fcf_cnt++; |
| 2627 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2628 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2629 | if (select_new_fcf) { |
| 2630 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2631 | "2839 Update current FCF record " |
| 2632 | "(x%x) with new FCF record (x%x)\n", |
| 2633 | fcf_rec->fcf_indx, |
| 2634 | bf_get(lpfc_fcf_record_fcf_index, |
| 2635 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2636 | /* Choose the new FCF by random selection */ |
| 2637 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2638 | new_fcf_record, |
| 2639 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2640 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2641 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2642 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2643 | goto read_next_fcf; |
| 2644 | } |
| 2645 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2646 | * This is the first suitable FCF record, choose this record for |
| 2647 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2648 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2649 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2650 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2651 | "2840 Update initial FCF candidate " |
| 2652 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2653 | bf_get(lpfc_fcf_record_fcf_index, |
| 2654 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2655 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2656 | addr_mode, vlan_id, (boot_flag ? |
| 2657 | BOOT_ENABLE : 0)); |
| 2658 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2659 | /* Setup initial running random FCF selection count */ |
| 2660 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2661 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2662 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2663 | goto read_next_fcf; |
| 2664 | |
| 2665 | read_next_fcf: |
| 2666 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2667 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2668 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2669 | /* |
| 2670 | * Case of FCF fast failover scan |
| 2671 | */ |
| 2672 | |
| 2673 | /* |
| 2674 | * It has not found any suitable FCF record, cancel |
| 2675 | * FCF scan inprogress, and do nothing |
| 2676 | */ |
| 2677 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2678 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2679 | "2782 No suitable FCF found: " |
| 2680 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2681 | phba->fcoe_eventtag_at_fcf_scan, |
| 2682 | bf_get(lpfc_fcf_record_fcf_index, |
| 2683 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2684 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2685 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2686 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2687 | spin_unlock_irq(&phba->hbalock); |
| 2688 | /* Unregister in-use FCF and rescan */ |
| 2689 | lpfc_printf_log(phba, KERN_INFO, |
| 2690 | LOG_FIP, |
| 2691 | "2864 On devloss tmo " |
| 2692 | "unreg in-use FCF and " |
| 2693 | "rescan FCF table\n"); |
| 2694 | lpfc_unregister_fcf_rescan(phba); |
| 2695 | return; |
| 2696 | } |
| 2697 | /* |
| 2698 | * Let next new FCF event trigger fast failover |
| 2699 | */ |
| 2700 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2701 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2702 | return; |
| 2703 | } |
| 2704 | /* |
| 2705 | * It has found a suitable FCF record that is not |
| 2706 | * the same as in-use FCF record, unregister the |
| 2707 | * in-use FCF record, replace the in-use FCF record |
| 2708 | * with the new FCF record, mark FCF fast failover |
| 2709 | * completed, and then start register the new FCF |
| 2710 | * record. |
| 2711 | */ |
| 2712 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2713 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2714 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2715 | |
| 2716 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2717 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2718 | "2842 Replace in-use FCF (x%x) " |
| 2719 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2720 | phba->fcf.current_rec.fcf_indx, |
| 2721 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2722 | memcpy(&phba->fcf.current_rec, |
| 2723 | &phba->fcf.failover_rec, |
| 2724 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2725 | /* |
| 2726 | * Mark the fast FCF failover rediscovery completed |
| 2727 | * and the start of the first round of the roundrobin |
| 2728 | * FCF failover. |
| 2729 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2730 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2731 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2732 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2733 | /* Register to the new FCF record */ |
| 2734 | lpfc_register_fcf(phba); |
| 2735 | } else { |
| 2736 | /* |
| 2737 | * In case of transaction period to fast FCF failover, |
| 2738 | * do nothing when search to the end of the FCF table. |
| 2739 | */ |
| 2740 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2741 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2742 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2743 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2744 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2745 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2746 | /* |
| 2747 | * In case the current in-use FCF record no |
| 2748 | * longer existed during FCF discovery that |
| 2749 | * was not triggered by fast FCF failover |
| 2750 | * process, treat it as fast FCF failover. |
| 2751 | */ |
| 2752 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2753 | "2841 In-use FCF record (x%x) " |
| 2754 | "not reported, entering fast " |
| 2755 | "FCF failover mode scanning.\n", |
| 2756 | phba->fcf.current_rec.fcf_indx); |
| 2757 | spin_lock_irq(&phba->hbalock); |
| 2758 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2759 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2760 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2761 | LPFC_FCOE_FCF_GET_FIRST); |
| 2762 | return; |
| 2763 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2764 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2765 | lpfc_register_fcf(phba); |
| 2766 | } |
| 2767 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2768 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2769 | return; |
| 2770 | |
| 2771 | out: |
| 2772 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2773 | lpfc_register_fcf(phba); |
| 2774 | |
| 2775 | return; |
| 2776 | } |
| 2777 | |
| 2778 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2779 | * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2780 | * @phba: pointer to lpfc hba data structure. |
| 2781 | * @mboxq: pointer to mailbox object. |
| 2782 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2783 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2784 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2785 | * performing the failover. If the FCF read back is not valid/available, it |
| 2786 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2787 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2788 | * newly read FCF record to the failover FCF record, unregister currently |
| 2789 | * registered FCF record, copy the failover FCF record to the current |
| 2790 | * FCF record, and then register the current FCF record before proceeding |
| 2791 | * to trying FLOGI on the new failover FCF. |
| 2792 | */ |
| 2793 | void |
| 2794 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2795 | { |
| 2796 | struct fcf_record *new_fcf_record; |
| 2797 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2798 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2799 | uint16_t current_fcf_index; |
| 2800 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2801 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2802 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2803 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2804 | if (phba->link_state < LPFC_LINK_UP) { |
| 2805 | spin_lock_irq(&phba->hbalock); |
| 2806 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2807 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2808 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2809 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2813 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2814 | &next_fcf_index); |
| 2815 | if (!new_fcf_record) { |
| 2816 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2817 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2818 | "failed to retrieve a FCF record. " |
| 2819 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2820 | phba->fcf.fcf_flag); |
| 2821 | lpfc_unregister_fcf_rescan(phba); |
| 2822 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2826 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2827 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2828 | |
| 2829 | /* Log the FCF record information if turned on */ |
| 2830 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2831 | next_fcf_index); |
| 2832 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2833 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2834 | if (!rc) { |
| 2835 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2836 | "2848 Remove ineligible FCF (x%x) from " |
| 2837 | "from roundrobin bmask\n", fcf_index); |
| 2838 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2839 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2840 | /* Perform next round of roundrobin FCF failover */ |
| 2841 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2842 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2843 | if (rc) |
| 2844 | goto out; |
| 2845 | goto error_out; |
| 2846 | } |
| 2847 | |
| 2848 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2849 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2850 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2851 | "FCF (x%x) back to FCF (x%x)\n", |
| 2852 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2853 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2854 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2855 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2856 | goto out; |
| 2857 | } |
| 2858 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2859 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2860 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2861 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2862 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2863 | spin_lock_irq(&phba->hbalock); |
| 2864 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2865 | new_fcf_record, addr_mode, vlan_id, |
| 2866 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2867 | spin_unlock_irq(&phba->hbalock); |
| 2868 | |
| 2869 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2870 | |
| 2871 | /* Unregister the current in-use FCF record */ |
| 2872 | lpfc_unregister_fcf(phba); |
| 2873 | |
| 2874 | /* Replace in-use record with the new record */ |
| 2875 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2876 | sizeof(struct lpfc_fcf_rec)); |
| 2877 | |
| 2878 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2879 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2880 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2881 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2882 | error_out: |
| 2883 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2884 | out: |
| 2885 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | /** |
| 2889 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2890 | * @phba: pointer to lpfc hba data structure. |
| 2891 | * @mboxq: pointer to mailbox object. |
| 2892 | * |
| 2893 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2894 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2895 | * failover when a new FCF event happened. If the FCF read back is |
| 2896 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2897 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2898 | */ |
| 2899 | void |
| 2900 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2901 | { |
| 2902 | struct fcf_record *new_fcf_record; |
| 2903 | uint32_t boot_flag, addr_mode; |
| 2904 | uint16_t fcf_index, next_fcf_index; |
| 2905 | uint16_t vlan_id; |
| 2906 | int rc; |
| 2907 | |
| 2908 | /* If link state is not up, no need to proceed */ |
| 2909 | if (phba->link_state < LPFC_LINK_UP) |
| 2910 | goto out; |
| 2911 | |
| 2912 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2913 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2914 | goto out; |
| 2915 | |
| 2916 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2917 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2918 | &next_fcf_index); |
| 2919 | if (!new_fcf_record) { |
| 2920 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2921 | "2767 Mailbox command READ_FCF_RECORD " |
| 2922 | "failed to retrieve a FCF record.\n"); |
| 2923 | goto out; |
| 2924 | } |
| 2925 | |
| 2926 | /* Check the connection list for eligibility */ |
| 2927 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2928 | &addr_mode, &vlan_id); |
| 2929 | |
| 2930 | /* Log the FCF record information if turned on */ |
| 2931 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2932 | next_fcf_index); |
| 2933 | |
| 2934 | if (!rc) |
| 2935 | goto out; |
| 2936 | |
| 2937 | /* Update the eligible FCF record index bmask */ |
| 2938 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2939 | |
| 2940 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2941 | |
| 2942 | out: |
| 2943 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2944 | } |
| 2945 | |
| 2946 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2947 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2948 | * @phba: pointer to lpfc hba data structure. |
| 2949 | * @mboxq: pointer to mailbox data structure. |
| 2950 | * |
| 2951 | * This function handles completion of init vfi mailbox command. |
| 2952 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2953 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2954 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2955 | { |
| 2956 | struct lpfc_vport *vport = mboxq->vport; |
| 2957 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2958 | /* |
| 2959 | * VFI not supported on interface type 0, just do the flogi |
| 2960 | * Also continue if the VFI is in use - just use the same one. |
| 2961 | */ |
| 2962 | if (mboxq->u.mb.mbxStatus && |
| 2963 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2964 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2965 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2966 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 2967 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2968 | mboxq->u.mb.mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2969 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2970 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2971 | return; |
| 2972 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2973 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2974 | lpfc_initial_flogi(vport); |
| 2975 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2976 | return; |
| 2977 | } |
| 2978 | |
| 2979 | /** |
| 2980 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2981 | * @vport: pointer to lpfc_vport data structure. |
| 2982 | * |
| 2983 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2984 | * VPI for the physical port. |
| 2985 | */ |
| 2986 | void |
| 2987 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2988 | { |
| 2989 | LPFC_MBOXQ_t *mboxq; |
| 2990 | int rc; |
| 2991 | struct lpfc_hba *phba = vport->phba; |
| 2992 | |
| 2993 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2994 | if (!mboxq) { |
| 2995 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2996 | LOG_TRACE_EVENT, "2892 Failed to allocate " |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2997 | "init_vfi mailbox\n"); |
| 2998 | return; |
| 2999 | } |
| 3000 | lpfc_init_vfi(mboxq, vport); |
| 3001 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 3002 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 3003 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3004 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 3005 | "2893 Failed to issue init_vfi mailbox\n"); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3006 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3011 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 3012 | * @phba: pointer to lpfc hba data structure. |
| 3013 | * @mboxq: pointer to mailbox data structure. |
| 3014 | * |
| 3015 | * This function handles completion of init vpi mailbox command. |
| 3016 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3017 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3018 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 3019 | { |
| 3020 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3021 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3022 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3023 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3024 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3025 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 3026 | "2609 Init VPI mailbox failed 0x%x\n", |
| 3027 | mboxq->u.mb.mbxStatus); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3028 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3029 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3030 | return; |
| 3031 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3032 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3033 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3034 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3035 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3036 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 3037 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 3038 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 3039 | if (!ndlp) |
| 3040 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3041 | LOG_TRACE_EVENT, |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3042 | "2731 Cannot find fabric " |
| 3043 | "controller node\n"); |
| 3044 | else |
| 3045 | lpfc_register_new_vport(phba, vport, ndlp); |
| 3046 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3047 | return; |
| 3048 | } |
| 3049 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3050 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 3051 | lpfc_initial_fdisc(vport); |
| 3052 | else { |
| 3053 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3054 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3055 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3056 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3057 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3058 | return; |
| 3059 | } |
| 3060 | |
| 3061 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3062 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 3063 | * @vport: pointer to lpfc_vport data structure. |
| 3064 | * |
| 3065 | * This function issue a init_vpi mailbox command to initialize |
| 3066 | * VPI for the vport. |
| 3067 | */ |
| 3068 | void |
| 3069 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 3070 | { |
| 3071 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3072 | int rc, vpi; |
| 3073 | |
| 3074 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 3075 | vpi = lpfc_alloc_vpi(vport->phba); |
| 3076 | if (!vpi) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3077 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3078 | "3303 Failed to obtain vport vpi\n"); |
| 3079 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3080 | return; |
| 3081 | } |
| 3082 | vport->vpi = vpi; |
| 3083 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3084 | |
| 3085 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 3086 | if (!mboxq) { |
| 3087 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3088 | LOG_TRACE_EVENT, "2607 Failed to allocate " |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3089 | "init_vpi mailbox\n"); |
| 3090 | return; |
| 3091 | } |
| 3092 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 3093 | mboxq->vport = vport; |
| 3094 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 3095 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 3096 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3097 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 3098 | "2608 Failed to issue init_vpi mailbox\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3099 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3104 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 3105 | * @phba: pointer to lpfc hba data structure. |
| 3106 | * |
| 3107 | * This function loops through the list of vports on the @phba and issues an |
| 3108 | * FDISC if possible. |
| 3109 | */ |
| 3110 | void |
| 3111 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 3112 | { |
| 3113 | struct lpfc_vport **vports; |
| 3114 | int i; |
| 3115 | |
| 3116 | vports = lpfc_create_vport_work_array(phba); |
| 3117 | if (vports != NULL) { |
| 3118 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3119 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 3120 | continue; |
| 3121 | /* There are no vpi for this vport */ |
| 3122 | if (vports[i]->vpi > phba->max_vpi) { |
| 3123 | lpfc_vport_set_state(vports[i], |
| 3124 | FC_VPORT_FAILED); |
| 3125 | continue; |
| 3126 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3127 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3128 | lpfc_vport_set_state(vports[i], |
| 3129 | FC_VPORT_LINKDOWN); |
| 3130 | continue; |
| 3131 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3132 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3133 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3134 | continue; |
| 3135 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3136 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 3137 | lpfc_initial_fdisc(vports[i]); |
| 3138 | else { |
| 3139 | lpfc_vport_set_state(vports[i], |
| 3140 | FC_VPORT_NO_FABRIC_SUPP); |
| 3141 | lpfc_printf_vlog(vports[i], KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3142 | LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3143 | "0259 No NPIV " |
| 3144 | "Fabric support\n"); |
| 3145 | } |
| 3146 | } |
| 3147 | } |
| 3148 | lpfc_destroy_vport_work_array(phba, vports); |
| 3149 | } |
| 3150 | |
| 3151 | void |
| 3152 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 3153 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3154 | struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3155 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3156 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3157 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 3158 | /* |
| 3159 | * VFI not supported for interface type 0, so ignore any mailbox |
| 3160 | * error (except VFI in use) and continue with the discovery. |
| 3161 | */ |
| 3162 | if (mboxq->u.mb.mbxStatus && |
| 3163 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3164 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 3165 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3166 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 3167 | "2018 REG_VFI mbxStatus error x%x " |
| 3168 | "HBA state x%x\n", |
| 3169 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3170 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3171 | /* FLOGI failed, use loop map to make discovery list */ |
| 3172 | lpfc_disc_list_loopmap(vport); |
| 3173 | /* Start discovery */ |
| 3174 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3175 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3176 | } |
| 3177 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3178 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3179 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3180 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3181 | /* If the VFI is already registered, there is nothing else to do |
| 3182 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 3183 | * we should drop through to set the port state to ready. |
| 3184 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3185 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3186 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 3187 | vport->fc_flag & FC_PT2PT)) |
| 3188 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3189 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3190 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3191 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3192 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3193 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3194 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 3195 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3196 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3197 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3198 | /* In case SLI4 FC loopback test, we are ready */ |
| 3199 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 3200 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 3201 | phba->link_state = LPFC_HBA_READY; |
| 3202 | goto out_free_mem; |
| 3203 | } |
| 3204 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3205 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3206 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 3207 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 3208 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 3209 | vport->phba->alpa_map[0], |
| 3210 | phba->link_state, phba->fc_topology); |
| 3211 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3212 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 3213 | /* |
| 3214 | * For private loop or for NPort pt2pt, |
| 3215 | * just start discovery and we are done. |
| 3216 | */ |
| 3217 | if ((vport->fc_flag & FC_PT2PT) || |
| 3218 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 3219 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 3220 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3221 | /* Use loop map to make discovery list */ |
| 3222 | lpfc_disc_list_loopmap(vport); |
| 3223 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3224 | if (vport->fc_flag & FC_PT2PT) |
| 3225 | vport->port_state = LPFC_VPORT_READY; |
| 3226 | else |
| 3227 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3228 | } else { |
| 3229 | lpfc_start_fdiscs(phba); |
| 3230 | lpfc_do_scr_ns_plogi(phba, vport); |
| 3231 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3232 | } |
| 3233 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3234 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3235 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3236 | if (dmabuf) { |
| 3237 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 3238 | kfree(dmabuf); |
| 3239 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3240 | return; |
| 3241 | } |
| 3242 | |
| 3243 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3244 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3245 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3246 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3247 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3248 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3249 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3250 | struct serv_parm *sp = &vport->fc_sparam; |
| 3251 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | |
| 3253 | /* Check for error */ |
| 3254 | if (mb->mbxStatus) { |
| 3255 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3256 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3257 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3258 | "hba state x%x>\n", |
| 3259 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | goto out; |
| 3262 | } |
| 3263 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3266 | |
| 3267 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3268 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3269 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3270 | |
| 3271 | phba->fc_edtov = ed_tov; |
| 3272 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3273 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3274 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3275 | phba->fc_ratov = FF_DEF_RATOV; |
| 3276 | } |
| 3277 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3278 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3279 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3280 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3281 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3282 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3283 | } |
| 3284 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3286 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 3288 | |
| 3289 | /* Check if sending the FLOGI is being deferred to after we get |
| 3290 | * up to date CSPs from MBX_READ_SPARAM. |
| 3291 | */ |
| 3292 | if (phba->hba_flag & HBA_DEFER_FLOGI) { |
| 3293 | lpfc_initial_flogi(vport); |
| 3294 | phba->hba_flag &= ~HBA_DEFER_FLOGI; |
| 3295 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | return; |
| 3297 | |
| 3298 | out: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3299 | pmb->ctx_buf = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3301 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3302 | lpfc_issue_clear_la(phba, vport); |
| 3303 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | return; |
| 3305 | } |
| 3306 | |
| 3307 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3308 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3310 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3311 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3312 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3313 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3314 | struct lpfc_dmabuf *mp; |
| 3315 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3316 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3317 | uint32_t fc_flags = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3318 | unsigned long iflags; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3319 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3320 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3321 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3322 | |
| 3323 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3324 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3325 | case LPFC_LINK_SPEED_1GHZ: |
| 3326 | case LPFC_LINK_SPEED_2GHZ: |
| 3327 | case LPFC_LINK_SPEED_4GHZ: |
| 3328 | case LPFC_LINK_SPEED_8GHZ: |
| 3329 | case LPFC_LINK_SPEED_10GHZ: |
| 3330 | case LPFC_LINK_SPEED_16GHZ: |
| 3331 | case LPFC_LINK_SPEED_32GHZ: |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 3332 | case LPFC_LINK_SPEED_64GHZ: |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 3333 | case LPFC_LINK_SPEED_128GHZ: |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3334 | break; |
| 3335 | default: |
| 3336 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3337 | break; |
| 3338 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | } |
| 3340 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3341 | if (phba->fc_topology && |
| 3342 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3343 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3344 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3345 | phba->fc_topology, |
| 3346 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3347 | phba->fc_topology_changed = 1; |
| 3348 | } |
| 3349 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3350 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 3351 | phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3353 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3354 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3355 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3357 | /* if npiv is enabled and this adapter supports npiv log |
| 3358 | * a message that npiv is not supported in this topology |
| 3359 | */ |
| 3360 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3361 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3362 | "1309 Link Up Event npiv not supported in loop " |
| 3363 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3364 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3365 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3366 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3368 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3369 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | |
| 3371 | if (i == 0) { |
| 3372 | phba->alpa_map[0] = 0; |
| 3373 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3374 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | int numalpa, j, k; |
| 3376 | union { |
| 3377 | uint8_t pamap[16]; |
| 3378 | struct { |
| 3379 | uint32_t wd1; |
| 3380 | uint32_t wd2; |
| 3381 | uint32_t wd3; |
| 3382 | uint32_t wd4; |
| 3383 | } pa; |
| 3384 | } un; |
| 3385 | numalpa = phba->alpa_map[0]; |
| 3386 | j = 0; |
| 3387 | while (j < numalpa) { |
| 3388 | memset(un.pamap, 0, 16); |
| 3389 | for (k = 1; j < numalpa; k++) { |
| 3390 | un.pamap[k - 1] = |
| 3391 | phba->alpa_map[j + 1]; |
| 3392 | j++; |
| 3393 | if (k == 16) |
| 3394 | break; |
| 3395 | } |
| 3396 | /* Link Up Event ALPA map */ |
| 3397 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3398 | KERN_WARNING, |
| 3399 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3400 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | "ALPA map Data: x%x " |
| 3402 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3403 | un.pa.wd1, un.pa.wd2, |
| 3404 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3409 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3410 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3411 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3412 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3413 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3415 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3417 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3419 | if (fc_flags) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3420 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3421 | vport->fc_flag |= fc_flags; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3422 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3423 | } |
| 3424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | lpfc_linkup(phba); |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 3426 | sparam_mbox = NULL; |
| 3427 | |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3428 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3429 | if (!sparam_mbox) |
| 3430 | goto out; |
| 3431 | |
| 3432 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3433 | if (rc) { |
| 3434 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3435 | goto out; |
| 3436 | } |
| 3437 | sparam_mbox->vport = vport; |
| 3438 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3439 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3440 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3441 | mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3442 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3443 | kfree(mp); |
| 3444 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3445 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | } |
| 3447 | |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 3448 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3449 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3450 | if (!cfglink_mbox) |
| 3451 | goto out; |
| 3452 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| 3453 | lpfc_config_link(phba, cfglink_mbox); |
| 3454 | cfglink_mbox->vport = vport; |
| 3455 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 3456 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
| 3457 | if (rc == MBX_NOT_FINISHED) { |
| 3458 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3459 | goto out; |
| 3460 | } |
| 3461 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3462 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3463 | /* |
| 3464 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3465 | * is phase 1 implementation that support FCF index 0 and driver |
| 3466 | * defaults. |
| 3467 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3468 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3469 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3470 | GFP_KERNEL); |
| 3471 | if (unlikely(!fcf_record)) { |
| 3472 | lpfc_printf_log(phba, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3473 | LOG_TRACE_EVENT, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3474 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3475 | "fcf record\n"); |
| 3476 | rc = -ENODEV; |
| 3477 | goto out; |
| 3478 | } |
| 3479 | |
| 3480 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3481 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3482 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3483 | if (unlikely(rc)) { |
| 3484 | lpfc_printf_log(phba, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3485 | LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3486 | "2013 Could not manually add FCF " |
| 3487 | "record 0, status %d\n", rc); |
| 3488 | rc = -ENODEV; |
| 3489 | kfree(fcf_record); |
| 3490 | goto out; |
| 3491 | } |
| 3492 | kfree(fcf_record); |
| 3493 | } |
| 3494 | /* |
| 3495 | * The driver is expected to do FIP/FCF. Call the port |
| 3496 | * and get the FCF Table. |
| 3497 | */ |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3498 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3499 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3500 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3501 | return; |
| 3502 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3503 | /* This is the initial FCF discovery scan */ |
| 3504 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3505 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3506 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3507 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3508 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3509 | LPFC_FCOE_FCF_GET_FIRST); |
| 3510 | if (rc) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3511 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3512 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3513 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3514 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3515 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3516 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3517 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3519 | |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 3520 | /* Prepare for LINK up registrations */ |
| 3521 | memset(phba->os_host_name, 0, sizeof(phba->os_host_name)); |
| 3522 | scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s", |
| 3523 | init_utsname()->nodename); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3524 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3525 | out: |
| 3526 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3527 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 3528 | "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3529 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3530 | lpfc_issue_clear_la(phba, vport); |
| 3531 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3535 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3536 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | uint32_t control; |
| 3538 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3539 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3541 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3542 | control = readl(phba->HCregaddr); |
| 3543 | control |= HC_LAINT_ENA; |
| 3544 | writel(control, phba->HCregaddr); |
| 3545 | readl(phba->HCregaddr); /* flush */ |
| 3546 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3547 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | } |
| 3549 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3550 | static void |
| 3551 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3552 | { |
| 3553 | lpfc_linkdown(phba); |
| 3554 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3555 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3556 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3557 | } |
| 3558 | |
| 3559 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3561 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3563 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3564 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3565 | */ |
| 3566 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3567 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3569 | struct lpfc_vport *vport = pmb->vport; |
| 3570 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3571 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3572 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3573 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3574 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3575 | uint8_t attn_type; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3576 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3578 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3579 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 3580 | if (pring) |
| 3581 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | /* Check for error */ |
| 3584 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3585 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3586 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3587 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3589 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3590 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | } |
| 3592 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3593 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3594 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | |
| 3596 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3597 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3598 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3599 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3600 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3601 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3602 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3603 | spin_unlock_irqrestore(shost->host_lock, iflags); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3604 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3605 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3607 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | if (phba->fc_eventTag != 0) |
| 3609 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3610 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3611 | |
| 3612 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3613 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3614 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3615 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3616 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3617 | else |
| 3618 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3619 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3620 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3622 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3623 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3624 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3627 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3628 | "1306 Link Up Event in loop back mode " |
| 3629 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3630 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3631 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3632 | la), |
| 3633 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3634 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3635 | } else { |
| 3636 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3637 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3638 | "Data: x%x x%x x%x x%x x%x x%x %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3639 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3640 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3641 | la), |
| 3642 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3643 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3644 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3645 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3646 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3647 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3648 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3649 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3650 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3652 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3653 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3654 | "1308 Link Down Event in loop back mode " |
| 3655 | "x%x received " |
| 3656 | "Data: x%x x%x x%x\n", |
| 3657 | la->eventTag, phba->fc_eventTag, |
| 3658 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3659 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3660 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | b9da814 | 2019-11-04 16:57:04 -0800 | [diff] [blame] | 3661 | "1313 Link Down Unexpected FA WWPN Event x%x " |
| 3662 | "received Data: x%x x%x x%x x%x x%x\n", |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3663 | la->eventTag, phba->fc_eventTag, |
| 3664 | phba->pport->port_state, vport->fc_flag, |
| 3665 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3666 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3667 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3668 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3669 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3670 | "Data: x%x x%x x%x x%x x%x\n", |
| 3671 | la->eventTag, phba->fc_eventTag, |
| 3672 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3673 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3674 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3675 | lpfc_mbx_issue_link_down(phba); |
| 3676 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3677 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3678 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3679 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3680 | phba->fc_stat.LinkDown++; |
| 3681 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3682 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3684 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3685 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3686 | lpfc_mbx_issue_link_down(phba); |
| 3687 | } else |
| 3688 | lpfc_enable_la(phba); |
| 3689 | |
| 3690 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3691 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3692 | "Data: x%x x%x x%x\n", |
| 3693 | la->eventTag, phba->fc_eventTag, |
| 3694 | phba->pport->port_state, vport->fc_flag); |
| 3695 | /* |
| 3696 | * The cmnd that triggered this will be waiting for this |
| 3697 | * signal. |
| 3698 | */ |
| 3699 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3700 | if (phba->wait_4_mlo_maint_flg) { |
| 3701 | phba->wait_4_mlo_maint_flg = 0; |
| 3702 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3703 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3704 | } |
| 3705 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3706 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3707 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3708 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3709 | lpfc_issue_clear_la(phba, vport); |
| 3710 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3711 | "1311 fa %d\n", |
| 3712 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | } |
| 3714 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3715 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3717 | kfree(mp); |
| 3718 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3719 | return; |
| 3720 | } |
| 3721 | |
| 3722 | /* |
| 3723 | * This routine handles processing a REG_LOGIN mailbox |
| 3724 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3725 | * as the completion routine when the command is |
| 3726 | * handed off to the SLI layer. |
| 3727 | */ |
| 3728 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3729 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3731 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3732 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 3733 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3735 | pmb->ctx_buf = NULL; |
| 3736 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 3738 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3739 | "0002 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3740 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3741 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3742 | ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3743 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3744 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3745 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3746 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3747 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3748 | /* We rcvd a rscn after issuing this |
| 3749 | * mbox reg login, we may have cycled |
| 3750 | * back through the state and be |
| 3751 | * back at reg login state so this |
| 3752 | * mbox needs to be ignored becase |
| 3753 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3754 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3755 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3756 | spin_lock_irq(&ndlp->lock); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3757 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3758 | spin_unlock_irq(&ndlp->lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3759 | |
| 3760 | /* |
| 3761 | * We cannot leave the RPI registered because |
| 3762 | * if we go thru discovery again for this ndlp |
| 3763 | * a subsequent REG_RPI will fail. |
| 3764 | */ |
| 3765 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3766 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /* Call state machine */ |
| 3770 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3771 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3773 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3775 | /* decrement the node reference count held for this callback |
| 3776 | * function. |
| 3777 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3778 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | |
| 3780 | return; |
| 3781 | } |
| 3782 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3783 | static void |
| 3784 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3785 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3786 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3787 | struct lpfc_vport *vport = pmb->vport; |
| 3788 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3789 | |
| 3790 | switch (mb->mbxStatus) { |
| 3791 | case 0x0011: |
| 3792 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3793 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3794 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3795 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3796 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3797 | /* If VPI is busy, reset the HBA */ |
| 3798 | case 0x9700: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3799 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3800 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3801 | vport->vpi, mb->mbxStatus); |
| 3802 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3803 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3804 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3805 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3806 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3807 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3808 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3809 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3810 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3811 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3812 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3813 | /* |
| 3814 | * This shost reference might have been taken at the beginning of |
| 3815 | * lpfc_vport_delete() |
| 3816 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3817 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3818 | scsi_host_put(shost); |
| 3819 | } |
| 3820 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3821 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3822 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3823 | { |
| 3824 | struct lpfc_hba *phba = vport->phba; |
| 3825 | LPFC_MBOXQ_t *mbox; |
| 3826 | int rc; |
| 3827 | |
| 3828 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3829 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3830 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3831 | |
| 3832 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3833 | mbox->vport = vport; |
| 3834 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3835 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3836 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3837 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3838 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3839 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3840 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3841 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3842 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3843 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | static void |
| 3847 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3848 | { |
| 3849 | struct lpfc_vport *vport = pmb->vport; |
| 3850 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3851 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | |
| 3853 | switch (mb->mbxStatus) { |
| 3854 | case 0x0011: |
| 3855 | case 0x9601: |
| 3856 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3857 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3858 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3859 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3860 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3861 | spin_lock_irq(shost->host_lock); |
| 3862 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3863 | spin_unlock_irq(shost->host_lock); |
| 3864 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3865 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3866 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3867 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3868 | if (phba->nvmet_support) |
| 3869 | lpfc_nvmet_update_targetport(phba); |
| 3870 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3871 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3872 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3873 | goto out; |
| 3874 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3875 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3876 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3877 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3878 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3879 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3880 | vport->num_disc_nodes = 0; |
| 3881 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3882 | if (vport->fc_npr_cnt) |
| 3883 | lpfc_els_disc_plogi(vport); |
| 3884 | |
| 3885 | if (!vport->num_disc_nodes) { |
| 3886 | spin_lock_irq(shost->host_lock); |
| 3887 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3888 | spin_unlock_irq(shost->host_lock); |
| 3889 | lpfc_can_disctmo(vport); |
| 3890 | } |
| 3891 | vport->port_state = LPFC_VPORT_READY; |
| 3892 | |
| 3893 | out: |
| 3894 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3895 | return; |
| 3896 | } |
| 3897 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3898 | /** |
| 3899 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3900 | * @phba: pointer to lpfc hba data structure. |
| 3901 | * |
| 3902 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3903 | * the list of static vports to be created. The function create vports |
| 3904 | * based on the information returned from the HBA. |
| 3905 | **/ |
| 3906 | void |
| 3907 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3908 | { |
| 3909 | LPFC_MBOXQ_t *pmb = NULL; |
| 3910 | MAILBOX_t *mb; |
| 3911 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3912 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3913 | struct fc_vport_identifiers vport_id; |
| 3914 | struct fc_vport *new_fc_vport; |
| 3915 | struct Scsi_Host *shost; |
| 3916 | struct lpfc_vport *vport; |
| 3917 | uint16_t offset = 0; |
| 3918 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3919 | struct lpfc_dmabuf *mp; |
| 3920 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3921 | |
| 3922 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3923 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3924 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3925 | "0542 lpfc_create_static_vport failed to" |
| 3926 | " allocate mailbox memory\n"); |
| 3927 | return; |
| 3928 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3929 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3930 | mb = &pmb->u.mb; |
| 3931 | |
| 3932 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3933 | if (!vport_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3934 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3935 | "0543 lpfc_create_static_vport failed to" |
| 3936 | " allocate vport_info\n"); |
| 3937 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3938 | return; |
| 3939 | } |
| 3940 | |
| 3941 | vport_buff = (uint8_t *) vport_info; |
| 3942 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3943 | /* free dma buffer from previous round */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3944 | if (pmb->ctx_buf) { |
| 3945 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3946 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3947 | kfree(mp); |
| 3948 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3949 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3950 | goto out; |
| 3951 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3952 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3953 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3954 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3955 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3956 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3957 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3958 | "0544 lpfc_create_static_vport failed to" |
| 3959 | " issue dump mailbox command ret 0x%x " |
| 3960 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3961 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3962 | goto out; |
| 3963 | } |
| 3964 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3965 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3966 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3967 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3968 | if (byte_count > sizeof(struct static_vport_info) - |
| 3969 | offset) |
| 3970 | byte_count = sizeof(struct static_vport_info) |
| 3971 | - offset; |
| 3972 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3973 | offset += byte_count; |
| 3974 | } else { |
| 3975 | if (mb->un.varDmp.word_cnt > |
| 3976 | sizeof(struct static_vport_info) - offset) |
| 3977 | mb->un.varDmp.word_cnt = |
| 3978 | sizeof(struct static_vport_info) |
| 3979 | - offset; |
| 3980 | byte_count = mb->un.varDmp.word_cnt; |
| 3981 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3982 | vport_buff + offset, |
| 3983 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3984 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3985 | offset += byte_count; |
| 3986 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3987 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3988 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3989 | offset < sizeof(struct static_vport_info)); |
| 3990 | |
| 3991 | |
| 3992 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3993 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3994 | != VPORT_INFO_REV)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3995 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3996 | "0545 lpfc_create_static_vport bad" |
| 3997 | " information header 0x%x 0x%x\n", |
| 3998 | le32_to_cpu(vport_info->signature), |
| 3999 | le32_to_cpu(vport_info->rev) & |
| 4000 | VPORT_INFO_REV_MASK); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4001 | |
| 4002 | goto out; |
| 4003 | } |
| 4004 | |
| 4005 | shost = lpfc_shost_from_vport(phba->pport); |
| 4006 | |
| 4007 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 4008 | memset(&vport_id, 0, sizeof(vport_id)); |
| 4009 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 4010 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 4011 | if (!vport_id.port_name || !vport_id.node_name) |
| 4012 | continue; |
| 4013 | |
| 4014 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 4015 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 4016 | vport_id.disable = false; |
| 4017 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 4018 | |
| 4019 | if (!new_fc_vport) { |
| 4020 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4021 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4022 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4023 | continue; |
| 4024 | } |
| 4025 | |
| 4026 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 4027 | vport->vport_flag |= STATIC_VPORT; |
| 4028 | } |
| 4029 | |
| 4030 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4031 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 4032 | if (mbx_wait_rc != MBX_TIMEOUT) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4033 | if (pmb->ctx_buf) { |
| 4034 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 4035 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4036 | kfree(mp); |
| 4037 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4038 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 4039 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4040 | |
| 4041 | return; |
| 4042 | } |
| 4043 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | /* |
| 4045 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 4046 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4047 | * as the completion routine when the command is |
| 4048 | * handed off to the SLI layer. |
| 4049 | */ |
| 4050 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4051 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4053 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4054 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4055 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4056 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4057 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4059 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 4060 | pmb->ctx_ndlp = NULL; |
| 4061 | pmb->ctx_buf = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4062 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4064 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4065 | "0258 Register Fabric login error: 0x%x\n", |
| 4066 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4068 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4069 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4071 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4072 | /* FLOGI failed, use loop map to make discovery list */ |
| 4073 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | /* Start discovery */ |
| 4076 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4077 | /* Decrement the reference count to ndlp after the |
| 4078 | * reference to the ndlp are done. |
| 4079 | */ |
| 4080 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4081 | return; |
| 4082 | } |
| 4083 | |
| 4084 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4085 | /* Decrement the reference count to ndlp after the reference |
| 4086 | * to the ndlp are done. |
| 4087 | */ |
| 4088 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | return; |
| 4090 | } |
| 4091 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4092 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4093 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4094 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4096 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4098 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 4099 | /* when physical port receive logo donot start |
| 4100 | * vport discovery */ |
| 4101 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 4102 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4103 | else { |
| 4104 | shost = lpfc_shost_from_vport(vport); |
| 4105 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 4106 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4107 | spin_unlock_irq(shost->host_lock); |
| 4108 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4109 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4113 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4114 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4115 | |
| 4116 | /* Drop the reference count from the mbox at the end after |
| 4117 | * all the current reference to the ndlp have been done. |
| 4118 | */ |
| 4119 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | return; |
| 4121 | } |
| 4122 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4123 | /* |
| 4124 | * This routine will issue a GID_FT for each FC4 Type supported |
| 4125 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 4126 | */ |
| 4127 | int |
| 4128 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 4129 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4130 | /* Good status, issue CT Request to NameServer */ |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4131 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4132 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4133 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 4134 | /* Cannot issue NameServer FCP Query, so finish up |
| 4135 | * discovery |
| 4136 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4137 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4138 | LOG_TRACE_EVENT, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4139 | "0604 %s FC TYPE %x %s\n", |
| 4140 | "Failed to issue GID_FT to ", |
| 4141 | FC_TYPE_FCP, |
| 4142 | "Finishing discovery."); |
| 4143 | return 0; |
| 4144 | } |
| 4145 | vport->gidft_inp++; |
| 4146 | } |
| 4147 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4148 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4149 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4150 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 4151 | /* Cannot issue NameServer NVME Query, so finish up |
| 4152 | * discovery |
| 4153 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4154 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4155 | LOG_TRACE_EVENT, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4156 | "0605 %s FC_TYPE %x %s %d\n", |
| 4157 | "Failed to issue GID_FT to ", |
| 4158 | FC_TYPE_NVME, |
| 4159 | "Finishing discovery: gidftinp ", |
| 4160 | vport->gidft_inp); |
| 4161 | if (vport->gidft_inp == 0) |
| 4162 | return 0; |
| 4163 | } else |
| 4164 | vport->gidft_inp++; |
| 4165 | } |
| 4166 | return vport->gidft_inp; |
| 4167 | } |
| 4168 | |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 4169 | /** |
| 4170 | * lpfc_issue_gidpt - issue a GID_PT for all N_Ports |
| 4171 | * @vport: The virtual port for which this call is being executed. |
| 4172 | * |
| 4173 | * This routine will issue a GID_PT to get a list of all N_Ports |
| 4174 | * |
| 4175 | * Return value : |
| 4176 | * 0 - Failure to issue a GID_PT |
| 4177 | * 1 - GID_PT issued |
| 4178 | **/ |
| 4179 | int |
| 4180 | lpfc_issue_gidpt(struct lpfc_vport *vport) |
| 4181 | { |
| 4182 | /* Good status, issue CT Request to NameServer */ |
| 4183 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) { |
| 4184 | /* Cannot issue NameServer FCP Query, so finish up |
| 4185 | * discovery |
| 4186 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4187 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 4188 | "0606 %s Port TYPE %x %s\n", |
| 4189 | "Failed to issue GID_PT to ", |
| 4190 | GID_PT_N_PORT, |
| 4191 | "Finishing discovery."); |
| 4192 | return 0; |
| 4193 | } |
| 4194 | vport->gidft_inp++; |
| 4195 | return 1; |
| 4196 | } |
| 4197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | /* |
| 4199 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 4200 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4201 | * as the completion routine when the command is |
| 4202 | * handed off to the SLI layer. |
| 4203 | */ |
| 4204 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4207 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4208 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4209 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4210 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4212 | pmb->ctx_buf = NULL; |
| 4213 | pmb->ctx_ndlp = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4214 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4217 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4218 | "0260 Register NameServer error: 0x%x\n", |
| 4219 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4220 | |
| 4221 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4222 | /* decrement the node reference count held for this |
| 4223 | * callback function. |
| 4224 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4225 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4227 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4228 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4229 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 4230 | /* If the node is not registered with the scsi or nvme |
| 4231 | * transport, remove the fabric node. The failed reg_login |
| 4232 | * is terminal. |
| 4233 | */ |
| 4234 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { |
| 4235 | spin_lock_irq(&ndlp->lock); |
| 4236 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 4237 | spin_unlock_irq(&ndlp->lock); |
| 4238 | lpfc_nlp_not_used(ndlp); |
| 4239 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4241 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4242 | /* |
| 4243 | * RegLogin failed, use loop map to make discovery |
| 4244 | * list |
| 4245 | */ |
| 4246 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4248 | /* Start discovery */ |
| 4249 | lpfc_disc_start(vport); |
| 4250 | return; |
| 4251 | } |
| 4252 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | return; |
| 4254 | } |
| 4255 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4256 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4257 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4258 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4260 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4261 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4262 | "0003 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4263 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4264 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4265 | ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4267 | if (vport->port_state < LPFC_VPORT_READY) { |
| 4268 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4269 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 4270 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 4271 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 4272 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4273 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4274 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4275 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4276 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 4277 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4278 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4279 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4280 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 4281 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4282 | |
| 4283 | /* Issue SCR just before NameServer GID_FT Query */ |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 4284 | lpfc_issue_els_scr(vport, 0); |
| 4285 | |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 4286 | if (!phba->cfg_enable_mi || |
| 4287 | phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT) |
| 4288 | lpfc_issue_els_rdf(vport, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | } |
| 4290 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4292 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4293 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4295 | /* |
| 4296 | * At this point in time we may need to wait for multiple |
| 4297 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 4298 | * |
| 4299 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4300 | * callback function. |
| 4301 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4302 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4304 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | |
| 4307 | return; |
| 4308 | } |
| 4309 | |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame] | 4310 | /* |
| 4311 | * This routine handles processing a Fabric Controller REG_LOGIN mailbox |
| 4312 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4313 | * as the completion routine when the command is handed off to the SLI layer. |
| 4314 | */ |
| 4315 | void |
| 4316 | lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4317 | { |
| 4318 | struct lpfc_vport *vport = pmb->vport; |
| 4319 | MAILBOX_t *mb = &pmb->u.mb; |
| 4320 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4321 | struct lpfc_nodelist *ndlp; |
| 4322 | |
| 4323 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 4324 | pmb->ctx_ndlp = NULL; |
| 4325 | pmb->ctx_buf = NULL; |
| 4326 | |
| 4327 | if (mb->mbxStatus) { |
| 4328 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 4329 | "0933 %s: Register FC login error: 0x%x\n", |
| 4330 | __func__, mb->mbxStatus); |
| 4331 | goto out; |
| 4332 | } |
| 4333 | |
| 4334 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4335 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| 4336 | |
| 4337 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4338 | "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n", |
| 4339 | __func__, ndlp->nlp_DID, ndlp->nlp_rpi, |
| 4340 | ndlp->nlp_state); |
| 4341 | |
| 4342 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 4343 | ndlp->nlp_type |= NLP_FABRIC; |
| 4344 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| 4345 | |
| 4346 | out: |
| 4347 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4348 | kfree(mp); |
| 4349 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4350 | |
| 4351 | /* Drop the reference count from the mbox at the end after |
| 4352 | * all the current reference to the ndlp have been done. |
| 4353 | */ |
| 4354 | lpfc_nlp_put(ndlp); |
| 4355 | } |
| 4356 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4358 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4361 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | struct lpfc_rport_data *rdata; |
| 4363 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | struct lpfc_hba *phba = vport->phba; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4365 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4367 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4368 | return; |
| 4369 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4371 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4372 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | rport_ids.port_id = ndlp->nlp_DID; |
| 4374 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4376 | |
| 4377 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4378 | "rport add: did:x%x flg:x%x type x%x", |
| 4379 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4380 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4381 | /* Don't add the remote port if unloading. */ |
| 4382 | if (vport->load_flag & FC_UNLOADING) |
| 4383 | return; |
| 4384 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4385 | /* |
| 4386 | * Disassociate any older association between this ndlp and rport |
| 4387 | */ |
| 4388 | if (ndlp->rport) { |
| 4389 | rdata = ndlp->rport->dd_data; |
| 4390 | rdata->pnode = NULL; |
| 4391 | } |
| 4392 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4393 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 4394 | if (!rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4396 | "Warning: fc_remote_port_add failed\n"); |
| 4397 | return; |
| 4398 | } |
| 4399 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4400 | /* Successful port add. Complete initializing node data */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4402 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4404 | rdata->pnode = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4405 | if (!rdata->pnode) { |
| 4406 | dev_warn(&phba->pcidev->dev, |
| 4407 | "Warning - node ref failed. Unreg rport\n"); |
| 4408 | fc_remote_port_delete(rport); |
| 4409 | ndlp->rport = NULL; |
| 4410 | return; |
| 4411 | } |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4412 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4413 | spin_lock_irqsave(&ndlp->lock, flags); |
| 4414 | ndlp->fc4_xpt_flags |= SCSI_XPT_REGD; |
| 4415 | spin_unlock_irqrestore(&ndlp->lock, flags); |
| 4416 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4417 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4418 | rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4419 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4420 | rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; |
| 4421 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) |
| 4422 | rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; |
| 4423 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4424 | rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; |
| 4425 | if (ndlp->nlp_type & NLP_NVME_DISCOVERY) |
| 4426 | rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4427 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4428 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4429 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4430 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4431 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4432 | "3183 %s rport x%px DID x%x, role x%x\n", |
| 4433 | __func__, rport, rport->port_id, rport->roles); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4434 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4435 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4436 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4437 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4438 | } |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 4439 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4440 | return; |
| 4441 | } |
| 4442 | |
| 4443 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4444 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4445 | { |
| 4446 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4447 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4448 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4449 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4450 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4451 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4452 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4453 | "rport delete: did:x%x flg:x%x type x%x", |
| 4454 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4455 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4456 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4457 | "3184 rport unregister x%06x, rport x%px " |
| 4458 | "xptflg x%x\n", |
| 4459 | ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4460 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4461 | fc_remote_port_delete(rport); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4462 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | } |
| 4464 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4465 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4466 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4467 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4468 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4469 | unsigned long iflags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4470 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4471 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4472 | switch (state) { |
| 4473 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4474 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4475 | break; |
| 4476 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4477 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4478 | break; |
| 4479 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4481 | break; |
| 4482 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4483 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4484 | break; |
| 4485 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4486 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4487 | break; |
| 4488 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4489 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4490 | break; |
| 4491 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4492 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4493 | break; |
| 4494 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4495 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4496 | vport->fc_npr_cnt = 0; |
| 4497 | else |
| 4498 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4499 | break; |
| 4500 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4501 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4502 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4503 | |
James Smart | 0614568 | 2021-07-07 11:43:46 -0700 | [diff] [blame^] | 4504 | /* Register a node with backend if not already done */ |
| 4505 | void |
| 4506 | lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4507 | { |
| 4508 | |
| 4509 | unsigned long iflags; |
| 4510 | |
| 4511 | spin_lock_irqsave(&ndlp->lock, iflags); |
| 4512 | if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) { |
| 4513 | /* Already registered with backend, trigger rescan */ |
| 4514 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
| 4515 | |
| 4516 | if (ndlp->fc4_xpt_flags & NVME_XPT_REGD && |
| 4517 | ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) { |
| 4518 | lpfc_nvme_rescan_port(vport, ndlp); |
| 4519 | } |
| 4520 | return; |
| 4521 | } |
| 4522 | |
| 4523 | ndlp->fc4_xpt_flags |= NLP_XPT_REGD; |
| 4524 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
| 4525 | |
| 4526 | if (lpfc_valid_xpt_node(ndlp)) { |
| 4527 | vport->phba->nport_event_cnt++; |
| 4528 | /* |
| 4529 | * Tell the fc transport about the port, if we haven't |
| 4530 | * already. If we have, and it's a scsi entity, be |
| 4531 | */ |
| 4532 | lpfc_register_remote_port(vport, ndlp); |
| 4533 | } |
| 4534 | |
| 4535 | /* We are done if we do not have any NVME remote node */ |
| 4536 | if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME)) |
| 4537 | return; |
| 4538 | |
| 4539 | /* Notify the NVME transport of this new rport. */ |
| 4540 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
| 4541 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
| 4542 | if (vport->phba->nvmet_support == 0) { |
| 4543 | /* Register this rport with the transport. |
| 4544 | * Only NVME Target Rports are registered with |
| 4545 | * the transport. |
| 4546 | */ |
| 4547 | if (ndlp->nlp_type & NLP_NVME_TARGET) { |
| 4548 | vport->phba->nport_event_cnt++; |
| 4549 | lpfc_nvme_register_port(vport, ndlp); |
| 4550 | } |
| 4551 | } else { |
| 4552 | /* Just take an NDLP ref count since the |
| 4553 | * target does not register rports. |
| 4554 | */ |
| 4555 | lpfc_nlp_get(ndlp); |
| 4556 | } |
| 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | /* Unregister a node with backend if not already done */ |
| 4561 | void |
| 4562 | lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4563 | { |
| 4564 | unsigned long iflags; |
| 4565 | |
| 4566 | spin_lock_irqsave(&ndlp->lock, iflags); |
| 4567 | if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) { |
| 4568 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
| 4569 | return; |
| 4570 | } |
| 4571 | |
| 4572 | ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD; |
| 4573 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
| 4574 | |
| 4575 | if (ndlp->rport && |
| 4576 | ndlp->fc4_xpt_flags & SCSI_XPT_REGD) { |
| 4577 | vport->phba->nport_event_cnt++; |
| 4578 | lpfc_unregister_remote_port(ndlp); |
| 4579 | } |
| 4580 | |
| 4581 | if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) { |
| 4582 | vport->phba->nport_event_cnt++; |
| 4583 | if (vport->phba->nvmet_support == 0) { |
| 4584 | /* Start devloss if target. */ |
| 4585 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4586 | lpfc_nvme_unregister_port(vport, ndlp); |
| 4587 | } else { |
| 4588 | /* NVMET has no upcall. */ |
| 4589 | lpfc_nlp_put(ndlp); |
| 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | } |
| 4594 | |
| 4595 | /* |
| 4596 | * Adisc state change handling |
| 4597 | */ |
| 4598 | static void |
| 4599 | lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4600 | int new_state) |
| 4601 | { |
| 4602 | switch (new_state) { |
| 4603 | /* |
| 4604 | * Any state to ADISC_ISSUE |
| 4605 | * Do nothing, adisc cmpl handling will trigger state changes |
| 4606 | */ |
| 4607 | case NLP_STE_ADISC_ISSUE: |
| 4608 | break; |
| 4609 | |
| 4610 | /* |
| 4611 | * ADISC_ISSUE to mapped states |
| 4612 | * Trigger a registration with backend, it will be nop if |
| 4613 | * already registered |
| 4614 | */ |
| 4615 | case NLP_STE_UNMAPPED_NODE: |
| 4616 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4617 | fallthrough; |
| 4618 | case NLP_STE_MAPPED_NODE: |
| 4619 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4620 | lpfc_nlp_reg_node(vport, ndlp); |
| 4621 | break; |
| 4622 | |
| 4623 | /* |
| 4624 | * ADISC_ISSUE to non-mapped states |
| 4625 | * We are moving from ADISC_ISSUE to a non-mapped state because |
| 4626 | * ADISC failed, we would have skipped unregistering with |
| 4627 | * backend, attempt it now |
| 4628 | */ |
| 4629 | case NLP_STE_NPR_NODE: |
| 4630 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| 4631 | fallthrough; |
| 4632 | default: |
| 4633 | lpfc_nlp_unreg_node(vport, ndlp); |
| 4634 | break; |
| 4635 | } |
| 4636 | |
| 4637 | } |
| 4638 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4639 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4640 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4641 | int old_state, int new_state) |
| 4642 | { |
James Smart | 0614568 | 2021-07-07 11:43:46 -0700 | [diff] [blame^] | 4643 | /* Trap ADISC changes here */ |
| 4644 | if (new_state == NLP_STE_ADISC_ISSUE || |
| 4645 | old_state == NLP_STE_ADISC_ISSUE) { |
| 4646 | lpfc_handle_adisc_state(vport, ndlp, new_state); |
| 4647 | return; |
| 4648 | } |
| 4649 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4650 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4651 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4652 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4653 | } |
| 4654 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4655 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4656 | if (new_state == NLP_STE_NPR_NODE) |
| 4657 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4658 | |
James Smart | 0614568 | 2021-07-07 11:43:46 -0700 | [diff] [blame^] | 4659 | /* Reg/Unreg for FCP and NVME Transport interface */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4660 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4661 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 0614568 | 2021-07-07 11:43:46 -0700 | [diff] [blame^] | 4662 | /* For nodes marked for ADISC, Handle unreg in ADISC cmpl */ |
| 4663 | if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) |
| 4664 | lpfc_nlp_unreg_node(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4665 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4666 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4667 | if (new_state == NLP_STE_MAPPED_NODE || |
James Smart | 0614568 | 2021-07-07 11:43:46 -0700 | [diff] [blame^] | 4668 | new_state == NLP_STE_UNMAPPED_NODE) |
| 4669 | lpfc_nlp_reg_node(vport, ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4670 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4671 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4672 | (vport->stat_data_enabled)) { |
| 4673 | /* |
| 4674 | * A new target is discovered, if there is no buffer for |
| 4675 | * statistical data collection allocate buffer. |
| 4676 | */ |
| 4677 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4678 | sizeof(struct lpfc_scsicmd_bkt), |
| 4679 | GFP_KERNEL); |
| 4680 | |
| 4681 | if (!ndlp->lat_data) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4682 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4683 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4684 | "allocate statistical data buffer DID " |
| 4685 | "0x%x\n", ndlp->nlp_DID); |
| 4686 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4687 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4688 | * If the node just added to Mapped list was an FCP target, |
| 4689 | * but the remote port registration failed or assigned a target |
| 4690 | * id outside the presentable range - move the node to the |
| 4691 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4692 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4693 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4694 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4695 | (!ndlp->rport || |
| 4696 | ndlp->rport->scsi_target_id == -1 || |
| 4697 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4698 | spin_lock_irq(&ndlp->lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4699 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4700 | spin_unlock_irq(&ndlp->lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4701 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4703 | } |
| 4704 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4705 | static char * |
| 4706 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4707 | { |
| 4708 | static char *states[] = { |
| 4709 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4710 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4711 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4712 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4713 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4714 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4715 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4716 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4717 | [NLP_STE_NPR_NODE] = "NPR", |
| 4718 | }; |
| 4719 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4720 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4721 | strlcpy(buffer, states[state], size); |
| 4722 | else |
| 4723 | snprintf(buffer, size, "unknown (%d)", state); |
| 4724 | return buffer; |
| 4725 | } |
| 4726 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4727 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4729 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4730 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4731 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4732 | int old_state = ndlp->nlp_state; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4733 | int node_dropped = ndlp->nlp_flag & NLP_DROPPED; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4734 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4735 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4736 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4737 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4738 | ndlp->nlp_DID, |
| 4739 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4740 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4741 | |
| 4742 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4743 | "node statechg did:x%x old:%d ste:%d", |
| 4744 | ndlp->nlp_DID, old_state, state); |
| 4745 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4746 | if (node_dropped && old_state == NLP_STE_UNUSED_NODE && |
| 4747 | state != NLP_STE_UNUSED_NODE) { |
| 4748 | ndlp->nlp_flag &= ~NLP_DROPPED; |
| 4749 | lpfc_nlp_get(ndlp); |
| 4750 | } |
| 4751 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4752 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4753 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4754 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4755 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4756 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4757 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4758 | } |
| 4759 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4760 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4761 | spin_lock_irq(shost->host_lock); |
| 4762 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4763 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4764 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4765 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4766 | |
| 4767 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4768 | lpfc_nlp_counters(vport, state, 1); |
| 4769 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4773 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4774 | { |
| 4775 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4776 | |
| 4777 | if (list_empty(&ndlp->nlp_listp)) { |
| 4778 | spin_lock_irq(shost->host_lock); |
| 4779 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4780 | spin_unlock_irq(shost->host_lock); |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4786 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4788 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4789 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4790 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4791 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4792 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4793 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4794 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4795 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4796 | NLP_STE_UNUSED_NODE); |
| 4797 | } |
| 4798 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4800 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4801 | * @vport: Pointer to Virtual Port object. |
| 4802 | * @ndlp: Pointer to FC node object. |
| 4803 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4804 | * |
| 4805 | * This function is always called when node object need to be initialized. |
| 4806 | * It initializes all the fields of the node object. Although the reference |
| 4807 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4808 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4809 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4810 | * the final release of ndlp is determined by its reference count. And, the |
| 4811 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4812 | **/ |
| 4813 | static inline void |
| 4814 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4815 | uint32_t did) |
| 4816 | { |
| 4817 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4818 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4819 | timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 4820 | INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp); |
| 4821 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4822 | ndlp->nlp_DID = did; |
| 4823 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4824 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4825 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4826 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4827 | kref_init(&ndlp->kref); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4828 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4829 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4830 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4831 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4832 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4833 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4834 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4835 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4836 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4837 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4838 | * be used if we wish to issue the "last" lpfc_nlp_put() to remove |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4839 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4840 | * until ALL other outstanding threads have completed. We check |
| 4841 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4842 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4843 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4844 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4845 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4846 | ndlp->nlp_flag |= NLP_DROPPED; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4847 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4848 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4849 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4850 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4851 | |
| 4852 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4853 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | /* |
| 4857 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4858 | */ |
| 4859 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4860 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4862 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4863 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4864 | uint32_t tmo; |
| 4865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4866 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4867 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4868 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4869 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4870 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4871 | * FC spec states we need 3 * ratov for CT requests |
| 4872 | */ |
| 4873 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4874 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4875 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4876 | |
| 4877 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4878 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4879 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4880 | tmo, vport->port_state, vport->fc_flag); |
| 4881 | } |
| 4882 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4883 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4884 | spin_lock_irq(shost->host_lock); |
| 4885 | vport->fc_flag |= FC_DISC_TMO; |
| 4886 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4887 | |
| 4888 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4889 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4890 | "0247 Start Discovery Timer state x%x " |
| 4891 | "Data: x%x x%lx x%x x%x\n", |
| 4892 | vport->port_state, tmo, |
| 4893 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4894 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4895 | |
| 4896 | return; |
| 4897 | } |
| 4898 | |
| 4899 | /* |
| 4900 | * Cancel rescue timer for Discovery / RSCN handling |
| 4901 | */ |
| 4902 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4905 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4906 | unsigned long iflags; |
| 4907 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4908 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4909 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4910 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4912 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4913 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4914 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4915 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4916 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4917 | del_timer_sync(&vport->fc_disctmo); |
| 4918 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4919 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4920 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4924 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4925 | "0248 Cancel Discovery Timer state x%x " |
| 4926 | "Data: x%x x%x x%x\n", |
| 4927 | vport->port_state, vport->fc_flag, |
| 4928 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4929 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | /* |
| 4933 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4934 | * Return true if iocb matches the specified nport |
| 4935 | */ |
| 4936 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4937 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4938 | struct lpfc_sli_ring *pring, |
| 4939 | struct lpfc_iocbq *iocb, |
| 4940 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4943 | struct lpfc_vport *vport = ndlp->vport; |
| 4944 | |
| 4945 | if (iocb->vport != vport) |
| 4946 | return 0; |
| 4947 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4948 | if (pring->ringno == LPFC_ELS_RING) { |
| 4949 | switch (icmd->ulpCommand) { |
| 4950 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4951 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4952 | return 1; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4953 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4955 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4956 | return 1; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4957 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | case CMD_XMIT_ELS_RSP64_CX: |
| 4959 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4960 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4962 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | /* Skip match check if waiting to relogin to FCP target */ |
| 4964 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4965 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4966 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | } |
| 4968 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4969 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4972 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | } |
| 4974 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4975 | static void |
| 4976 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4977 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4978 | struct list_head *dequeue_list) |
| 4979 | { |
| 4980 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4981 | |
| 4982 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4983 | /* Check to see if iocb matches the nport */ |
| 4984 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4985 | /* match, dequeue */ |
| 4986 | list_move_tail(&iocb->list, dequeue_list); |
| 4987 | } |
| 4988 | } |
| 4989 | |
| 4990 | static void |
| 4991 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4992 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4993 | { |
| 4994 | struct lpfc_sli *psli = &phba->sli; |
| 4995 | uint32_t i; |
| 4996 | |
| 4997 | spin_lock_irq(&phba->hbalock); |
| 4998 | for (i = 0; i < psli->num_rings; i++) |
| 4999 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 5000 | dequeue_list); |
| 5001 | spin_unlock_irq(&phba->hbalock); |
| 5002 | } |
| 5003 | |
| 5004 | static void |
| 5005 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 5006 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 5007 | { |
| 5008 | struct lpfc_sli_ring *pring; |
| 5009 | struct lpfc_queue *qp = NULL; |
| 5010 | |
| 5011 | spin_lock_irq(&phba->hbalock); |
| 5012 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 5013 | pring = qp->pring; |
| 5014 | if (!pring) |
| 5015 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 5016 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5017 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 5018 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5019 | } |
| 5020 | spin_unlock_irq(&phba->hbalock); |
| 5021 | } |
| 5022 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | /* |
| 5024 | * Free resources / clean up outstanding I/Os |
| 5025 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 5026 | */ |
| 5027 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5028 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5029 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5030 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5032 | lpfc_fabric_abort_nport(ndlp); |
| 5033 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5034 | /* |
| 5035 | * Everything that matches on txcmplq will be returned |
| 5036 | * by firmware with a no rpi error. |
| 5037 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5038 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5039 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 5040 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 5041 | else |
| 5042 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5044 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5045 | /* Cancel all the IOCBs from the completions list */ |
| 5046 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5047 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5048 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5049 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | } |
| 5051 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5052 | /** |
| 5053 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 5054 | * @phba: Pointer to HBA context object. |
| 5055 | * @pmb: Pointer to mailbox object. |
| 5056 | * |
| 5057 | * This function will issue an ELS LOGO command after completing |
| 5058 | * the UNREG_RPI. |
| 5059 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 5060 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5061 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5062 | { |
| 5063 | struct lpfc_vport *vport = pmb->vport; |
| 5064 | struct lpfc_nodelist *ndlp; |
| 5065 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5066 | ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5067 | if (!ndlp) |
| 5068 | return; |
| 5069 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 5070 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5071 | |
| 5072 | /* Check to see if there are any deferred events to process */ |
| 5073 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 5074 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
| 5075 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5076 | "1434 UNREG cmpl deferred logo x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5077 | "on NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5078 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5079 | ndlp->nlp_defer_did, ndlp); |
| 5080 | |
| 5081 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 5082 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 5083 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 5084 | } else { |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5085 | /* NLP_RELEASE_RPI is only set for SLI4 ports. */ |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5086 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 5087 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5088 | spin_lock_irq(&ndlp->lock); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5089 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5090 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5091 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5092 | } |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5093 | spin_lock_irq(&ndlp->lock); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 5094 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5095 | spin_unlock_irq(&ndlp->lock); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5096 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5097 | } |
| 5098 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | /* |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5100 | * Sets the mailbox completion handler to be used for the |
| 5101 | * unreg_rpi command. The handler varies based on the state of |
| 5102 | * the port and what will be happening to the rpi next. |
| 5103 | */ |
| 5104 | static void |
| 5105 | lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5106 | struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox) |
| 5107 | { |
| 5108 | unsigned long iflags; |
| 5109 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 5110 | /* Driver always gets a reference on the mailbox job |
| 5111 | * in support of async jobs. |
| 5112 | */ |
| 5113 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
| 5114 | if (!mbox->ctx_ndlp) |
| 5115 | return; |
| 5116 | |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5117 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5118 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 5119 | |
| 5120 | } else if (phba->sli_rev == LPFC_SLI_REV4 && |
| 5121 | (!(vport->load_flag & FC_UNLOADING)) && |
| 5122 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >= |
| 5123 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 5124 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5125 | mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr; |
| 5126 | } else { |
| 5127 | if (vport->load_flag & FC_UNLOADING) { |
| 5128 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5129 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5130 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5131 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5132 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5133 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5134 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5139 | * Free rpi associated with LPFC_NODELIST entry. |
| 5140 | * This routine is called from lpfc_freenode(), when we are removing |
| 5141 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 5142 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 5143 | * to the remote NPort. In addition, it is called after we receive |
| 5144 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 5145 | * we are waiting to PLOGI back to the remote NPort. |
| 5146 | */ |
| 5147 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5148 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5150 | struct lpfc_hba *phba = vport->phba; |
| 5151 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5152 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5153 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5154 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 5155 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 5156 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 5157 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5158 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5159 | LOG_NODE | LOG_DISCOVERY, |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 5160 | "3366 RPI x%x needs to be " |
| 5161 | "unregistered nlp_flag x%x " |
| 5162 | "did x%x\n", |
| 5163 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 5164 | ndlp->nlp_DID); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5165 | |
| 5166 | /* If there is already an UNREG in progress for this ndlp, |
| 5167 | * no need to queue up another one. |
| 5168 | */ |
| 5169 | if (ndlp->nlp_flag & NLP_UNREG_INP) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5170 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5171 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5172 | "1436 unreg_rpi SKIP UNREG x%x on " |
| 5173 | "NPort x%x deferred x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5174 | "Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5175 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5176 | ndlp->nlp_defer_did, |
| 5177 | ndlp->nlp_flag, ndlp); |
| 5178 | goto out; |
| 5179 | } |
| 5180 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5181 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5182 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5183 | /* SLI4 ports require the physical rpi value. */ |
| 5184 | rpi = ndlp->nlp_rpi; |
| 5185 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5186 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5187 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5188 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5189 | mbox->vport = vport; |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5190 | lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox); |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 5191 | if (!mbox->ctx_ndlp) { |
| 5192 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5193 | return 1; |
| 5194 | } |
| 5195 | |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5196 | if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr) |
| 5197 | /* |
| 5198 | * accept PLOGIs after unreg_rpi_cmpl |
| 5199 | */ |
| 5200 | acc_plogi = 0; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5201 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != |
| 5202 | Fabric_DID_MASK) && |
| 5203 | (!(vport->fc_flag & FC_OFFLINE_MODE))) |
| 5204 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 5205 | |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5206 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5207 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5208 | "1433 unreg_rpi UNREG x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5209 | "NPort x%x deferred flg x%x " |
| 5210 | "Data:x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5211 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5212 | ndlp->nlp_flag, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5213 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5214 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5215 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5216 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5217 | acc_plogi = 1; |
| 5218 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5219 | } else { |
| 5220 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5221 | LOG_NODE | LOG_DISCOVERY, |
| 5222 | "1444 Failed to allocate mempool " |
| 5223 | "unreg_rpi UNREG x%x, " |
| 5224 | "DID x%x, flag x%x, " |
| 5225 | "ndlp x%px\n", |
| 5226 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5227 | ndlp->nlp_flag, ndlp); |
| 5228 | |
| 5229 | /* Because mempool_alloc failed, we |
| 5230 | * will issue a LOGO here and keep the rpi alive if |
| 5231 | * not unloading. |
| 5232 | */ |
| 5233 | if (!(vport->load_flag & FC_UNLOADING)) { |
| 5234 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 5235 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 5236 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 5237 | lpfc_nlp_set_state(vport, ndlp, |
| 5238 | NLP_STE_NPR_NODE); |
| 5239 | } |
| 5240 | |
| 5241 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5243 | lpfc_no_rpi(phba, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 5244 | out: |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5245 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 5246 | ndlp->nlp_rpi = 0; |
| 5247 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 5248 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5249 | if (acc_plogi) |
| 5250 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | return 1; |
| 5252 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5253 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | return 0; |
| 5255 | } |
| 5256 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5257 | /** |
| 5258 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 5259 | * @phba: pointer to lpfc hba data structure. |
| 5260 | * |
| 5261 | * This routine is invoked to unregister all the currently registered RPIs |
| 5262 | * to the HBA. |
| 5263 | **/ |
| 5264 | void |
| 5265 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 5266 | { |
| 5267 | struct lpfc_vport **vports; |
| 5268 | struct lpfc_nodelist *ndlp; |
| 5269 | struct Scsi_Host *shost; |
| 5270 | int i; |
| 5271 | |
| 5272 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5273 | if (!vports) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5274 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5275 | "2884 Vport array allocation failed \n"); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5276 | return; |
| 5277 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5278 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5279 | shost = lpfc_shost_from_vport(vports[i]); |
| 5280 | spin_lock_irq(shost->host_lock); |
| 5281 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5282 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5283 | /* The mempool_alloc might sleep */ |
| 5284 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5285 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5286 | spin_lock_irq(shost->host_lock); |
| 5287 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5288 | } |
| 5289 | spin_unlock_irq(shost->host_lock); |
| 5290 | } |
| 5291 | lpfc_destroy_vport_work_array(phba, vports); |
| 5292 | } |
| 5293 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5294 | void |
| 5295 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 5296 | { |
| 5297 | struct lpfc_hba *phba = vport->phba; |
| 5298 | LPFC_MBOXQ_t *mbox; |
| 5299 | int rc; |
| 5300 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5301 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 5302 | lpfc_sli4_unreg_all_rpis(vport); |
| 5303 | return; |
| 5304 | } |
| 5305 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5306 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5307 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5308 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 5309 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5310 | mbox->vport = vport; |
| 5311 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5312 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5313 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5314 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5315 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5316 | |
| 5317 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5318 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 5319 | "1836 Could not issue " |
| 5320 | "unreg_login(all_rpis) status %d\n", |
| 5321 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | void |
| 5326 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 5327 | { |
| 5328 | struct lpfc_hba *phba = vport->phba; |
| 5329 | LPFC_MBOXQ_t *mbox; |
| 5330 | int rc; |
| 5331 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 5332 | /* Unreg DID is an SLI3 operation. */ |
| 5333 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 5334 | return; |
| 5335 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5336 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5337 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5338 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 5339 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5340 | mbox->vport = vport; |
| 5341 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5342 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5343 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5344 | if (rc != MBX_TIMEOUT) |
| 5345 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5346 | |
| 5347 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5348 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5349 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5350 | "unreg_did (default rpis) status %d\n", |
| 5351 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5355 | /* |
| 5356 | * Free resources associated with LPFC_NODELIST entry |
| 5357 | * so it can be freed. |
| 5358 | */ |
| 5359 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5360 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5361 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5362 | struct lpfc_hba *phba = vport->phba; |
| 5363 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5365 | |
| 5366 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5367 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5368 | "0900 Cleanup node for NPort x%x " |
| 5369 | "Data: x%x x%x x%x\n", |
| 5370 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5371 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5372 | lpfc_dequeue_node(vport, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5373 | |
| 5374 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 5375 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5376 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 5377 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5378 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5379 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5380 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5381 | mb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5382 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5383 | } |
| 5384 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 5385 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5386 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5387 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 5388 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 5389 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5390 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5391 | (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp)) |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5392 | continue; |
| 5393 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5394 | mb->ctx_ndlp = NULL; |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5395 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5396 | } |
| 5397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5398 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5399 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5400 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5401 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5402 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5403 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5404 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5405 | kfree(mp); |
| 5406 | } |
| 5407 | list_del(&mb->list); |
| 5408 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5409 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 5410 | * the ndlp reference count as we are in the process |
| 5411 | * of lpfc_nlp_release. |
| 5412 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | } |
| 5414 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5415 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5417 | lpfc_els_abort(phba, ndlp); |
| 5418 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5419 | spin_lock_irq(&ndlp->lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 5420 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5421 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5422 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5423 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 5425 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5426 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 5427 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5428 | list_del_init(&ndlp->recovery_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5429 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5430 | |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5431 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5432 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5433 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5434 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | } |
| 5436 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5437 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5438 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5439 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5441 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5442 | |
| 5443 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5444 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | /* First check for Direct match */ |
| 5447 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5448 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5449 | |
| 5450 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5451 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5453 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | matchdid.un.word = did; |
| 5457 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5458 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5459 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5460 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5461 | /* This code is supposed to match the ID |
| 5462 | * for a private loop device that is |
| 5463 | * connect to fl_port. But we need to |
| 5464 | * check that the port did not just go |
| 5465 | * from pt2pt to fabric or we could end |
| 5466 | * up matching ndlp->nlp_DID 000001 to |
| 5467 | * fabric DID 0x20101 |
| 5468 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5469 | if ((ndlpdid.un.b.domain == 0) && |
| 5470 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5471 | if (ndlpdid.un.b.id && |
| 5472 | vport->phba->fc_topology == |
| 5473 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5474 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5476 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5477 | } |
| 5478 | |
| 5479 | matchdid.un.word = ndlp->nlp_DID; |
| 5480 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5481 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5482 | if ((matchdid.un.b.domain == 0) && |
| 5483 | (matchdid.un.b.area == 0)) { |
| 5484 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5485 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | } |
| 5487 | } |
| 5488 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5489 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | } |
| 5491 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5492 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5493 | static struct lpfc_nodelist * |
| 5494 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5495 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5496 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5497 | uint32_t data1; |
| 5498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5499 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5500 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5501 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5502 | ((uint32_t)ndlp->nlp_xri << 16) | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5503 | ((uint32_t)ndlp->nlp_type << 8) |
| 5504 | ); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5505 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5506 | "0929 FIND node DID " |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5507 | "Data: x%px x%x x%x x%x x%x x%px\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5508 | ndlp, ndlp->nlp_DID, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5509 | ndlp->nlp_flag, data1, ndlp->nlp_rpi, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5510 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5511 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5512 | } |
| 5513 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5514 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5515 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5516 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5517 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5518 | return NULL; |
| 5519 | } |
| 5520 | |
| 5521 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5522 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5524 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5525 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5526 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5528 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5529 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5530 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5531 | return ndlp; |
| 5532 | } |
| 5533 | |
| 5534 | struct lpfc_nodelist * |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5535 | lpfc_findnode_mapped(struct lpfc_vport *vport) |
| 5536 | { |
| 5537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5538 | struct lpfc_nodelist *ndlp; |
| 5539 | uint32_t data1; |
| 5540 | unsigned long iflags; |
| 5541 | |
| 5542 | spin_lock_irqsave(shost->host_lock, iflags); |
| 5543 | |
| 5544 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5545 | if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || |
| 5546 | ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 5547 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5548 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5549 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5550 | ((uint32_t)ndlp->nlp_rpi & 0xff)); |
| 5551 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5552 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5553 | "2025 FIND node DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5554 | "Data: x%px x%x x%x x%x x%px\n", |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5555 | ndlp, ndlp->nlp_DID, |
| 5556 | ndlp->nlp_flag, data1, |
| 5557 | ndlp->active_rrqs_xri_bitmap); |
| 5558 | return ndlp; |
| 5559 | } |
| 5560 | } |
| 5561 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5562 | |
| 5563 | /* FIND node did <did> NOT FOUND */ |
| 5564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5565 | "2026 FIND mapped did NOT FOUND.\n"); |
| 5566 | return NULL; |
| 5567 | } |
| 5568 | |
| 5569 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5570 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5571 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | struct lpfc_nodelist *ndlp; |
| 5573 | |
| 5574 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5575 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5576 | if (vport->phba->nvmet_support) |
| 5577 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5579 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5581 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5582 | if (!ndlp) |
| 5583 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5584 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5585 | |
| 5586 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5587 | "6453 Setup New Node 2B_DISC x%x " |
| 5588 | "Data:x%x x%x x%x\n", |
| 5589 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5590 | ndlp->nlp_state, vport->fc_flag); |
| 5591 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5592 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5594 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | return ndlp; |
| 5596 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5597 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5598 | /* The NVME Target does not want to actively manage an rport. |
| 5599 | * The goal is to allow the target to reset its state and clear |
| 5600 | * pending IO in preparation for the initiator to recover. |
| 5601 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5602 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5603 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5605 | |
| 5606 | /* Since this node is marked for discovery, |
| 5607 | * delay timeout is not needed. |
| 5608 | */ |
| 5609 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5610 | |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5611 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5612 | "6455 Setup RSCN Node 2B_DISC x%x " |
| 5613 | "Data:x%x x%x x%x\n", |
| 5614 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5615 | ndlp->nlp_state, vport->fc_flag); |
| 5616 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5617 | /* NVME Target mode waits until rport is known to be |
| 5618 | * impacted by the RSCN before it transitions. No |
| 5619 | * active management - just go to NPR provided the |
| 5620 | * node had a valid login. |
| 5621 | */ |
| 5622 | if (vport->phba->nvmet_support) |
| 5623 | return ndlp; |
| 5624 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5625 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5626 | * we don't need to try to discover it again. |
| 5627 | */ |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5628 | if (ndlp->nlp_flag & NLP_RCV_PLOGI && |
| 5629 | !(ndlp->nlp_type & |
| 5630 | (NLP_FCP_TARGET | NLP_NVME_TARGET))) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5631 | return NULL; |
| 5632 | |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5633 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 5634 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5635 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5636 | spin_lock_irq(&ndlp->lock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5637 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5638 | spin_unlock_irq(&ndlp->lock); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5639 | } else { |
| 5640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5641 | "6456 Skip Setup RSCN Node x%x " |
| 5642 | "Data:x%x x%x x%x\n", |
| 5643 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5644 | ndlp->nlp_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | ndlp = NULL; |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5646 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5647 | } else { |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5648 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5649 | "6457 Setup Active Node 2B_DISC x%x " |
| 5650 | "Data:x%x x%x x%x\n", |
| 5651 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5652 | ndlp->nlp_state, vport->fc_flag); |
| 5653 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5654 | /* If the initiator received a PLOGI from this NPort or if the |
| 5655 | * initiator is already in the process of discovery on it, |
| 5656 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5657 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5658 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5659 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5660 | (!vport->phba->nvmet_support && |
| 5661 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5662 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5663 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5664 | if (vport->phba->nvmet_support) |
| 5665 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5666 | |
| 5667 | /* Moving to NPR state clears unsolicited flags and |
| 5668 | * allows for rediscovery |
| 5669 | */ |
| 5670 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5671 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5672 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5674 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5675 | } |
| 5676 | return ndlp; |
| 5677 | } |
| 5678 | |
| 5679 | /* Build a list of nodes to discover based on the loopmap */ |
| 5680 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5681 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5682 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5683 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | int j; |
| 5685 | uint32_t alpa, index; |
| 5686 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5687 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5688 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5689 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5690 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5691 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | |
| 5693 | /* Check for loop map present or not */ |
| 5694 | if (phba->alpa_map[0]) { |
| 5695 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5696 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5697 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5699 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | } |
| 5701 | } else { |
| 5702 | /* No alpamap, so try all alpa's */ |
| 5703 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5704 | /* If cfg_scan_down is set, start from highest |
| 5705 | * ALPA (0xef) to lowest (0x1). |
| 5706 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5707 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5708 | index = j; |
| 5709 | else |
| 5710 | index = FC_MAXLOOP - j - 1; |
| 5711 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5712 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5713 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5714 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5715 | } |
| 5716 | } |
| 5717 | return; |
| 5718 | } |
| 5719 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5720 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5721 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5722 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5723 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5724 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5725 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5726 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5727 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5728 | int rc; |
| 5729 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5730 | /* |
| 5731 | * if it's not a physical port or if we already send |
| 5732 | * clear_la then don't send it. |
| 5733 | */ |
| 5734 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5735 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5736 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5737 | return; |
| 5738 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5739 | /* Link up discovery */ |
| 5740 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5741 | phba->link_state = LPFC_CLEAR_LA; |
| 5742 | lpfc_clear_la(phba, mbox); |
| 5743 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5744 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5745 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5746 | if (rc == MBX_NOT_FINISHED) { |
| 5747 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5748 | lpfc_disc_flush_list(vport); |
| 5749 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5750 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5751 | phba->link_state = LPFC_HBA_ERROR; |
| 5752 | } |
| 5753 | } |
| 5754 | } |
| 5755 | |
| 5756 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5757 | void |
| 5758 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5759 | { |
| 5760 | LPFC_MBOXQ_t *regvpimbox; |
| 5761 | |
| 5762 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5763 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5764 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5765 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5766 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5767 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5768 | == MBX_NOT_FINISHED) { |
| 5769 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5770 | } |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5775 | void |
| 5776 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5777 | { |
| 5778 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5779 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5780 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5781 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5782 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5783 | if (!lpfc_is_link_up(phba)) { |
| 5784 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5785 | "3315 Link is not up %x\n", |
| 5786 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5787 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5788 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5789 | |
| 5790 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | clear_la_pending = 1; |
| 5792 | else |
| 5793 | clear_la_pending = 0; |
| 5794 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5795 | if (vport->port_state < LPFC_VPORT_READY) |
| 5796 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5797 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5798 | lpfc_set_disctmo(vport); |
| 5799 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5800 | vport->fc_prevDID = vport->fc_myDID; |
| 5801 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5802 | |
| 5803 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5804 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5805 | "0202 Start Discovery port state x%x " |
| 5806 | "flg x%x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5807 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5808 | vport->fc_adisc_cnt, vport->fc_npr_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5809 | |
| 5810 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5811 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5812 | |
| 5813 | if (num_sent) |
| 5814 | return; |
| 5815 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5816 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5818 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5819 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5820 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5821 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5822 | lpfc_issue_reg_vpi(phba, vport); |
| 5823 | return; |
| 5824 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5825 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5826 | /* |
| 5827 | * For SLI2, we need to set port_state to READY and continue |
| 5828 | * discovery. |
| 5829 | */ |
| 5830 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5831 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5832 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5833 | |
| 5834 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5835 | vport->num_disc_nodes = 0; |
| 5836 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5837 | if (vport->fc_npr_cnt) |
| 5838 | lpfc_els_disc_plogi(vport); |
| 5839 | |
| 5840 | if (!vport->num_disc_nodes) { |
| 5841 | spin_lock_irq(shost->host_lock); |
| 5842 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5843 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5844 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5845 | } |
| 5846 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5847 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5848 | } else { |
| 5849 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5850 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5851 | |
| 5852 | if (num_sent) |
| 5853 | return; |
| 5854 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5855 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5856 | /* Check to see if more RSCNs came in while we |
| 5857 | * were processing this one. |
| 5858 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5859 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5860 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5861 | spin_lock_irq(shost->host_lock); |
| 5862 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5863 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5864 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5865 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5866 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5867 | } |
| 5868 | } |
| 5869 | return; |
| 5870 | } |
| 5871 | |
| 5872 | /* |
| 5873 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5874 | * ring the match the sppecified nodelist. |
| 5875 | */ |
| 5876 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5877 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5878 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5879 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5880 | IOCB_t *icmd; |
| 5881 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5882 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5883 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5884 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 5885 | if (unlikely(!pring)) |
| 5886 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5887 | |
| 5888 | /* Error matching iocb on txq or txcmplq |
| 5889 | * First check the txq. |
| 5890 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5891 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5892 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5893 | if (iocb->context1 != ndlp) { |
| 5894 | continue; |
| 5895 | } |
| 5896 | icmd = &iocb->iocb; |
| 5897 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5898 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5899 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5900 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5901 | } |
| 5902 | } |
| 5903 | |
| 5904 | /* Next check the txcmplq */ |
| 5905 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5906 | if (iocb->context1 != ndlp) { |
| 5907 | continue; |
| 5908 | } |
| 5909 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5910 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5911 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5912 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | } |
| 5914 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5915 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5916 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 5917 | /* Make sure HBA is alive */ |
| 5918 | lpfc_issue_hb_tmo(phba); |
| 5919 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5920 | /* Cancel all the IOCBs from the completions list */ |
| 5921 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5922 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5923 | } |
| 5924 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5925 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5926 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5927 | { |
| 5928 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5929 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5931 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5932 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5933 | nlp_listp) { |
| 5934 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5935 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5936 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5938 | } |
| 5939 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5940 | } |
| 5941 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5942 | void |
| 5943 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5944 | { |
| 5945 | lpfc_els_flush_rscn(vport); |
| 5946 | lpfc_els_flush_cmd(vport); |
| 5947 | lpfc_disc_flush_list(vport); |
| 5948 | } |
| 5949 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5950 | /*****************************************************************************/ |
| 5951 | /* |
| 5952 | * NAME: lpfc_disc_timeout |
| 5953 | * |
| 5954 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5955 | * |
| 5956 | * EXECUTION ENVIRONMENT: interrupt only |
| 5957 | * |
| 5958 | * CALLED FROM: |
| 5959 | * Timer function |
| 5960 | * |
| 5961 | * RETURNS: |
| 5962 | * none |
| 5963 | */ |
| 5964 | /*****************************************************************************/ |
| 5965 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5966 | lpfc_disc_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5967 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5968 | struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5969 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5970 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5971 | unsigned long flags = 0; |
| 5972 | |
| 5973 | if (unlikely(!phba)) |
| 5974 | return; |
| 5975 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5976 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5977 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5978 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5979 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5980 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5981 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5982 | if (!tmo_posted) |
| 5983 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5984 | return; |
| 5985 | } |
| 5986 | |
| 5987 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5988 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5990 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5991 | struct lpfc_hba *phba = vport->phba; |
| 5992 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5993 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5994 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5995 | int rc, clrlaerr = 0; |
| 5996 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5997 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5998 | return; |
| 5999 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6000 | spin_lock_irq(shost->host_lock); |
| 6001 | vport->fc_flag &= ~FC_DISC_TMO; |
| 6002 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6003 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6004 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6005 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 6006 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 6007 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6008 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6009 | |
| 6010 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6011 | /* |
| 6012 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 6013 | * waiting for FAN timeout |
| 6014 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6015 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 6016 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6017 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6018 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6019 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6020 | nlp_listp) { |
| 6021 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 6022 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6023 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 6024 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6025 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6026 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 6027 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6028 | /* Fail outstanding IO now since device |
| 6029 | * is marked for PLOGI. |
| 6030 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6031 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6032 | } |
| 6033 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6034 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6035 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 6036 | lpfc_initial_flogi(vport); |
| 6037 | else |
| 6038 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 6039 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6040 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6041 | break; |
| 6042 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6043 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6044 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6045 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6046 | /* Initial FLOGI timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6047 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6048 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6049 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6050 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6051 | |
| 6052 | /* Assume no Fabric and go on with discovery. |
| 6053 | * Check for outstanding ELS FLOGI to abort. |
| 6054 | */ |
| 6055 | |
| 6056 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6057 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6058 | |
| 6059 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6060 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6061 | break; |
| 6062 | |
| 6063 | case LPFC_FABRIC_CFG_LINK: |
| 6064 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 6065 | NameServer login */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6066 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6067 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6068 | "0223 Timeout while waiting for " |
| 6069 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6070 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6071 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6072 | if (ndlp) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6073 | lpfc_els_abort(phba, ndlp); |
| 6074 | |
| 6075 | /* ReStart discovery */ |
| 6076 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6077 | |
| 6078 | case LPFC_NS_QRY: |
| 6079 | /* Check for wait for NameServer Rsp timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6080 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6081 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6082 | "0224 NameServer Query timeout " |
| 6083 | "Data: x%x x%x\n", |
| 6084 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6085 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6086 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 6087 | /* Try it one more time */ |
| 6088 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6089 | vport->gidft_inp = 0; |
| 6090 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6091 | if (rc == 0) |
| 6092 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6093 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6094 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6095 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6096 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6097 | /* |
| 6098 | * Discovery is over. |
| 6099 | * set port_state to PORT_READY if SLI2. |
| 6100 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 6101 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6102 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6103 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 6104 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6105 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6106 | lpfc_issue_clear_la(phba, vport); |
| 6107 | vport->port_state = LPFC_VPORT_READY; |
| 6108 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 6112 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6113 | if (!initlinkmbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6114 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6115 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6116 | "0206 Device Discovery " |
| 6117 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6118 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6119 | break; |
| 6120 | } |
| 6121 | |
| 6122 | lpfc_linkdown(phba); |
| 6123 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 6124 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6125 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6126 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6127 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6128 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 6129 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6130 | if (rc == MBX_NOT_FINISHED) |
| 6131 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 6132 | |
| 6133 | break; |
| 6134 | |
| 6135 | case LPFC_DISC_AUTH: |
| 6136 | /* Node Authentication timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6137 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6138 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6139 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6140 | lpfc_disc_flush_list(vport); |
| 6141 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6142 | /* |
| 6143 | * set port_state to PORT_READY if SLI2. |
| 6144 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 6145 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6146 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 6147 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 6148 | lpfc_issue_reg_vpi(phba, vport); |
| 6149 | else { /* NPIV Not enabled */ |
| 6150 | lpfc_issue_clear_la(phba, vport); |
| 6151 | vport->port_state = LPFC_VPORT_READY; |
| 6152 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6153 | } |
| 6154 | break; |
| 6155 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6156 | case LPFC_VPORT_READY: |
| 6157 | if (vport->fc_flag & FC_RSCN_MODE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6158 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6159 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6160 | "0231 RSCN timeout Data: x%x " |
| 6161 | "x%x\n", |
| 6162 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6163 | |
| 6164 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6165 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6166 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6167 | lpfc_els_flush_rscn(vport); |
| 6168 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6169 | } |
| 6170 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6172 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6173 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6174 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6175 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6176 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6177 | break; |
| 6178 | } |
| 6179 | |
| 6180 | switch (phba->link_state) { |
| 6181 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6182 | /* CLEAR LA timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6183 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6184 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6185 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6186 | clrlaerr = 1; |
| 6187 | break; |
| 6188 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6189 | case LPFC_LINK_UP: |
| 6190 | lpfc_issue_clear_la(phba, vport); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6191 | fallthrough; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6192 | case LPFC_LINK_UNKNOWN: |
| 6193 | case LPFC_WARM_START: |
| 6194 | case LPFC_INIT_START: |
| 6195 | case LPFC_INIT_MBX_CMDS: |
| 6196 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6197 | case LPFC_HBA_ERROR: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6198 | lpfc_printf_vlog(vport, KERN_ERR, |
| 6199 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6200 | "0230 Unexpected timeout, hba link " |
| 6201 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6202 | clrlaerr = 1; |
| 6203 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6204 | |
| 6205 | case LPFC_HBA_READY: |
| 6206 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6207 | } |
| 6208 | |
| 6209 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6210 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6211 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 6212 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 6213 | ~LPFC_STOP_IOCB_EVENT; |
| 6214 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 6215 | ~LPFC_STOP_IOCB_EVENT; |
| 6216 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6217 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6218 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | return; |
| 6220 | } |
| 6221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6222 | /* |
| 6223 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 6224 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 6225 | * as the completion routine when the command is |
| 6226 | * handed off to the SLI layer. |
| 6227 | */ |
| 6228 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6229 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6230 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6231 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6232 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 6233 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6234 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6235 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6236 | pmb->ctx_buf = NULL; |
| 6237 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6238 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6239 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6240 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 6241 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6242 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6243 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6244 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6245 | "0004 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6246 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6247 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6248 | ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6249 | /* |
| 6250 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6251 | * 0xfffffa (FDMI well known port). |
| 6252 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 6253 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6254 | */ |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6255 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 6256 | phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6257 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6258 | } else { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6259 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6260 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6261 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6262 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6263 | /* decrement the node reference count held for this callback |
| 6264 | * function. |
| 6265 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6266 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6267 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6268 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6269 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6270 | |
| 6271 | return; |
| 6272 | } |
| 6273 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6274 | static int |
| 6275 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 6276 | { |
| 6277 | uint16_t *rpi = param; |
| 6278 | |
| 6279 | return ndlp->nlp_rpi == *rpi; |
| 6280 | } |
| 6281 | |
| 6282 | static int |
| 6283 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 6284 | { |
| 6285 | return memcmp(&ndlp->nlp_portname, param, |
| 6286 | sizeof(ndlp->nlp_portname)) == 0; |
| 6287 | } |
| 6288 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6289 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6290 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6291 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6292 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6293 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6294 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6295 | if (filter(ndlp, param)) { |
| 6296 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6297 | "3185 FIND node filter %ps DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6298 | "ndlp x%px did x%x flg x%x st x%x " |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6299 | "xri x%x type x%x rpi x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6300 | filter, ndlp, ndlp->nlp_DID, |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6301 | ndlp->nlp_flag, ndlp->nlp_state, |
| 6302 | ndlp->nlp_xri, ndlp->nlp_type, |
| 6303 | ndlp->nlp_rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6304 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6305 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6306 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6307 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6308 | "3186 FIND node filter %ps NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6309 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6310 | } |
| 6311 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6312 | /* |
| 6313 | * This routine looks up the ndlp lists for the given RPI. If rpi found it |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6314 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6315 | */ |
| 6316 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6317 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6318 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6319 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6320 | } |
| 6321 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6322 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6323 | * This routine looks up the ndlp lists for the given WWPN. If WWPN found it |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6324 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6325 | */ |
| 6326 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6327 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6328 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6329 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6330 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6332 | spin_lock_irq(shost->host_lock); |
| 6333 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 6334 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6335 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6336 | } |
| 6337 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6338 | /* |
| 6339 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 6340 | * is found, the routine returns the node element list pointer else |
| 6341 | * return NULL. |
| 6342 | */ |
| 6343 | struct lpfc_nodelist * |
| 6344 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 6345 | { |
| 6346 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6347 | struct lpfc_nodelist *ndlp; |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6348 | unsigned long flags; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6349 | |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6350 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6351 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6352 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6353 | return ndlp; |
| 6354 | } |
| 6355 | |
| 6356 | /** |
| 6357 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 6358 | * @phba: pointer to lpfc hba data structure. |
| 6359 | * @vpi: the physical host virtual N_Port identifier. |
| 6360 | * |
| 6361 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6362 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6363 | * of the vport with the matching @vpi. |
| 6364 | * |
| 6365 | * Return code |
| 6366 | * NULL - No vport with the matching @vpi found |
| 6367 | * Otherwise - Address to the vport with the matching @vpi. |
| 6368 | **/ |
| 6369 | struct lpfc_vport * |
| 6370 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6371 | { |
| 6372 | struct lpfc_vport *vport; |
| 6373 | unsigned long flags; |
| 6374 | int i = 0; |
| 6375 | |
| 6376 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 6377 | if (vpi > 0) { |
| 6378 | /* |
| 6379 | * Translate the physical vpi to the logical vpi. The |
| 6380 | * vport stores the logical vpi. |
| 6381 | */ |
James Smart | 58c36e8 | 2021-03-01 09:18:01 -0800 | [diff] [blame] | 6382 | for (i = 0; i <= phba->max_vpi; i++) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6383 | if (vpi == phba->vpi_ids[i]) |
| 6384 | break; |
| 6385 | } |
| 6386 | |
James Smart | 58c36e8 | 2021-03-01 09:18:01 -0800 | [diff] [blame] | 6387 | if (i > phba->max_vpi) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6388 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6389 | "2936 Could not find Vport mapped " |
| 6390 | "to vpi %d\n", vpi); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6391 | return NULL; |
| 6392 | } |
| 6393 | } |
| 6394 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6395 | spin_lock_irqsave(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6396 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 6397 | if (vport->vpi == i) { |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6398 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6399 | return vport; |
| 6400 | } |
| 6401 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6402 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6403 | return NULL; |
| 6404 | } |
| 6405 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6406 | struct lpfc_nodelist * |
| 6407 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6408 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6409 | struct lpfc_nodelist *ndlp; |
| 6410 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 6411 | |
| 6412 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 6413 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 6414 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 6415 | return NULL; |
| 6416 | } |
| 6417 | |
| 6418 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 6419 | if (!ndlp) { |
| 6420 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6421 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 6422 | return NULL; |
| 6423 | } |
| 6424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6425 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6426 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6427 | spin_lock_init(&ndlp->lock); |
| 6428 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6429 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6430 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6431 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6432 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6433 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
| 6434 | "0007 Init New ndlp x%px, rpi:x%x DID:%x " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6435 | "flg:x%x refcnt:%d\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6436 | ndlp, ndlp->nlp_rpi, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6437 | ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6438 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6439 | ndlp->active_rrqs_xri_bitmap = |
| 6440 | mempool_alloc(vport->phba->active_rrq_pool, |
| 6441 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 6442 | if (ndlp->active_rrqs_xri_bitmap) |
| 6443 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 6444 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6445 | } |
| 6446 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 6447 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6448 | |
| 6449 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 6450 | "node init: did:x%x", |
| 6451 | ndlp->nlp_DID, 0, 0); |
| 6452 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6453 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6454 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6455 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6456 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 6457 | * and mempool_free's the nodelist. |
| 6458 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 6459 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6460 | lpfc_nlp_release(struct kref *kref) |
| 6461 | { |
| 6462 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 6463 | kref); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6464 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6465 | |
| 6466 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6467 | "node release: did:x%x flg:x%x type:x%x", |
| 6468 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 6469 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6470 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 6471 | "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n", |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6472 | __func__, ndlp, ndlp->nlp_DID, |
| 6473 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6474 | |
| 6475 | /* remove ndlp from action. */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6476 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 6477 | lpfc_cleanup_node(vport, ndlp); |
| 6478 | |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 6479 | /* Not all ELS transactions have registered the RPI with the port. |
| 6480 | * In these cases the rpi usage is temporary and the node is |
| 6481 | * released when the WQE is completed. Catch this case to free the |
| 6482 | * RPI to the pool. Because this node is in the release path, a lock |
| 6483 | * is unnecessary. All references are gone and the node has been |
| 6484 | * dequeued. |
| 6485 | */ |
| 6486 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 6487 | if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR && |
| 6488 | !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) { |
| 6489 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 6490 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | /* The node is not freed back to memory, it is released to a pool so |
| 6495 | * the node fields need to be cleaned up. |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6496 | */ |
| 6497 | ndlp->vport = NULL; |
| 6498 | ndlp->nlp_state = NLP_STE_FREED_NODE; |
| 6499 | ndlp->nlp_flag = 0; |
| 6500 | ndlp->fc4_xpt_flags = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6501 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6502 | /* free ndlp memory for final ndlp release */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6503 | kfree(ndlp->lat_data); |
| 6504 | if (ndlp->phba->sli_rev == LPFC_SLI_REV4) |
| 6505 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6506 | ndlp->phba->active_rrq_pool); |
| 6507 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6508 | } |
| 6509 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6510 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6511 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6512 | * is using it. |
| 6513 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6514 | struct lpfc_nodelist * |
| 6515 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6516 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6517 | unsigned long flags; |
| 6518 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6519 | if (ndlp) { |
| 6520 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6521 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6522 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6523 | kref_read(&ndlp->kref)); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6524 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6525 | /* The check of ndlp usage to prevent incrementing the |
| 6526 | * ndlp reference count that is in the process of being |
| 6527 | * released. |
| 6528 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6529 | spin_lock_irqsave(&ndlp->lock, flags); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6530 | if (!kref_get_unless_zero(&ndlp->kref)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6531 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6532 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6533 | "0276 %s: ndlp:x%px refcnt:%d\n", |
| 6534 | __func__, (void *)ndlp, kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6535 | return NULL; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6536 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6537 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6538 | } else { |
| 6539 | WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6540 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6541 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6542 | return ndlp; |
| 6543 | } |
| 6544 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6545 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6546 | * count goes to 0, this indicates the associated nodelist should be freed. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6547 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6548 | int |
| 6549 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6550 | { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6551 | if (ndlp) { |
| 6552 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6553 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6554 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6555 | kref_read(&ndlp->kref)); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6556 | } else { |
| 6557 | WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6558 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6559 | |
| 6560 | return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6561 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6562 | |
| 6563 | /* This routine free's the specified nodelist if it is not in use |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6564 | * by any other discovery thread. This routine returns 1 if the |
| 6565 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6566 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6567 | */ |
| 6568 | int |
| 6569 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6570 | { |
| 6571 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6572 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6573 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6574 | kref_read(&ndlp->kref)); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 6575 | |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6576 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6577 | if (lpfc_nlp_put(ndlp)) |
| 6578 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6579 | return 0; |
| 6580 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6581 | |
| 6582 | /** |
| 6583 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6584 | * @phba: Pointer to hba context object. |
| 6585 | * |
| 6586 | * This function iterate through all FC nodes associated |
| 6587 | * will all vports to check if there is any node with |
| 6588 | * fc_rports associated with it. If there is an fc_rport |
| 6589 | * associated with the node, then the node is either in |
| 6590 | * discovered state or its devloss_timer is pending. |
| 6591 | */ |
| 6592 | static int |
| 6593 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6594 | { |
| 6595 | struct lpfc_vport **vports; |
| 6596 | int i, ret = 0; |
| 6597 | struct lpfc_nodelist *ndlp; |
| 6598 | struct Scsi_Host *shost; |
| 6599 | |
| 6600 | vports = lpfc_create_vport_work_array(phba); |
| 6601 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6602 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6603 | if (!vports) |
| 6604 | return 1; |
| 6605 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6606 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6607 | shost = lpfc_shost_from_vport(vports[i]); |
| 6608 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6609 | /* |
| 6610 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6611 | * flogi. |
| 6612 | * If dev_loss fires while we are waiting we do not want to |
| 6613 | * unreg the fcf. |
| 6614 | */ |
| 6615 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6616 | spin_unlock_irq(shost->host_lock); |
| 6617 | ret = 1; |
| 6618 | goto out; |
| 6619 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6620 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6621 | if (ndlp->rport && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6622 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6623 | ret = 1; |
| 6624 | spin_unlock_irq(shost->host_lock); |
| 6625 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6626 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6627 | ret = 1; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6628 | lpfc_printf_log(phba, KERN_INFO, |
| 6629 | LOG_NODE | LOG_DISCOVERY, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6630 | "2624 RPI %x DID %x flag %x " |
| 6631 | "still logged in\n", |
| 6632 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6633 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6634 | } |
| 6635 | } |
| 6636 | spin_unlock_irq(shost->host_lock); |
| 6637 | } |
| 6638 | out: |
| 6639 | lpfc_destroy_vport_work_array(phba, vports); |
| 6640 | return ret; |
| 6641 | } |
| 6642 | |
| 6643 | /** |
| 6644 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6645 | * @phba: Pointer to hba context object. |
| 6646 | * @mboxq: Pointer to mailbox object. |
| 6647 | * |
| 6648 | * This function frees memory associated with the mailbox command. |
| 6649 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6650 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6651 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6652 | { |
| 6653 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6654 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6655 | |
| 6656 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6657 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6658 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6659 | "HBA state x%x\n", |
| 6660 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6661 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6662 | spin_lock_irq(shost->host_lock); |
| 6663 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6664 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6665 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6666 | return; |
| 6667 | } |
| 6668 | |
| 6669 | /** |
| 6670 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6671 | * @phba: Pointer to hba context object. |
| 6672 | * @mboxq: Pointer to mailbox object. |
| 6673 | * |
| 6674 | * This function frees memory associated with the mailbox command. |
| 6675 | */ |
| 6676 | static void |
| 6677 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6678 | { |
| 6679 | struct lpfc_vport *vport = mboxq->vport; |
| 6680 | |
| 6681 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6682 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6683 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6684 | "HBA state x%x\n", |
| 6685 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6686 | } |
| 6687 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6688 | return; |
| 6689 | } |
| 6690 | |
| 6691 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6692 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6693 | * @phba: Pointer to hba context object. |
| 6694 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6695 | * This function prepare the HBA for unregistering the currently registered |
| 6696 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6697 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6698 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6699 | int |
| 6700 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6701 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6702 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6703 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6704 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6705 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6706 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6707 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6708 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6709 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6710 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6711 | /* At this point, all discovery is aborted */ |
| 6712 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6713 | |
| 6714 | /* Unregister VPIs */ |
| 6715 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6716 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6717 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6718 | /* Stop FLOGI/FDISC retries */ |
| 6719 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6720 | if (ndlp) |
| 6721 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6722 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6723 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6724 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6725 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6726 | shost = lpfc_shost_from_vport(vports[i]); |
| 6727 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6728 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6729 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6730 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6731 | } |
| 6732 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6733 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6734 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6735 | if (ndlp) |
| 6736 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6737 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6738 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6739 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6740 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6741 | shost = lpfc_shost_from_vport(phba->pport); |
| 6742 | spin_lock_irq(shost->host_lock); |
| 6743 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6744 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6745 | spin_unlock_irq(shost->host_lock); |
| 6746 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6747 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6748 | /* Cleanup any outstanding ELS commands */ |
| 6749 | lpfc_els_flush_all_cmd(phba); |
| 6750 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6751 | /* Unregister the physical port VFI */ |
| 6752 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6753 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | /** |
| 6757 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6758 | * @phba: Pointer to hba context object. |
| 6759 | * |
| 6760 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6761 | * unregister the currently registered FCF record. The driver does not reset |
| 6762 | * the driver FCF usage state flags. |
| 6763 | * |
| 6764 | * Return 0 if successfully issued, none-zero otherwise. |
| 6765 | */ |
| 6766 | int |
| 6767 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6768 | { |
| 6769 | LPFC_MBOXQ_t *mbox; |
| 6770 | int rc; |
| 6771 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6772 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6773 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6774 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6775 | "2551 UNREG_FCFI mbox allocation failed" |
| 6776 | "HBA state x%x\n", phba->pport->port_state); |
| 6777 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6778 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6779 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6780 | mbox->vport = phba->pport; |
| 6781 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6782 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6783 | |
| 6784 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6785 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6786 | "2552 Unregister FCFI command failed rc x%x " |
| 6787 | "HBA state x%x\n", |
| 6788 | rc, phba->pport->port_state); |
| 6789 | return -EINVAL; |
| 6790 | } |
| 6791 | return 0; |
| 6792 | } |
| 6793 | |
| 6794 | /** |
| 6795 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6796 | * @phba: Pointer to hba context object. |
| 6797 | * |
| 6798 | * This function unregisters the currently reigstered FCF. This function |
| 6799 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6800 | */ |
| 6801 | void |
| 6802 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6803 | { |
| 6804 | int rc; |
| 6805 | |
| 6806 | /* Preparation for unregistering fcf */ |
| 6807 | rc = lpfc_unregister_fcf_prep(phba); |
| 6808 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6809 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6810 | "2748 Failed to prepare for unregistering " |
| 6811 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6812 | return; |
| 6813 | } |
| 6814 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6815 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6816 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6817 | if (rc) |
| 6818 | return; |
| 6819 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6820 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6821 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6822 | |
| 6823 | /* |
| 6824 | * If driver is not unloading, check if there is any other |
| 6825 | * FCF record that can be used for discovery. |
| 6826 | */ |
| 6827 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6828 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6829 | return; |
| 6830 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6831 | /* This is considered as the initial FCF discovery scan */ |
| 6832 | spin_lock_irq(&phba->hbalock); |
| 6833 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6834 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6835 | |
| 6836 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6837 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6838 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6839 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6840 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6841 | if (rc) { |
| 6842 | spin_lock_irq(&phba->hbalock); |
| 6843 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6844 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6845 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6846 | "2553 lpfc_unregister_unused_fcf failed " |
| 6847 | "to read FCF record HBA state x%x\n", |
| 6848 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6849 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | /** |
| 6853 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6854 | * @phba: Pointer to hba context object. |
| 6855 | * |
| 6856 | * This function just unregisters the currently reigstered FCF. It does not |
| 6857 | * try to find another FCF for discovery. |
| 6858 | */ |
| 6859 | void |
| 6860 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6861 | { |
| 6862 | int rc; |
| 6863 | |
| 6864 | /* Preparation for unregistering fcf */ |
| 6865 | rc = lpfc_unregister_fcf_prep(phba); |
| 6866 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6867 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6868 | "2749 Failed to prepare for unregistering " |
| 6869 | "HBA's FCF record: rc=%d\n", rc); |
| 6870 | return; |
| 6871 | } |
| 6872 | |
| 6873 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6874 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6875 | if (rc) |
| 6876 | return; |
| 6877 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6878 | spin_lock_irq(&phba->hbalock); |
| 6879 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6880 | spin_unlock_irq(&phba->hbalock); |
| 6881 | } |
| 6882 | |
| 6883 | /** |
| 6884 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6885 | * @phba: Pointer to hba context object. |
| 6886 | * |
| 6887 | * This function check if there are any connected remote port for the FCF and |
| 6888 | * if all the devices are disconnected, this function unregister FCFI. |
| 6889 | * This function also tries to use another FCF for discovery. |
| 6890 | */ |
| 6891 | void |
| 6892 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6893 | { |
| 6894 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6895 | * If HBA is not running in FIP mode, if HBA does not support |
| 6896 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6897 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6898 | */ |
| 6899 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6900 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6901 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6902 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6903 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6904 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6905 | spin_unlock_irq(&phba->hbalock); |
| 6906 | return; |
| 6907 | } |
| 6908 | spin_unlock_irq(&phba->hbalock); |
| 6909 | |
| 6910 | if (lpfc_fcf_inuse(phba)) |
| 6911 | return; |
| 6912 | |
| 6913 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6918 | * @phba: Pointer to hba context object. |
| 6919 | * @buff: Buffer containing the FCF connection table as in the config |
| 6920 | * region. |
| 6921 | * This function create driver data structure for the FCF connection |
| 6922 | * record table read from config region 23. |
| 6923 | */ |
| 6924 | static void |
| 6925 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6926 | uint8_t *buff) |
| 6927 | { |
| 6928 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6929 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6930 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6931 | uint32_t record_count; |
| 6932 | int i; |
| 6933 | |
| 6934 | /* Free the current connect table */ |
| 6935 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6936 | &phba->fcf_conn_rec_list, list) { |
| 6937 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6938 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6939 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6940 | |
| 6941 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6942 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6943 | sizeof(struct lpfc_fcf_conn_rec); |
| 6944 | |
| 6945 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6946 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6947 | |
| 6948 | for (i = 0; i < record_count; i++) { |
| 6949 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6950 | continue; |
| 6951 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6952 | GFP_KERNEL); |
| 6953 | if (!conn_entry) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6954 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6955 | "2566 Failed to allocate connection" |
| 6956 | " table entry\n"); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6957 | return; |
| 6958 | } |
| 6959 | |
| 6960 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6961 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6962 | list_add_tail(&conn_entry->list, |
| 6963 | &phba->fcf_conn_rec_list); |
| 6964 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6965 | |
| 6966 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6967 | i = 0; |
| 6968 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6969 | list) { |
| 6970 | conn_rec = &conn_entry->conn_rec; |
| 6971 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6972 | "3345 FCF connection list rec[%02d]: " |
| 6973 | "flags:x%04x, vtag:x%04x, " |
| 6974 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6975 | "%02x:%02x:%02x:%02x, " |
| 6976 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6977 | "%02x:%02x:%02x:%02x\n", i++, |
| 6978 | conn_rec->flags, conn_rec->vlan_tag, |
| 6979 | conn_rec->fabric_name[0], |
| 6980 | conn_rec->fabric_name[1], |
| 6981 | conn_rec->fabric_name[2], |
| 6982 | conn_rec->fabric_name[3], |
| 6983 | conn_rec->fabric_name[4], |
| 6984 | conn_rec->fabric_name[5], |
| 6985 | conn_rec->fabric_name[6], |
| 6986 | conn_rec->fabric_name[7], |
| 6987 | conn_rec->switch_name[0], |
| 6988 | conn_rec->switch_name[1], |
| 6989 | conn_rec->switch_name[2], |
| 6990 | conn_rec->switch_name[3], |
| 6991 | conn_rec->switch_name[4], |
| 6992 | conn_rec->switch_name[5], |
| 6993 | conn_rec->switch_name[6], |
| 6994 | conn_rec->switch_name[7]); |
| 6995 | } |
| 6996 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6997 | } |
| 6998 | |
| 6999 | /** |
| 7000 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 7001 | * @phba: Pointer to hba context object. |
| 7002 | * @buff: Buffer containing the FCoE parameter data structure. |
| 7003 | * |
| 7004 | * This function update driver data structure with config |
| 7005 | * parameters read from config region 23. |
| 7006 | */ |
| 7007 | static void |
| 7008 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 7009 | uint8_t *buff) |
| 7010 | { |
| 7011 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 7012 | struct lpfc_fcoe_params *fcoe_param; |
| 7013 | |
| 7014 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 7015 | buff; |
| 7016 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 7017 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7018 | |
| 7019 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 7020 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 7021 | return; |
| 7022 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7023 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 7024 | phba->valid_vlan = 1; |
| 7025 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 7026 | 0xFFF; |
| 7027 | } |
| 7028 | |
| 7029 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 7030 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 7031 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 7032 | return; |
| 7033 | } |
| 7034 | |
| 7035 | /** |
| 7036 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 7037 | * @buff: Buffer containing config region 23 data. |
| 7038 | * @size: Size of the data buffer. |
| 7039 | * @rec_type: Record type to be searched. |
| 7040 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7041 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7042 | * of the record specified by record_type. If record found, this |
| 7043 | * function return pointer to the record else return NULL. |
| 7044 | */ |
| 7045 | static uint8_t * |
| 7046 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 7047 | { |
| 7048 | uint32_t offset = 0, rec_length; |
| 7049 | |
| 7050 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 7051 | (size < sizeof(uint32_t))) |
| 7052 | return NULL; |
| 7053 | |
| 7054 | rec_length = buff[offset + 1]; |
| 7055 | |
| 7056 | /* |
| 7057 | * One TLV record has one word header and number of data words |
| 7058 | * specified in the rec_length field of the record header. |
| 7059 | */ |
| 7060 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 7061 | <= size) { |
| 7062 | if (buff[offset] == rec_type) |
| 7063 | return &buff[offset]; |
| 7064 | |
| 7065 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 7066 | return NULL; |
| 7067 | |
| 7068 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 7069 | rec_length = buff[offset + 1]; |
| 7070 | } |
| 7071 | return NULL; |
| 7072 | } |
| 7073 | |
| 7074 | /** |
| 7075 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 7076 | * @phba: Pointer to lpfc_hba data structure. |
| 7077 | * @buff: Buffer containing config region 23 data. |
| 7078 | * @size: Size of the data buffer. |
| 7079 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 7080 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7081 | * populate driver data structure with the parameters. |
| 7082 | */ |
| 7083 | void |
| 7084 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 7085 | uint8_t *buff, |
| 7086 | uint32_t size) |
| 7087 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7088 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7089 | uint8_t *rec_ptr; |
| 7090 | |
| 7091 | /* |
| 7092 | * If data size is less than 2 words signature and version cannot be |
| 7093 | * verified. |
| 7094 | */ |
| 7095 | if (size < 2*sizeof(uint32_t)) |
| 7096 | return; |
| 7097 | |
| 7098 | /* Check the region signature first */ |
| 7099 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7100 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7101 | "2567 Config region 23 has bad signature\n"); |
| 7102 | return; |
| 7103 | } |
| 7104 | |
| 7105 | offset += 4; |
| 7106 | |
| 7107 | /* Check the data structure version */ |
| 7108 | if (buff[offset] != LPFC_REGION23_VERSION) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7109 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 7110 | "2568 Config region 23 has bad version\n"); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7111 | return; |
| 7112 | } |
| 7113 | offset += 4; |
| 7114 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7115 | /* Read FCoE param record */ |
| 7116 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 7117 | size - offset, FCOE_PARAM_TYPE); |
| 7118 | if (rec_ptr) |
| 7119 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 7120 | |
| 7121 | /* Read FCF connection table */ |
| 7122 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 7123 | size - offset, FCOE_CONN_TBL_TYPE); |
| 7124 | if (rec_ptr) |
| 7125 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 7126 | |
| 7127 | } |