| 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 *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 76 | static int |
| 77 | lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp) |
| 78 | { |
| 79 | if (ndlp->nlp_fc4_type || |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame^] | 80 | ndlp->nlp_type & NLP_FABRIC) |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 81 | return 1; |
| 82 | return 0; |
| 83 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 84 | /* The source of a terminate rport I/O is either a dev_loss_tmo |
| 85 | * event or a call to fc_remove_host. While the rport should be |
| 86 | * valid during these downcalls, the transport can call twice |
| 87 | * in a single event. This routine provides somoe protection |
| 88 | * as the NDLP isn't really free, just released to the pool. |
| 89 | */ |
| 90 | static int |
| 91 | lpfc_rport_invalid(struct fc_rport *rport) |
| 92 | { |
| 93 | struct lpfc_rport_data *rdata; |
| 94 | struct lpfc_nodelist *ndlp; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 95 | |
| 96 | if (!rport) { |
| 97 | pr_err("**** %s: NULL rport, exit.\n", __func__); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
| 101 | rdata = rport->dd_data; |
| 102 | if (!rdata) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 103 | 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] | 104 | __func__, rport, rport->scsi_target_id); |
| 105 | return -EINVAL; |
| 106 | } |
| 107 | |
| 108 | ndlp = rdata->pnode; |
| 109 | if (!rdata->pnode) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 110 | 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] | 111 | __func__, rport, rport->scsi_target_id); |
| 112 | return -EINVAL; |
| 113 | } |
| 114 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 115 | if (!ndlp->vport) { |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 116 | 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] | 117 | "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport, |
| 118 | rport->scsi_target_id); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 124 | void |
| 125 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 126 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 127 | struct lpfc_rport_data *rdata; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 128 | struct lpfc_nodelist *ndlp; |
| 129 | struct lpfc_vport *vport; |
| 130 | |
| 131 | if (lpfc_rport_invalid(rport)) |
| 132 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 133 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 134 | rdata = rport->dd_data; |
| 135 | ndlp = rdata->pnode; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 136 | vport = ndlp->vport; |
| 137 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 138 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 139 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 140 | |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 141 | if (ndlp->nlp_sid != NLP_NO_SID) |
| 142 | lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
| 146 | * This function will be called when dev_loss_tmo fire. |
| 147 | */ |
| 148 | void |
| 149 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 150 | { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 151 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 152 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 153 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 154 | struct lpfc_work_evt *evtp; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 155 | unsigned long iflags; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 156 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 157 | ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 158 | if (!ndlp) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 159 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 160 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 161 | vport = ndlp->vport; |
| 162 | phba = vport->phba; |
| 163 | |
| 164 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 165 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 166 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 167 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 168 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 169 | "3181 dev_loss_callbk x%06x, rport x%px flg x%x " |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 170 | "load_flag x%x refcnt %d\n", |
| 171 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag, |
| 172 | vport->load_flag, kref_read(&ndlp->kref)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 173 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 174 | /* Don't schedule a worker thread event if the vport is going down. |
| 175 | * The teardown process cleans up the node via lpfc_drop_node. |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 176 | */ |
| 177 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 178 | ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 179 | ndlp->rport = NULL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 180 | |
| 181 | ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; |
| 182 | |
| 183 | /* Remove the node reference from remote_port_add now. |
| 184 | * The driver will not call remote_port_delete. |
| 185 | */ |
| 186 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
| 190 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 191 | return; |
| 192 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 193 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 194 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 195 | "6789 rport name %llx != node port name %llx", |
| 196 | rport->port_name, |
| 197 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 198 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 199 | evtp = &ndlp->dev_loss_evt; |
| 200 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 201 | if (!list_empty(&evtp->evt_listp)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 202 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 203 | "6790 rport name %llx dev_loss_evt pending\n", |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 204 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 205 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 206 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 207 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 208 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 209 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 210 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 211 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 212 | /* |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 213 | * The backend does not expect any more calls associated with this |
| 214 | * rport. Remove the association between rport and ndlp. |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 215 | */ |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 216 | ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 217 | ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL; |
| 218 | ndlp->rport = NULL; |
| 219 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 220 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 221 | /* We need to hold the node by incrementing the reference |
| 222 | * count until this queued work is done |
| 223 | */ |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 224 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 225 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 226 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 227 | if (evtp->evt_arg1) { |
| 228 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 229 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 230 | lpfc_worker_wake_up(phba); |
| 231 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 232 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 233 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 234 | return; |
| 235 | } |
| 236 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 237 | /** |
| 238 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 239 | * @ndlp: Pointer to remote node object. |
| 240 | * |
| 241 | * This function is called from the worker thread when devloss timeout timer |
| 242 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 243 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 244 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 245 | * when devloss timeout happened to this @ndlp. |
| 246 | **/ |
| 247 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 248 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 249 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 250 | struct lpfc_vport *vport; |
| 251 | struct lpfc_hba *phba; |
| 252 | uint8_t *name; |
| 253 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 254 | int fcf_inuse = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 255 | unsigned long iflags; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 256 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 257 | vport = ndlp->vport; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 258 | name = (uint8_t *)&ndlp->nlp_portname; |
| 259 | phba = vport->phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 260 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 261 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 262 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 263 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 264 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 265 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 266 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 267 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 268 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 269 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 270 | ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 271 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 272 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 273 | "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] | 274 | __func__, ndlp->nlp_DID, ndlp->nlp_flag, |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 275 | ndlp->fc4_xpt_flags, kref_read(&ndlp->kref)); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 276 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 277 | /* If the driver is recovering the rport, ignore devloss. */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 278 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 279 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 280 | "0284 Devloss timeout Ignored on " |
| 281 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 282 | "NPort x%x\n", |
| 283 | *name, *(name+1), *(name+2), *(name+3), |
| 284 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 285 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 286 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 287 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 288 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 289 | /* Fabric nodes are done. */ |
| 290 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 291 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 292 | return fcf_inuse; |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 293 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 295 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 296 | warn_on = 1; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 297 | lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 298 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 299 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 300 | if (warn_on) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 301 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 302 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 303 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 304 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 305 | *name, *(name+1), *(name+2), *(name+3), |
| 306 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 307 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 308 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 309 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 310 | lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 311 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 312 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 313 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 314 | *name, *(name+1), *(name+2), *(name+3), |
| 315 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 316 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 317 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 318 | } |
| 319 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 320 | if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 321 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 322 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 323 | return fcf_inuse; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 328 | * @phba: Pointer to hba context object. |
| 329 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 330 | * @nlp_did: remote node identifer with devloss timeout. |
| 331 | * |
| 332 | * This function is called from the worker thread after invoking devloss |
| 333 | * timeout handler and releasing the reference count for the ndlp with |
| 334 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 335 | * timeout of the last remote node which had been in use of FCF, when this |
| 336 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 337 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 338 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 339 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 340 | * engine is in FCF discovery process, the devloss timeout state shall |
| 341 | * be set for either the FCF table scan process or roundrobin failover |
| 342 | * process to unregister the in-use FCF. |
| 343 | **/ |
| 344 | static void |
| 345 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 346 | uint32_t nlp_did) |
| 347 | { |
| 348 | /* If devloss timeout happened to a remote node when FCF had no |
| 349 | * longer been in-use, do nothing. |
| 350 | */ |
| 351 | if (!fcf_inuse) |
| 352 | return; |
| 353 | |
| 354 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 355 | spin_lock_irq(&phba->hbalock); |
| 356 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 357 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 358 | spin_unlock_irq(&phba->hbalock); |
| 359 | return; |
| 360 | } |
| 361 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 362 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 363 | "2847 Last remote node (x%x) using " |
| 364 | "FCF devloss tmo\n", nlp_did); |
| 365 | } |
| 366 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 367 | spin_unlock_irq(&phba->hbalock); |
| 368 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 369 | "2868 Devloss tmo to FCF rediscovery " |
| 370 | "in progress\n"); |
| 371 | return; |
| 372 | } |
| 373 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 374 | spin_unlock_irq(&phba->hbalock); |
| 375 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 376 | "2869 Devloss tmo to idle FIP engine, " |
| 377 | "unreg in-use FCF and rescan.\n"); |
| 378 | /* Unregister in-use FCF and rescan */ |
| 379 | lpfc_unregister_fcf_rescan(phba); |
| 380 | return; |
| 381 | } |
| 382 | spin_unlock_irq(&phba->hbalock); |
| 383 | if (phba->hba_flag & FCF_TS_INPROG) |
| 384 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 385 | "2870 FCF table scan in progress\n"); |
| 386 | if (phba->hba_flag & FCF_RR_INPROG) |
| 387 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 388 | "2871 FLOGI roundrobin FCF failover " |
| 389 | "in progress\n"); |
| 390 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 391 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 392 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 393 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 395 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 396 | * @phba: Pointer to hba context object. |
| 397 | * |
| 398 | * This function is called from the functions which need to post |
| 399 | * events from interrupt context. This function allocates data |
| 400 | * structure required for posting event. It also keeps track of |
| 401 | * number of events pending and prevent event storm when there are |
| 402 | * too many events. |
| 403 | **/ |
| 404 | struct lpfc_fast_path_event * |
| 405 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 406 | struct lpfc_fast_path_event *ret; |
| 407 | |
| 408 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 409 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 410 | return NULL; |
| 411 | |
| 412 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 413 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 414 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 415 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 416 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 417 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 418 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 423 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 424 | * @phba: Pointer to hba context object. |
| 425 | * @evt: Event object which need to be freed. |
| 426 | * |
| 427 | * This function frees the data structure required for posting |
| 428 | * events. |
| 429 | **/ |
| 430 | void |
| 431 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 432 | struct lpfc_fast_path_event *evt) { |
| 433 | |
| 434 | atomic_dec(&phba->fast_event_count); |
| 435 | kfree(evt); |
| 436 | } |
| 437 | |
| 438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 439 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 440 | * @phba: Pointer to hba context object. |
| 441 | * @evtp: Event data structure. |
| 442 | * |
| 443 | * This function is called from worker thread, when the interrupt |
| 444 | * context need to post an event. This function posts the event |
| 445 | * to fc transport netlink interface. |
| 446 | **/ |
| 447 | static void |
| 448 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 449 | struct lpfc_work_evt *evtp) |
| 450 | { |
| 451 | unsigned long evt_category, evt_sub_category; |
| 452 | struct lpfc_fast_path_event *fast_evt_data; |
| 453 | char *evt_data; |
| 454 | uint32_t evt_data_size; |
| 455 | struct Scsi_Host *shost; |
| 456 | |
| 457 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 458 | work_evt); |
| 459 | |
| 460 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 461 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 462 | fabric_evt.subcategory; |
| 463 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 464 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 465 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 466 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 467 | evt_data_size = sizeof(fast_evt_data->un. |
| 468 | read_check_error); |
| 469 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 470 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 471 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 472 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 473 | } else { |
| 474 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 475 | return; |
| 476 | } |
| 477 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 478 | switch (evt_sub_category) { |
| 479 | case LPFC_EVENT_QFULL: |
| 480 | case LPFC_EVENT_DEVBSY: |
| 481 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 482 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 483 | break; |
| 484 | case LPFC_EVENT_CHECK_COND: |
| 485 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 486 | evt_data_size = sizeof(fast_evt_data->un. |
| 487 | check_cond_evt); |
| 488 | break; |
| 489 | case LPFC_EVENT_VARQUEDEPTH: |
| 490 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 491 | evt_data_size = sizeof(fast_evt_data->un. |
| 492 | queue_depth_evt); |
| 493 | break; |
| 494 | default: |
| 495 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 496 | return; |
| 497 | } |
| 498 | } else { |
| 499 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 500 | return; |
| 501 | } |
| 502 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 503 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 504 | fc_host_post_vendor_event(shost, |
| 505 | fc_get_event_number(), |
| 506 | evt_data_size, |
| 507 | evt_data, |
| 508 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 509 | |
| 510 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 511 | return; |
| 512 | } |
| 513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | { |
| 517 | struct lpfc_work_evt *evtp = NULL; |
| 518 | struct lpfc_nodelist *ndlp; |
| 519 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 520 | int fcf_inuse; |
| 521 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 522 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | spin_lock_irq(&phba->hbalock); |
| 524 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 526 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 529 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 531 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 533 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 534 | /* decrement the node reference count held |
| 535 | * for this queued work |
| 536 | */ |
| 537 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 539 | case LPFC_EVT_DEV_LOSS: |
| 540 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 541 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 542 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 543 | /* decrement the node reference count held for |
| 544 | * this queued work |
| 545 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 546 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 547 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 548 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 549 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 550 | fcf_inuse, |
| 551 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 552 | break; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 553 | case LPFC_EVT_RECOVER_PORT: |
| 554 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
| 555 | lpfc_sli_abts_recover_port(ndlp->vport, ndlp); |
| 556 | free_evt = 0; |
| 557 | /* decrement the node reference count held for |
| 558 | * this queued work |
| 559 | */ |
| 560 | lpfc_nlp_put(ndlp); |
| 561 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 562 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 563 | if (phba->link_state < LPFC_LINK_DOWN) |
| 564 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 565 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 566 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 567 | complete((struct completion *)(evtp->evt_arg2)); |
| 568 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 569 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 570 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 571 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 572 | *(int *)(evtp->evt_arg1) = 0; |
| 573 | complete((struct completion *)(evtp->evt_arg2)); |
| 574 | break; |
| 575 | case LPFC_EVT_OFFLINE: |
| 576 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 577 | lpfc_sli_brdrestart(phba); |
| 578 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 579 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 580 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 581 | complete((struct completion *)(evtp->evt_arg2)); |
| 582 | break; |
| 583 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 584 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 585 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 586 | lpfc_sli_brdreset(phba); |
| 587 | lpfc_hba_down_post(phba); |
| 588 | *(int *)(evtp->evt_arg1) = |
| 589 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 590 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 591 | complete((struct completion *)(evtp->evt_arg2)); |
| 592 | break; |
| 593 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 594 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 595 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 596 | = (phba->pport->stopped) |
| 597 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 598 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | complete((struct completion *)(evtp->evt_arg2)); |
| 600 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 601 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 602 | lpfc_send_fastpath_evt(phba, evtp); |
| 603 | free_evt = 0; |
| 604 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 605 | case LPFC_EVT_RESET_HBA: |
| 606 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 607 | lpfc_reset_hba(phba); |
| 608 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | } |
| 610 | if (free_evt) |
| 611 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 612 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 614 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | |
| 616 | } |
| 617 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 618 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 619 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | { |
| 621 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 622 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 623 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 624 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 625 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 627 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | ha_copy = phba->work_ha; |
| 629 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 630 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 632 | /* First, try to post the next mailbox command to SLI4 device */ |
| 633 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 634 | lpfc_sli4_post_async_mbox(phba); |
| 635 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 636 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 637 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 638 | lpfc_handle_eratt(phba); |
| 639 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 640 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | lpfc_sli_handle_mb_event(phba); |
| 642 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 643 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 645 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 646 | /* Process SLI4 events */ |
| 647 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 648 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 649 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 650 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 651 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 652 | if (phba->hba_flag & ASYNC_EVENT) |
| 653 | lpfc_sli4_async_event_proc(phba); |
| 654 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 655 | spin_lock_irq(&phba->hbalock); |
| 656 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 657 | spin_unlock_irq(&phba->hbalock); |
| 658 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 659 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 660 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 661 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 662 | } |
| 663 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 664 | vports = lpfc_create_vport_work_array(phba); |
| 665 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 666 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 667 | /* |
| 668 | * We could have no vports in array if unloading, so if |
| 669 | * this happens then just use the pport |
| 670 | */ |
| 671 | if (vports[i] == NULL && i == 0) |
| 672 | vport = phba->pport; |
| 673 | else |
| 674 | vport = vports[i]; |
| 675 | if (vport == NULL) |
| 676 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 677 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 678 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 679 | vport->work_port_events &= ~work_port_events; |
| 680 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 681 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 682 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 683 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 684 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 685 | if (work_port_events & WORKER_HB_TMO) |
| 686 | lpfc_hb_timeout_handler(phba); |
| 687 | if (work_port_events & WORKER_MBOX_TMO) |
| 688 | lpfc_mbox_timeout_handler(phba); |
| 689 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 690 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 691 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 692 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 693 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 694 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 695 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 696 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 698 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 699 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 700 | status >>= (4*LPFC_ELS_RING); |
James Smart | 0c9c6a7 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 701 | if (pring && (status & HA_RXMASK || |
| 702 | pring->flag & LPFC_DEFERRED_RING_EVENT || |
| 703 | phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 704 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 705 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 161df4f0 | 2018-01-30 15:58:54 -0800 | [diff] [blame] | 706 | /* Preserve legacy behavior. */ |
| 707 | if (!(phba->hba_flag & HBA_SP_QUEUE_EVT)) |
| 708 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 709 | } else { |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 710 | /* Driver could have abort request completed in queue |
| 711 | * when link goes down. Allow for this transition. |
| 712 | */ |
| 713 | if (phba->link_state >= LPFC_LINK_DOWN || |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 714 | phba->link_flag & LS_MDS_LOOPBACK) { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 715 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 716 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 717 | (status & |
| 718 | HA_RXMASK)); |
| 719 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 720 | } |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 721 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 722 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 723 | /* |
| 724 | * Turn on Ring interrupts |
| 725 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 726 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 727 | spin_lock_irq(&phba->hbalock); |
| 728 | control = readl(phba->HCregaddr); |
| 729 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 730 | lpfc_debugfs_slow_ring_trc(phba, |
| 731 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 732 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 733 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 734 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 735 | writel(control, phba->HCregaddr); |
| 736 | readl(phba->HCregaddr); /* flush */ |
| 737 | } else { |
| 738 | lpfc_debugfs_slow_ring_trc(phba, |
| 739 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 740 | control, ha_copy, 0); |
| 741 | } |
| 742 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | } |
| 744 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 745 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 746 | } |
| 747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | int |
| 749 | lpfc_do_work(void *p) |
| 750 | { |
| 751 | struct lpfc_hba *phba = p; |
| 752 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 754 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 755 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 756 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 757 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 758 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 759 | /* wait and check worker queue activities */ |
| 760 | rc = wait_event_interruptible(phba->work_waitq, |
| 761 | (test_and_clear_bit(LPFC_DATA_READY, |
| 762 | &phba->data_flags) |
| 763 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 764 | /* Signal wakeup shall terminate the worker thread */ |
| 765 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 766 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 767 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 769 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 771 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 774 | phba->worker_thread = NULL; |
| 775 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 776 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /* |
| 781 | * 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] | 782 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | * embedding it in the IOCB. |
| 784 | */ |
| 785 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 786 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | uint32_t evt) |
| 788 | { |
| 789 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 790 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | |
| 792 | /* |
| 793 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 794 | * be queued to worker thread for processing |
| 795 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | if (!evtp) |
| 798 | return 0; |
| 799 | |
| 800 | evtp->evt_arg1 = arg1; |
| 801 | evtp->evt_arg2 = arg2; |
| 802 | evtp->evt = evt; |
| 803 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 804 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 805 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 806 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 808 | lpfc_worker_wake_up(phba); |
| 809 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | return 1; |
| 811 | } |
| 812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | void |
| 814 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 815 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 816 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 817 | struct lpfc_hba *phba = vport->phba; |
| 818 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | |
| 820 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 821 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 822 | continue; |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 823 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 824 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 825 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 826 | ((ndlp->nlp_DID == NameServer_DID) || |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame^] | 827 | (ndlp->nlp_DID == FDMI_DID) || |
| 828 | (ndlp->nlp_DID == Fabric_Cntl_DID)))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 829 | lpfc_unreg_rpi(vport, ndlp); |
| 830 | |
| 831 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 832 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 833 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 834 | continue; |
James Smart | 4c2805a | 2020-03-31 09:50:10 -0700 | [diff] [blame] | 835 | |
| 836 | /* Notify transport of connectivity loss to trigger cleanup. */ |
| 837 | if (phba->nvmet_support && |
| 838 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
| 839 | lpfc_nvmet_invalidate_host(phba, ndlp); |
| 840 | |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 841 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 842 | remove |
| 843 | ? NLP_EVT_DEVICE_RM |
| 844 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | } |
| 846 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 847 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 848 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 849 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 850 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 851 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 852 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 856 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 857 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 858 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 859 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 860 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 861 | /* Cleanup any outstanding received buffers */ |
| 862 | lpfc_cleanup_rcv_buffers(vport); |
| 863 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 864 | /* Cleanup any outstanding RSCN activity */ |
| 865 | lpfc_els_flush_rscn(vport); |
| 866 | |
| 867 | /* Cleanup any outstanding ELS commands */ |
| 868 | lpfc_els_flush_cmd(vport); |
| 869 | |
| 870 | lpfc_cleanup_rpis(vport, 0); |
| 871 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | /* Turn off discovery timer if its running */ |
| 873 | lpfc_can_disctmo(vport); |
| 874 | } |
| 875 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 876 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 877 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 878 | { |
| 879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 880 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 881 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 882 | fc_host_post_event(shost, fc_get_event_number(), |
| 883 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 884 | |
| 885 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 886 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 887 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 888 | |
| 889 | lpfc_port_link_failure(vport); |
| 890 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 891 | /* Stop delayed Nport discovery */ |
| 892 | spin_lock_irq(shost->host_lock); |
| 893 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 894 | spin_unlock_irq(shost->host_lock); |
| 895 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 896 | } |
| 897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 899 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | struct lpfc_vport *vport = phba->pport; |
| 902 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 903 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 904 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 905 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 907 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 908 | return 0; |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 909 | |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 910 | /* Block all SCSI stack I/Os */ |
| 911 | lpfc_scsi_dev_block(phba); |
| 912 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 913 | phba->defer_flogi_acc_flag = false; |
| 914 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 916 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 917 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 918 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 919 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 920 | if (phba->sli4_hba.conf_trunk) { |
| 921 | phba->trunk_link.link0.state = 0; |
| 922 | phba->trunk_link.link1.state = 0; |
| 923 | phba->trunk_link.link2.state = 0; |
| 924 | phba->trunk_link.link3.state = 0; |
James Smart | 845d032 | 2019-08-14 16:57:01 -0700 | [diff] [blame] | 925 | phba->sli4_hba.link_state.logical_speed = |
| 926 | LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 927 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 928 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 929 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 930 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 931 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 932 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 933 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 934 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 935 | /* Issue a LINK DOWN event to all nodes */ |
| 936 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 937 | |
| 938 | vports[i]->fc_myDID = 0; |
| 939 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 940 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 941 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 942 | if (phba->nvmet_support) |
| 943 | lpfc_nvmet_update_targetport(phba); |
| 944 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 945 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 946 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 947 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 948 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 949 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 950 | |
| 951 | /* Clean up any SLI3 firmware default rpi's */ |
| 952 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 953 | goto skip_unreg_did; |
| 954 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 955 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 956 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 957 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 958 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 959 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 960 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 962 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 966 | skip_unreg_did: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 969 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 970 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 972 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 973 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 974 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 976 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | } |
| 978 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 979 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 980 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 981 | phba->pport->rcv_flogi_cnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 984 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | } |
| 986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | static void |
| 988 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | struct lpfc_nodelist *ndlp; |
| 991 | |
| 992 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | a3da825 | 2018-03-05 12:04:06 -0800 | [diff] [blame] | 993 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 994 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 995 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 996 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 997 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 998 | /* On Linkup its safe to clean up the ndlp |
| 999 | * from Fabric connections. |
| 1000 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1001 | if (ndlp->nlp_DID != Fabric_DID) |
| 1002 | lpfc_unreg_rpi(vport, ndlp); |
| 1003 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 1004 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1005 | /* Fail outstanding IO now since device is |
| 1006 | * marked for PLOGI. |
| 1007 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1008 | lpfc_unreg_rpi(vport, ndlp); |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 1015 | { |
| 1016 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1017 | struct lpfc_hba *phba = vport->phba; |
| 1018 | |
| 1019 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 1020 | return; |
| 1021 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1022 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1023 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 1024 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 1025 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1026 | /* If NPIV is not enabled, only bring the physical port up */ |
| 1027 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1028 | (vport != phba->pport)) |
| 1029 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1031 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1032 | fc_host_post_event(shost, fc_get_event_number(), |
| 1033 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1034 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1035 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1036 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1037 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1038 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1039 | vport->fc_ns_retry = 0; |
| 1040 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | |
James Smart | b3f2e67 | 2020-11-15 11:26:37 -0800 | [diff] [blame] | 1042 | lpfc_linkup_cleanup_nodes(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static int |
| 1046 | lpfc_linkup(struct lpfc_hba *phba) |
| 1047 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1048 | struct lpfc_vport **vports; |
| 1049 | int i; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1050 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1051 | |
| 1052 | phba->link_state = LPFC_LINK_UP; |
| 1053 | |
| 1054 | /* Unblock fabric iocbs if they are blocked */ |
| 1055 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1056 | del_timer_sync(&phba->fabric_block_timer); |
| 1057 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1058 | vports = lpfc_create_vport_work_array(phba); |
| 1059 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1060 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1061 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1062 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1064 | /* Clear the pport flogi counter in case the link down was |
| 1065 | * absorbed without an ACQE. No lock here - in worker thread |
| 1066 | * and discovery is synchronized. |
| 1067 | */ |
| 1068 | spin_lock_irq(shost->host_lock); |
| 1069 | phba->pport->rcv_flogi_cnt = 0; |
| 1070 | spin_unlock_irq(shost->host_lock); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1071 | |
| 1072 | /* reinitialize initial FLOGI flag */ |
| 1073 | phba->hba_flag &= ~(HBA_FLOGI_ISSUED); |
| 1074 | phba->defer_flogi_acc_flag = false; |
| 1075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | * This routine handles processing a CLEAR_LA mailbox |
| 1081 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1082 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1083 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1085 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1086 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1087 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | struct lpfc_vport *vport = pmb->vport; |
| 1089 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1090 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1091 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | uint32_t control; |
| 1093 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1095 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1096 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | |
| 1098 | /* Check for error */ |
| 1099 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1100 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1101 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1102 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1103 | "state x%x\n", |
| 1104 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | goto out; |
| 1107 | } |
| 1108 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1109 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1110 | phba->link_state = LPFC_HBA_READY; |
| 1111 | |
| 1112 | spin_lock_irq(&phba->hbalock); |
| 1113 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1114 | control = readl(phba->HCregaddr); |
| 1115 | control |= HC_LAINT_ENA; |
| 1116 | writel(control, phba->HCregaddr); |
| 1117 | readl(phba->HCregaddr); /* flush */ |
| 1118 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1119 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1120 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1122 | out: |
| 1123 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1124 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1125 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1128 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1129 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
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 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1132 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | |
| 1134 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | |
| 1136 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1137 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1138 | control = readl(phba->HCregaddr); |
| 1139 | control |= HC_LAINT_ENA; |
| 1140 | writel(control, phba->HCregaddr); |
| 1141 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1142 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | |
| 1144 | return; |
| 1145 | } |
| 1146 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1147 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1148 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1149 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1150 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1151 | LPFC_MBOXQ_t *sparam_mb; |
| 1152 | struct lpfc_dmabuf *sparam_mp; |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1153 | u16 status = pmb->u.mb.mbxStatus; |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1154 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1156 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1157 | |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1158 | if (status) |
| 1159 | goto out; |
| 1160 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1161 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1162 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1163 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1164 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1165 | return; |
| 1166 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1167 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1168 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1169 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1170 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1171 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1172 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1173 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1174 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1175 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1176 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1177 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1178 | /* Start discovery by sending a FLOGI. port_state is identically |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1179 | * LPFC_FLOGI while waiting for FLOGI cmpl. |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1180 | */ |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1181 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1182 | /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if |
| 1183 | * bb-credit recovery is in place. |
| 1184 | */ |
| 1185 | if (phba->bbcredit_support && phba->cfg_enable_bbcr && |
| 1186 | !(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 1187 | sparam_mb = mempool_alloc(phba->mbox_mem_pool, |
| 1188 | GFP_KERNEL); |
| 1189 | if (!sparam_mb) |
| 1190 | goto sparam_out; |
| 1191 | |
| 1192 | rc = lpfc_read_sparam(phba, sparam_mb, 0); |
| 1193 | if (rc) { |
| 1194 | mempool_free(sparam_mb, phba->mbox_mem_pool); |
| 1195 | goto sparam_out; |
| 1196 | } |
| 1197 | sparam_mb->vport = vport; |
| 1198 | sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 1199 | rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT); |
| 1200 | if (rc == MBX_NOT_FINISHED) { |
| 1201 | sparam_mp = (struct lpfc_dmabuf *) |
| 1202 | sparam_mb->ctx_buf; |
| 1203 | lpfc_mbuf_free(phba, sparam_mp->virt, |
| 1204 | sparam_mp->phys); |
| 1205 | kfree(sparam_mp); |
| 1206 | sparam_mb->ctx_buf = NULL; |
| 1207 | mempool_free(sparam_mb, phba->mbox_mem_pool); |
| 1208 | goto sparam_out; |
| 1209 | } |
| 1210 | |
| 1211 | phba->hba_flag |= HBA_DEFER_FLOGI; |
| 1212 | } else { |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1213 | lpfc_initial_flogi(vport); |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 1214 | } |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 1215 | } else { |
| 1216 | if (vport->fc_flag & FC_PT2PT) |
| 1217 | lpfc_disc_start(vport); |
| 1218 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1219 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | |
| 1221 | out: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1222 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1223 | "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n", |
| 1224 | status, vport->port_state); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1225 | |
Dan Carpenter | 0be3109 | 2021-01-25 11:44:34 +0300 | [diff] [blame] | 1226 | sparam_out: |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1227 | lpfc_linkdown(phba); |
| 1228 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1229 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1230 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1231 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1233 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | return; |
| 1235 | } |
| 1236 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1237 | /** |
| 1238 | * lpfc_sli4_clear_fcf_rr_bmask |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1239 | * @phba: pointer to the struct lpfc_hba for this port. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1240 | * This fucnction resets the round robin bit mask and clears the |
| 1241 | * fcf priority list. The list deletions are done while holding the |
| 1242 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1243 | * from the lpfc_fcf_pri record. |
| 1244 | **/ |
| 1245 | void |
| 1246 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1247 | { |
| 1248 | struct lpfc_fcf_pri *fcf_pri; |
| 1249 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1250 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1251 | spin_lock_irq(&phba->hbalock); |
| 1252 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1253 | &phba->fcf.fcf_pri_list, list) { |
| 1254 | list_del_init(&fcf_pri->list); |
| 1255 | fcf_pri->fcf_rec.flag = 0; |
| 1256 | } |
| 1257 | spin_unlock_irq(&phba->hbalock); |
| 1258 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1260 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1261 | { |
| 1262 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1263 | |
| 1264 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1265 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 1266 | "2017 REG_FCFI mbxStatus error x%x " |
| 1267 | "HBA state x%x\n", mboxq->u.mb.mbxStatus, |
| 1268 | vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1269 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1273 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1274 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1275 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1276 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1277 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1278 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1279 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1280 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1281 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1282 | goto fail_out; |
| 1283 | |
| 1284 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1285 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1286 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1287 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1288 | if (vport->port_state != LPFC_FLOGI) { |
| 1289 | phba->hba_flag |= FCF_RR_INPROG; |
| 1290 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1291 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1292 | goto out; |
| 1293 | } |
| 1294 | spin_unlock_irq(&phba->hbalock); |
| 1295 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1296 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1297 | fail_out: |
| 1298 | spin_lock_irq(&phba->hbalock); |
| 1299 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1300 | spin_unlock_irq(&phba->hbalock); |
| 1301 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1302 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | /** |
| 1306 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1307 | * @fab_name: pointer to fabric name. |
| 1308 | * @new_fcf_record: pointer to fcf record. |
| 1309 | * |
| 1310 | * This routine compare the fcf record's fabric name with provided |
| 1311 | * fabric name. If the fabric name are identical this function |
| 1312 | * returns 1 else return 0. |
| 1313 | **/ |
| 1314 | static uint32_t |
| 1315 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1316 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1317 | 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] | 1318 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1319 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1320 | return 0; |
| 1321 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1322 | return 0; |
| 1323 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1324 | return 0; |
| 1325 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1326 | return 0; |
| 1327 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1328 | return 0; |
| 1329 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1330 | return 0; |
| 1331 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1332 | return 0; |
| 1333 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1337 | * lpfc_sw_name_match - Check if the fcf switch name match. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1338 | * @sw_name: pointer to switch name. |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1339 | * @new_fcf_record: pointer to fcf record. |
| 1340 | * |
| 1341 | * This routine compare the fcf record's switch name with provided |
| 1342 | * switch name. If the switch name are identical this function |
| 1343 | * returns 1 else return 0. |
| 1344 | **/ |
| 1345 | static uint32_t |
| 1346 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1347 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1348 | 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] | 1349 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1350 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1351 | return 0; |
| 1352 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1353 | return 0; |
| 1354 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1355 | return 0; |
| 1356 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1357 | return 0; |
| 1358 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1359 | return 0; |
| 1360 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1361 | return 0; |
| 1362 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1363 | return 0; |
| 1364 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1368 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1370 | * @new_fcf_record: pointer to fcf record. |
| 1371 | * |
| 1372 | * This routine compare the fcf record's mac address with HBA's |
| 1373 | * FCF mac address. If the mac addresses are identical this function |
| 1374 | * returns 1 else return 0. |
| 1375 | **/ |
| 1376 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1377 | 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] | 1378 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1379 | 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] | 1380 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1381 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1382 | return 0; |
| 1383 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1384 | return 0; |
| 1385 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1386 | return 0; |
| 1387 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1388 | return 0; |
| 1389 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1390 | return 0; |
| 1391 | return 1; |
| 1392 | } |
| 1393 | |
| 1394 | static bool |
| 1395 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1396 | { |
| 1397 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1401 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1402 | * @phba: pointer to lpfc hba data structure. |
| 1403 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1404 | * @new_fcf_record: pointer to hba fcf record. |
| 1405 | * |
| 1406 | * 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] | 1407 | * record. The hbalock is asserted held in the code path calling this |
| 1408 | * routine. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1409 | **/ |
| 1410 | static void |
| 1411 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1412 | struct fcf_record *new_fcf_record |
| 1413 | ) |
| 1414 | { |
| 1415 | struct lpfc_fcf_pri *fcf_pri; |
| 1416 | |
| 1417 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1418 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1419 | /* FCF record priority */ |
| 1420 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1421 | |
| 1422 | } |
| 1423 | |
| 1424 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1425 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1426 | * @fcf_rec: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1427 | * @new_fcf_record: pointer to fcf record. |
| 1428 | * |
| 1429 | * This routine copies the FCF information from the FCF |
| 1430 | * record to lpfc_hba data structure. |
| 1431 | **/ |
| 1432 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1433 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1434 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1435 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1436 | /* Fabric name */ |
| 1437 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1438 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1439 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1440 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1441 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1442 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1443 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1444 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1445 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1446 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1447 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1448 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1449 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1450 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1451 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1452 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1453 | /* Mac address */ |
| 1454 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1455 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1456 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1457 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1458 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1459 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1460 | /* FCF record index */ |
| 1461 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1462 | /* FCF record priority */ |
| 1463 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1464 | /* Switch name */ |
| 1465 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1466 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1467 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1468 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1469 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1470 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1471 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1472 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1473 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1474 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1475 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1476 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1477 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1478 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1479 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1480 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
Lee Jones | 3884ce1 | 2021-03-03 14:46:28 +0000 | [diff] [blame] | 1484 | * __lpfc_update_fcf_record - Update driver fcf record |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1485 | * @phba: pointer to lpfc hba data structure. |
| 1486 | * @fcf_rec: pointer to driver fcf record. |
| 1487 | * @new_fcf_record: pointer to hba fcf record. |
| 1488 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1489 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1490 | * @flag: flag bits to be set to the driver fcf record. |
| 1491 | * |
| 1492 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1493 | * together with the address mode, vlan_id, and other informations. This |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1494 | * routine is called with the hbalock held. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1495 | **/ |
| 1496 | static void |
| 1497 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1498 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1499 | uint16_t vlan_id, uint32_t flag) |
| 1500 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1501 | lockdep_assert_held(&phba->hbalock); |
| 1502 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1503 | /* Copy the fields from the HBA's FCF record */ |
| 1504 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1505 | /* Update other fields of driver FCF record */ |
| 1506 | fcf_rec->addr_mode = addr_mode; |
| 1507 | fcf_rec->vlan_id = vlan_id; |
| 1508 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1509 | __lpfc_update_fcf_record_pri(phba, |
| 1510 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1511 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1515 | * lpfc_register_fcf - Register the FCF with hba. |
| 1516 | * @phba: pointer to lpfc hba data structure. |
| 1517 | * |
| 1518 | * This routine issues a register fcfi mailbox command to register |
| 1519 | * the fcf with HBA. |
| 1520 | **/ |
| 1521 | static void |
| 1522 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1523 | { |
| 1524 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1525 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1526 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1527 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1528 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1529 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1530 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1531 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1532 | return; |
| 1533 | } |
| 1534 | |
| 1535 | /* The FCF is already registered, start discovery */ |
| 1536 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1537 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1538 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1539 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1540 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1541 | phba->hba_flag |= FCF_RR_INPROG; |
| 1542 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1543 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1544 | return; |
| 1545 | } |
| 1546 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1547 | return; |
| 1548 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1549 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1550 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1551 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1552 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1553 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1554 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1555 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1556 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1557 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1558 | |
| 1559 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1560 | fcf_mbxq->vport = phba->pport; |
| 1561 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1562 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1563 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1564 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1565 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1566 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1567 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1568 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1569 | |
| 1570 | return; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1575 | * @phba: pointer to lpfc hba data structure. |
| 1576 | * @new_fcf_record: pointer to fcf record. |
| 1577 | * @boot_flag: Indicates if this record used by boot bios. |
| 1578 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1579 | * @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] | 1580 | * |
| 1581 | * This routine compare the fcf record with connect list obtained from the |
| 1582 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1583 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1584 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1585 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1586 | * used for this FCF when the function returns. |
| 1587 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1588 | * 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] | 1589 | * 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] | 1590 | **/ |
| 1591 | static int |
| 1592 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1593 | struct fcf_record *new_fcf_record, |
| 1594 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1595 | uint16_t *vlan_id) |
| 1596 | { |
| 1597 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1598 | int i, j, fcf_vlan_id = 0; |
| 1599 | |
| 1600 | /* Find the lowest VLAN id in the FCF record */ |
| 1601 | for (i = 0; i < 512; i++) { |
| 1602 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1603 | fcf_vlan_id = i * 8; |
| 1604 | j = 0; |
| 1605 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1606 | j++; |
| 1607 | fcf_vlan_id++; |
| 1608 | } |
| 1609 | break; |
| 1610 | } |
| 1611 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1612 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1613 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1614 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1615 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1616 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1617 | return 0; |
| 1618 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1619 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1620 | *boot_flag = 0; |
| 1621 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1622 | new_fcf_record); |
| 1623 | if (phba->valid_vlan) |
| 1624 | *vlan_id = phba->vlan_id; |
| 1625 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1626 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1627 | return 1; |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * If there are no FCF connection table entry, driver connect to all |
| 1632 | * FCFs. |
| 1633 | */ |
| 1634 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1635 | *boot_flag = 0; |
| 1636 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1637 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1638 | |
| 1639 | /* |
| 1640 | * When there are no FCF connect entries, use driver's default |
| 1641 | * addressing mode - FPMA. |
| 1642 | */ |
| 1643 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1644 | *addr_mode = LPFC_FCF_FPMA; |
| 1645 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1646 | /* If FCF record report a vlan id use that vlan id */ |
| 1647 | if (fcf_vlan_id) |
| 1648 | *vlan_id = fcf_vlan_id; |
| 1649 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1650 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1651 | return 1; |
| 1652 | } |
| 1653 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1654 | list_for_each_entry(conn_entry, |
| 1655 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1656 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1657 | continue; |
| 1658 | |
| 1659 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1660 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1661 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1662 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1663 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1664 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1665 | new_fcf_record)) |
| 1666 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1667 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1668 | /* |
| 1669 | * If the vlan bit map does not have the bit set for the |
| 1670 | * vlan id to be used, then it is not a match. |
| 1671 | */ |
| 1672 | if (!(new_fcf_record->vlan_bitmap |
| 1673 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1674 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1675 | continue; |
| 1676 | } |
| 1677 | |
| 1678 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1679 | * If connection record does not support any addressing mode, |
| 1680 | * skip the FCF record. |
| 1681 | */ |
| 1682 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1683 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1684 | continue; |
| 1685 | |
| 1686 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1687 | * Check if the connection record specifies a required |
| 1688 | * addressing mode. |
| 1689 | */ |
| 1690 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1691 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1692 | |
| 1693 | /* |
| 1694 | * If SPMA required but FCF not support this continue. |
| 1695 | */ |
| 1696 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1697 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1698 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1699 | continue; |
| 1700 | |
| 1701 | /* |
| 1702 | * If FPMA required but FCF not support this continue. |
| 1703 | */ |
| 1704 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1705 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1706 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1707 | continue; |
| 1708 | } |
| 1709 | |
| 1710 | /* |
| 1711 | * This fcf record matches filtering criteria. |
| 1712 | */ |
| 1713 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1714 | *boot_flag = 1; |
| 1715 | else |
| 1716 | *boot_flag = 0; |
| 1717 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1718 | /* |
| 1719 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1720 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1721 | * by FCF, allow fabric to pick the addressing mode. |
| 1722 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1723 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1724 | new_fcf_record); |
| 1725 | /* |
| 1726 | * If the user specified a required address mode, assign that |
| 1727 | * address mode |
| 1728 | */ |
| 1729 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1730 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1731 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1732 | FCFCNCT_AM_SPMA) ? |
| 1733 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1734 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1735 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1736 | * addr mode only if FCF support the addr_mode. |
| 1737 | */ |
| 1738 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1739 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1740 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1741 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1742 | *addr_mode = LPFC_FCF_SPMA; |
| 1743 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1744 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1745 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1746 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1747 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1748 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1749 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1750 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1751 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1752 | /* |
| 1753 | * If no vlan id is specified in connect list, use the vlan id |
| 1754 | * in the FCF record |
| 1755 | */ |
| 1756 | else if (fcf_vlan_id) |
| 1757 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1758 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1759 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1760 | |
| 1761 | return 1; |
| 1762 | } |
| 1763 | |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
| 1767 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1768 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1769 | * @phba: pointer to lpfc hba data structure. |
| 1770 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1771 | * |
| 1772 | * This function check if there is any fcoe event pending while driver |
| 1773 | * scan FCF entries. If there is any pending event, it will restart the |
| 1774 | * FCF saning and return 1 else return 0. |
| 1775 | */ |
| 1776 | int |
| 1777 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1778 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1779 | /* |
| 1780 | * If the Link is up and no FCoE events while in the |
| 1781 | * FCF discovery, no need to restart FCF discovery. |
| 1782 | */ |
| 1783 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1784 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1785 | return 0; |
| 1786 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1787 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1788 | "2768 Pending link or FCF event during current " |
| 1789 | "handling of the previous event: link_state:x%x, " |
| 1790 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1791 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1792 | phba->fcoe_eventtag); |
| 1793 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1794 | spin_lock_irq(&phba->hbalock); |
| 1795 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1796 | spin_unlock_irq(&phba->hbalock); |
| 1797 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1798 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1799 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1800 | "2780 Restart FCF table scan due to " |
| 1801 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1802 | "evt_tag_current:x%x\n", |
| 1803 | phba->fcoe_eventtag_at_fcf_scan, |
| 1804 | phba->fcoe_eventtag); |
| 1805 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1806 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1807 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1808 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1809 | * flag |
| 1810 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1811 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1812 | "2833 Stop FCF discovery process due to link " |
| 1813 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1814 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1815 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1816 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1817 | spin_unlock_irq(&phba->hbalock); |
| 1818 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1819 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1820 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1821 | if (unreg_fcf) { |
| 1822 | spin_lock_irq(&phba->hbalock); |
| 1823 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1824 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1825 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1826 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1827 | return 1; |
| 1828 | } |
| 1829 | |
| 1830 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1831 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1832 | * @phba: pointer to lpfc hba data structure. |
| 1833 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1834 | * |
| 1835 | * This function makes an running random selection decision on FCF record to |
| 1836 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1837 | * probability. To perform integer manunipulation of random numbers with |
| 1838 | * 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] | 1839 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1840 | * |
| 1841 | * Returns true when outcome is for the newly read FCF record should be |
| 1842 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1843 | * chosen FCF record. |
| 1844 | **/ |
| 1845 | static bool |
| 1846 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1847 | { |
| 1848 | uint32_t rand_num; |
| 1849 | |
| 1850 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1851 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1852 | |
| 1853 | /* Decision with probability 1/fcf_cnt */ |
| 1854 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1855 | return true; |
| 1856 | else |
| 1857 | return false; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1861 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1862 | * @phba: pointer to lpfc hba data structure. |
| 1863 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1864 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1865 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1866 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1867 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1868 | * SGE parsing, and endianness swapping. |
| 1869 | * |
| 1870 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1871 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1872 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1873 | static struct fcf_record * |
| 1874 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1875 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1876 | { |
| 1877 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1878 | struct lpfc_mbx_sge sge; |
| 1879 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1880 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1881 | union lpfc_sli4_cfg_shdr *shdr; |
| 1882 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1883 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1884 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1885 | * routine only uses a single SGE. |
| 1886 | */ |
| 1887 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1888 | if (unlikely(!mboxq->sge_array)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1889 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1890 | "2524 Failed to get the non-embedded SGE " |
| 1891 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1892 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1893 | } |
| 1894 | virt_addr = mboxq->sge_array->addr[0]; |
| 1895 | |
| 1896 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1897 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1898 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1899 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1900 | 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] | 1901 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1902 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1903 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1904 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1905 | lpfc_printf_log(phba, KERN_ERR, |
| 1906 | LOG_TRACE_EVENT, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1907 | "2726 READ_FCF_RECORD Indicates empty " |
| 1908 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1909 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1910 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1911 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1912 | "with status x%x add_status x%x, " |
| 1913 | "mbx\n", shdr_status, shdr_add_status); |
| 1914 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1915 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1916 | |
| 1917 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1918 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1919 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1920 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1921 | *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] | 1922 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1923 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1924 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1925 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1926 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1927 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1928 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1929 | return new_fcf_record; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1934 | * @phba: pointer to lpfc hba data structure. |
| 1935 | * @fcf_record: pointer to the fcf record. |
| 1936 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1937 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1938 | * |
| 1939 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1940 | * enabled. |
| 1941 | **/ |
| 1942 | static void |
| 1943 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1944 | struct fcf_record *fcf_record, |
| 1945 | uint16_t vlan_id, |
| 1946 | uint16_t next_fcf_index) |
| 1947 | { |
| 1948 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1949 | "2764 READ_FCF_RECORD:\n" |
| 1950 | "\tFCF_Index : x%x\n" |
| 1951 | "\tFCF_Avail : x%x\n" |
| 1952 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1953 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1954 | "\tFIP_Priority : x%x\n" |
| 1955 | "\tMAC_Provider : x%x\n" |
| 1956 | "\tLowest VLANID : x%x\n" |
| 1957 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1958 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1959 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1960 | "\tNext_FCF_Index: x%x\n", |
| 1961 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1962 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1963 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1964 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1965 | fcf_record->fip_priority, |
| 1966 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1967 | vlan_id, |
| 1968 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1969 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1970 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1971 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1972 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1973 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1974 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1975 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1976 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1977 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1978 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1979 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1980 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1981 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1982 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1983 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1984 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1985 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1986 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1987 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1988 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1989 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1990 | next_fcf_index); |
| 1991 | } |
| 1992 | |
| 1993 | /** |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 1994 | * 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] | 1995 | * @phba: pointer to lpfc hba data structure. |
| 1996 | * @fcf_rec: pointer to an existing FCF record. |
| 1997 | * @new_fcf_record: pointer to a new FCF record. |
| 1998 | * @new_vlan_id: vlan id from the new FCF record. |
| 1999 | * |
| 2000 | * This function performs matching test of a new FCF record against an existing |
| 2001 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 2002 | * will not be used as part of the FCF record matching criteria. |
| 2003 | * |
| 2004 | * Returns true if all the fields matching, otherwise returns false. |
| 2005 | */ |
| 2006 | static bool |
| 2007 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 2008 | struct lpfc_fcf_rec *fcf_rec, |
| 2009 | struct fcf_record *new_fcf_record, |
| 2010 | uint16_t new_vlan_id) |
| 2011 | { |
| 2012 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 2013 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 2014 | return false; |
| 2015 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 2016 | return false; |
| 2017 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 2018 | return false; |
| 2019 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 2020 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2021 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 2022 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2023 | return true; |
| 2024 | } |
| 2025 | |
| 2026 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2027 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 2028 | * @vport: Pointer to vport object. |
| 2029 | * @fcf_index: index to next fcf. |
| 2030 | * |
| 2031 | * This function processing the roundrobin fcf failover to next fcf index. |
| 2032 | * When this function is invoked, there will be a current fcf registered |
| 2033 | * for flogi. |
| 2034 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 2035 | * 1 for stop flogi on currently registered fcf; |
| 2036 | */ |
| 2037 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 2038 | { |
| 2039 | struct lpfc_hba *phba = vport->phba; |
| 2040 | int rc; |
| 2041 | |
| 2042 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 2043 | spin_lock_irq(&phba->hbalock); |
| 2044 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2045 | spin_unlock_irq(&phba->hbalock); |
| 2046 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2047 | "2872 Devloss tmo with no eligible " |
| 2048 | "FCF, unregister in-use FCF (x%x) " |
| 2049 | "and rescan FCF table\n", |
| 2050 | phba->fcf.current_rec.fcf_indx); |
| 2051 | lpfc_unregister_fcf_rescan(phba); |
| 2052 | goto stop_flogi_current_fcf; |
| 2053 | } |
| 2054 | /* Mark the end to FLOGI roundrobin failover */ |
| 2055 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 2056 | /* Allow action to new fcf asynchronous event */ |
| 2057 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 2058 | spin_unlock_irq(&phba->hbalock); |
| 2059 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2060 | "2865 No FCF available, stop roundrobin FCF " |
| 2061 | "failover and change port state:x%x/x%x\n", |
| 2062 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 2063 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 2064 | |
| 2065 | if (!phba->fcf.fcf_redisc_attempted) { |
| 2066 | lpfc_unregister_fcf(phba); |
| 2067 | |
| 2068 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 2069 | if (!rc) { |
| 2070 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2071 | "3195 Rediscover FCF table\n"); |
| 2072 | phba->fcf.fcf_redisc_attempted = 1; |
| 2073 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 2074 | } else { |
| 2075 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2076 | "3196 Rediscover FCF table " |
| 2077 | "failed. Status:x%x\n", rc); |
| 2078 | } |
| 2079 | } else { |
| 2080 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2081 | "3197 Already rediscover FCF table " |
| 2082 | "attempted. No more retry\n"); |
| 2083 | } |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2084 | goto stop_flogi_current_fcf; |
| 2085 | } else { |
| 2086 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 2087 | "2794 Try FLOGI roundrobin FCF failover to " |
| 2088 | "(x%x)\n", fcf_index); |
| 2089 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 2090 | if (rc) |
| 2091 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 2092 | "2761 FLOGI roundrobin FCF failover " |
| 2093 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 2094 | rc, phba->fcf.current_rec.fcf_indx); |
| 2095 | else |
| 2096 | goto stop_flogi_current_fcf; |
| 2097 | } |
| 2098 | return 0; |
| 2099 | |
| 2100 | stop_flogi_current_fcf: |
| 2101 | lpfc_can_disctmo(vport); |
| 2102 | return 1; |
| 2103 | } |
| 2104 | |
| 2105 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2106 | * lpfc_sli4_fcf_pri_list_del |
| 2107 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2108 | * @fcf_index: the index of the fcf record to delete |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2109 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2110 | * If it is one the list then it is removed from the list, and the flag |
| 2111 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2112 | * record from the list. |
| 2113 | **/ |
| 2114 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2115 | uint16_t fcf_index) |
| 2116 | { |
| 2117 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2118 | |
| 2119 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2120 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2121 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2122 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2123 | new_fcf_pri->fcf_rec.flag); |
| 2124 | spin_lock_irq(&phba->hbalock); |
| 2125 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2126 | if (phba->fcf.current_rec.priority == |
| 2127 | new_fcf_pri->fcf_rec.priority) |
| 2128 | phba->fcf.eligible_fcf_cnt--; |
| 2129 | list_del_init(&new_fcf_pri->list); |
| 2130 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2131 | } |
| 2132 | spin_unlock_irq(&phba->hbalock); |
| 2133 | } |
| 2134 | |
| 2135 | /** |
| 2136 | * lpfc_sli4_set_fcf_flogi_fail |
| 2137 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2138 | * @fcf_index: the index of the fcf record to update |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2139 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2140 | * flag so the the round robin slection for the particular priority level |
| 2141 | * will try a different fcf record that does not have this bit set. |
| 2142 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2143 | * adding it to the priority list. |
| 2144 | **/ |
| 2145 | void |
| 2146 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2147 | { |
| 2148 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2149 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2150 | spin_lock_irq(&phba->hbalock); |
| 2151 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2152 | spin_unlock_irq(&phba->hbalock); |
| 2153 | } |
| 2154 | |
| 2155 | /** |
| 2156 | * lpfc_sli4_fcf_pri_list_add |
| 2157 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | e415f2a | 2020-07-23 13:24:08 +0100 | [diff] [blame] | 2158 | * @fcf_index: the index of the fcf record to add |
| 2159 | * @new_fcf_record: pointer to a new FCF record. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2160 | * This routine checks the priority of the fcf_index to be added. |
| 2161 | * If it is a lower priority than the current head of the fcf_pri list |
| 2162 | * then it is added to the list in the right order. |
| 2163 | * If it is the same priority as the current head of the list then it |
| 2164 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2165 | * If the fcf_index to be added is of a higher priority than the current |
| 2166 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2167 | * rr_bmask and it is added to the head of the list. |
| 2168 | * returns: |
| 2169 | * 0=success 1=failure |
| 2170 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2171 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2172 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2173 | struct fcf_record *new_fcf_record) |
| 2174 | { |
| 2175 | uint16_t current_fcf_pri; |
| 2176 | uint16_t last_index; |
| 2177 | struct lpfc_fcf_pri *fcf_pri; |
| 2178 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2179 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2180 | int ret; |
| 2181 | |
| 2182 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2183 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2184 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2185 | fcf_index, new_fcf_record->fip_priority, |
| 2186 | new_fcf_pri->fcf_rec.flag); |
| 2187 | spin_lock_irq(&phba->hbalock); |
| 2188 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2189 | list_del_init(&new_fcf_pri->list); |
| 2190 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2191 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2192 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2193 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2194 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2195 | new_fcf_pri->fcf_rec.fcf_index); |
| 2196 | goto out; |
| 2197 | } |
| 2198 | |
| 2199 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2200 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2201 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2202 | ret = 0; /* Empty rr list */ |
| 2203 | goto out; |
| 2204 | } |
| 2205 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2206 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2207 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2208 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2209 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2210 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2211 | /* fcfs_at_this_priority_level = 1; */ |
| 2212 | phba->fcf.eligible_fcf_cnt = 1; |
| 2213 | } else |
| 2214 | /* fcfs_at_this_priority_level++; */ |
| 2215 | phba->fcf.eligible_fcf_cnt++; |
| 2216 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2217 | new_fcf_pri->fcf_rec.fcf_index); |
| 2218 | goto out; |
| 2219 | } |
| 2220 | |
| 2221 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2222 | &phba->fcf.fcf_pri_list, list) { |
| 2223 | if (new_fcf_pri->fcf_rec.priority <= |
| 2224 | fcf_pri->fcf_rec.priority) { |
| 2225 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2226 | list_add(&new_fcf_pri->list, |
| 2227 | &phba->fcf.fcf_pri_list); |
| 2228 | else |
| 2229 | list_add(&new_fcf_pri->list, |
| 2230 | &((struct lpfc_fcf_pri *) |
| 2231 | fcf_pri->list.prev)->list); |
| 2232 | ret = 0; |
| 2233 | goto out; |
| 2234 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2235 | || new_fcf_pri->fcf_rec.priority < |
| 2236 | next_fcf_pri->fcf_rec.priority) { |
| 2237 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2238 | ret = 0; |
| 2239 | goto out; |
| 2240 | } |
| 2241 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2242 | continue; |
| 2243 | |
| 2244 | } |
| 2245 | ret = 1; |
| 2246 | out: |
| 2247 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2248 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2249 | spin_unlock_irq(&phba->hbalock); |
| 2250 | return ret; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2254 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2255 | * @phba: pointer to lpfc hba data structure. |
| 2256 | * @mboxq: pointer to mailbox object. |
| 2257 | * |
| 2258 | * This function iterates through all the fcf records available in |
| 2259 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2260 | * the FCF for discovery it registers the FCF record and kicks start |
| 2261 | * discovery. |
| 2262 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2263 | * use an FCF record which matches fabric name and mac address of the |
| 2264 | * currently used FCF record. |
| 2265 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2266 | * used by BOOT_BIOS. |
| 2267 | */ |
| 2268 | void |
| 2269 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2270 | { |
| 2271 | struct fcf_record *new_fcf_record; |
| 2272 | uint32_t boot_flag, addr_mode; |
| 2273 | uint16_t fcf_index, next_fcf_index; |
| 2274 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2275 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2276 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2277 | int rc; |
| 2278 | |
| 2279 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2280 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2281 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2286 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2287 | &next_fcf_index); |
| 2288 | if (!new_fcf_record) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2289 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2290 | "2765 Mailbox command READ_FCF_RECORD " |
| 2291 | "failed to retrieve a FCF record.\n"); |
| 2292 | /* Let next new FCF event trigger fast failover */ |
| 2293 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2294 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2295 | spin_unlock_irq(&phba->hbalock); |
| 2296 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2297 | return; |
| 2298 | } |
| 2299 | |
| 2300 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2301 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2302 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2303 | |
| 2304 | /* Log the FCF record information if turned on */ |
| 2305 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2306 | next_fcf_index); |
| 2307 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2308 | /* |
| 2309 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2310 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2311 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2312 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2313 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2314 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2315 | bf_get(lpfc_fcf_record_fcf_index, |
| 2316 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2317 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2318 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2319 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2320 | bf_get(lpfc_fcf_record_fcf_index, |
| 2321 | new_fcf_record), |
| 2322 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2323 | new_fcf_record), |
| 2324 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2325 | new_fcf_record), |
| 2326 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2327 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2328 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2329 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2330 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2331 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2332 | phba->fcf.current_rec.fcf_indx) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2333 | lpfc_printf_log(phba, KERN_ERR, |
| 2334 | LOG_TRACE_EVENT, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2335 | "2862 FCF (x%x) matches property " |
| 2336 | "of in-use FCF (x%x)\n", |
| 2337 | bf_get(lpfc_fcf_record_fcf_index, |
| 2338 | new_fcf_record), |
| 2339 | phba->fcf.current_rec.fcf_indx); |
| 2340 | goto read_next_fcf; |
| 2341 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2342 | /* |
| 2343 | * In case the current in-use FCF record becomes |
| 2344 | * invalid/unavailable during FCF discovery that |
| 2345 | * was not triggered by fast FCF failover process, |
| 2346 | * treat it as fast FCF failover. |
| 2347 | */ |
| 2348 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2349 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2350 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2351 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2352 | "(x%x), enter FCF failover " |
| 2353 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2354 | phba->fcf.current_rec.fcf_indx); |
| 2355 | spin_lock_irq(&phba->hbalock); |
| 2356 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2357 | spin_unlock_irq(&phba->hbalock); |
| 2358 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2359 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2360 | LPFC_FCOE_FCF_GET_FIRST); |
| 2361 | return; |
| 2362 | } |
| 2363 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2364 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2365 | } else { |
| 2366 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2367 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2368 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2369 | if (rc) |
| 2370 | goto read_next_fcf; |
| 2371 | } |
| 2372 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2373 | /* |
| 2374 | * 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] | 2375 | * FCF record for the discovery. The condition that a rescan |
| 2376 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2377 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2378 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2379 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2380 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2381 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2382 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2383 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2384 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2385 | phba->fcf.current_rec.fcf_indx) { |
| 2386 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2387 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2388 | /* Stop FCF redisc wait timer */ |
| 2389 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2390 | phba); |
| 2391 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2392 | /* Fast failover, mark completed */ |
| 2393 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2394 | spin_unlock_irq(&phba->hbalock); |
| 2395 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2396 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2397 | "FCF (x%x), port_state:x%x, " |
| 2398 | "fc_flag:x%x\n", |
| 2399 | phba->fcf.current_rec.fcf_indx, |
| 2400 | phba->pport->port_state, |
| 2401 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2402 | goto out; |
| 2403 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2404 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2405 | "2863 New FCF (x%x) matches " |
| 2406 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2407 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2408 | new_fcf_record), |
| 2409 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2410 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2411 | /* |
| 2412 | * Read next FCF record from HBA searching for the matching |
| 2413 | * with in-use record only if not during the fast failover |
| 2414 | * period. In case of fast failover period, it shall try to |
| 2415 | * determine whether the FCF record just read should be the |
| 2416 | * next candidate. |
| 2417 | */ |
| 2418 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2419 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2420 | goto read_next_fcf; |
| 2421 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2422 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2423 | /* |
| 2424 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2425 | * period; otherwise, update on current FCF record. |
| 2426 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2427 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2428 | fcf_rec = &phba->fcf.failover_rec; |
| 2429 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2430 | fcf_rec = &phba->fcf.current_rec; |
| 2431 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2432 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2433 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2434 | * If the driver FCF record does not have boot flag |
| 2435 | * set and new hba fcf record has boot flag set, use |
| 2436 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2437 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2438 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2439 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2440 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2441 | "2837 Update current FCF record " |
| 2442 | "(x%x) with new FCF record (x%x)\n", |
| 2443 | fcf_rec->fcf_indx, |
| 2444 | bf_get(lpfc_fcf_record_fcf_index, |
| 2445 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2446 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2447 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2448 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2449 | goto read_next_fcf; |
| 2450 | } |
| 2451 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2452 | * If the driver FCF record has boot flag set and the |
| 2453 | * new hba FCF record does not have boot flag, read |
| 2454 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2455 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2456 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2457 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2458 | goto read_next_fcf; |
| 2459 | } |
| 2460 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2461 | * If the new hba FCF record has lower priority value |
| 2462 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2463 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2464 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2465 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2466 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2467 | "2838 Update current FCF record " |
| 2468 | "(x%x) with new FCF record (x%x)\n", |
| 2469 | fcf_rec->fcf_indx, |
| 2470 | bf_get(lpfc_fcf_record_fcf_index, |
| 2471 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2472 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2473 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2474 | /* Reset running random FCF selection count */ |
| 2475 | phba->fcf.eligible_fcf_cnt = 1; |
| 2476 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2477 | /* Update running random FCF selection count */ |
| 2478 | phba->fcf.eligible_fcf_cnt++; |
| 2479 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2480 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2481 | if (select_new_fcf) { |
| 2482 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2483 | "2839 Update current FCF record " |
| 2484 | "(x%x) with new FCF record (x%x)\n", |
| 2485 | fcf_rec->fcf_indx, |
| 2486 | bf_get(lpfc_fcf_record_fcf_index, |
| 2487 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2488 | /* Choose the new FCF by random selection */ |
| 2489 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2490 | new_fcf_record, |
| 2491 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2492 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2493 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2494 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2495 | goto read_next_fcf; |
| 2496 | } |
| 2497 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2498 | * This is the first suitable FCF record, choose this record for |
| 2499 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2500 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2501 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2502 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2503 | "2840 Update initial FCF candidate " |
| 2504 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2505 | bf_get(lpfc_fcf_record_fcf_index, |
| 2506 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2507 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2508 | addr_mode, vlan_id, (boot_flag ? |
| 2509 | BOOT_ENABLE : 0)); |
| 2510 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2511 | /* Setup initial running random FCF selection count */ |
| 2512 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2513 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2514 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2515 | goto read_next_fcf; |
| 2516 | |
| 2517 | read_next_fcf: |
| 2518 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2519 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2520 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2521 | /* |
| 2522 | * Case of FCF fast failover scan |
| 2523 | */ |
| 2524 | |
| 2525 | /* |
| 2526 | * It has not found any suitable FCF record, cancel |
| 2527 | * FCF scan inprogress, and do nothing |
| 2528 | */ |
| 2529 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2530 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2531 | "2782 No suitable FCF found: " |
| 2532 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2533 | phba->fcoe_eventtag_at_fcf_scan, |
| 2534 | bf_get(lpfc_fcf_record_fcf_index, |
| 2535 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2536 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2537 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2538 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2539 | spin_unlock_irq(&phba->hbalock); |
| 2540 | /* Unregister in-use FCF and rescan */ |
| 2541 | lpfc_printf_log(phba, KERN_INFO, |
| 2542 | LOG_FIP, |
| 2543 | "2864 On devloss tmo " |
| 2544 | "unreg in-use FCF and " |
| 2545 | "rescan FCF table\n"); |
| 2546 | lpfc_unregister_fcf_rescan(phba); |
| 2547 | return; |
| 2548 | } |
| 2549 | /* |
| 2550 | * Let next new FCF event trigger fast failover |
| 2551 | */ |
| 2552 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2553 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2554 | return; |
| 2555 | } |
| 2556 | /* |
| 2557 | * It has found a suitable FCF record that is not |
| 2558 | * the same as in-use FCF record, unregister the |
| 2559 | * in-use FCF record, replace the in-use FCF record |
| 2560 | * with the new FCF record, mark FCF fast failover |
| 2561 | * completed, and then start register the new FCF |
| 2562 | * record. |
| 2563 | */ |
| 2564 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2565 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2566 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2567 | |
| 2568 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2569 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2570 | "2842 Replace in-use FCF (x%x) " |
| 2571 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2572 | phba->fcf.current_rec.fcf_indx, |
| 2573 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2574 | memcpy(&phba->fcf.current_rec, |
| 2575 | &phba->fcf.failover_rec, |
| 2576 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2577 | /* |
| 2578 | * Mark the fast FCF failover rediscovery completed |
| 2579 | * and the start of the first round of the roundrobin |
| 2580 | * FCF failover. |
| 2581 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2582 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2583 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2584 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2585 | /* Register to the new FCF record */ |
| 2586 | lpfc_register_fcf(phba); |
| 2587 | } else { |
| 2588 | /* |
| 2589 | * In case of transaction period to fast FCF failover, |
| 2590 | * do nothing when search to the end of the FCF table. |
| 2591 | */ |
| 2592 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2593 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2594 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2595 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2596 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2597 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2598 | /* |
| 2599 | * In case the current in-use FCF record no |
| 2600 | * longer existed during FCF discovery that |
| 2601 | * was not triggered by fast FCF failover |
| 2602 | * process, treat it as fast FCF failover. |
| 2603 | */ |
| 2604 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2605 | "2841 In-use FCF record (x%x) " |
| 2606 | "not reported, entering fast " |
| 2607 | "FCF failover mode scanning.\n", |
| 2608 | phba->fcf.current_rec.fcf_indx); |
| 2609 | spin_lock_irq(&phba->hbalock); |
| 2610 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2611 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2612 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2613 | LPFC_FCOE_FCF_GET_FIRST); |
| 2614 | return; |
| 2615 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2616 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2617 | lpfc_register_fcf(phba); |
| 2618 | } |
| 2619 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2620 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2621 | return; |
| 2622 | |
| 2623 | out: |
| 2624 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2625 | lpfc_register_fcf(phba); |
| 2626 | |
| 2627 | return; |
| 2628 | } |
| 2629 | |
| 2630 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2631 | * 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] | 2632 | * @phba: pointer to lpfc hba data structure. |
| 2633 | * @mboxq: pointer to mailbox object. |
| 2634 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2635 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2636 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2637 | * performing the failover. If the FCF read back is not valid/available, it |
| 2638 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2639 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2640 | * newly read FCF record to the failover FCF record, unregister currently |
| 2641 | * registered FCF record, copy the failover FCF record to the current |
| 2642 | * FCF record, and then register the current FCF record before proceeding |
| 2643 | * to trying FLOGI on the new failover FCF. |
| 2644 | */ |
| 2645 | void |
| 2646 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2647 | { |
| 2648 | struct fcf_record *new_fcf_record; |
| 2649 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2650 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2651 | uint16_t current_fcf_index; |
| 2652 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2653 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2654 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2655 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2656 | if (phba->link_state < LPFC_LINK_UP) { |
| 2657 | spin_lock_irq(&phba->hbalock); |
| 2658 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2659 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2660 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2661 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2665 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2666 | &next_fcf_index); |
| 2667 | if (!new_fcf_record) { |
| 2668 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2669 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2670 | "failed to retrieve a FCF record. " |
| 2671 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2672 | phba->fcf.fcf_flag); |
| 2673 | lpfc_unregister_fcf_rescan(phba); |
| 2674 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2678 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2679 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2680 | |
| 2681 | /* Log the FCF record information if turned on */ |
| 2682 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2683 | next_fcf_index); |
| 2684 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2685 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2686 | if (!rc) { |
| 2687 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2688 | "2848 Remove ineligible FCF (x%x) from " |
| 2689 | "from roundrobin bmask\n", fcf_index); |
| 2690 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2691 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2692 | /* Perform next round of roundrobin FCF failover */ |
| 2693 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2694 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2695 | if (rc) |
| 2696 | goto out; |
| 2697 | goto error_out; |
| 2698 | } |
| 2699 | |
| 2700 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2701 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2702 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2703 | "FCF (x%x) back to FCF (x%x)\n", |
| 2704 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2705 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2706 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2707 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2708 | goto out; |
| 2709 | } |
| 2710 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2711 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2712 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2713 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2714 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2715 | spin_lock_irq(&phba->hbalock); |
| 2716 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2717 | new_fcf_record, addr_mode, vlan_id, |
| 2718 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2719 | spin_unlock_irq(&phba->hbalock); |
| 2720 | |
| 2721 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2722 | |
| 2723 | /* Unregister the current in-use FCF record */ |
| 2724 | lpfc_unregister_fcf(phba); |
| 2725 | |
| 2726 | /* Replace in-use record with the new record */ |
| 2727 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2728 | sizeof(struct lpfc_fcf_rec)); |
| 2729 | |
| 2730 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2731 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2732 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2733 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2734 | error_out: |
| 2735 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2736 | out: |
| 2737 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | /** |
| 2741 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2742 | * @phba: pointer to lpfc hba data structure. |
| 2743 | * @mboxq: pointer to mailbox object. |
| 2744 | * |
| 2745 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2746 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2747 | * failover when a new FCF event happened. If the FCF read back is |
| 2748 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2749 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2750 | */ |
| 2751 | void |
| 2752 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2753 | { |
| 2754 | struct fcf_record *new_fcf_record; |
| 2755 | uint32_t boot_flag, addr_mode; |
| 2756 | uint16_t fcf_index, next_fcf_index; |
| 2757 | uint16_t vlan_id; |
| 2758 | int rc; |
| 2759 | |
| 2760 | /* If link state is not up, no need to proceed */ |
| 2761 | if (phba->link_state < LPFC_LINK_UP) |
| 2762 | goto out; |
| 2763 | |
| 2764 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2765 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2766 | goto out; |
| 2767 | |
| 2768 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2769 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2770 | &next_fcf_index); |
| 2771 | if (!new_fcf_record) { |
| 2772 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2773 | "2767 Mailbox command READ_FCF_RECORD " |
| 2774 | "failed to retrieve a FCF record.\n"); |
| 2775 | goto out; |
| 2776 | } |
| 2777 | |
| 2778 | /* Check the connection list for eligibility */ |
| 2779 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2780 | &addr_mode, &vlan_id); |
| 2781 | |
| 2782 | /* Log the FCF record information if turned on */ |
| 2783 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2784 | next_fcf_index); |
| 2785 | |
| 2786 | if (!rc) |
| 2787 | goto out; |
| 2788 | |
| 2789 | /* Update the eligible FCF record index bmask */ |
| 2790 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2791 | |
| 2792 | 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] | 2793 | |
| 2794 | out: |
| 2795 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2796 | } |
| 2797 | |
| 2798 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2799 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2800 | * @phba: pointer to lpfc hba data structure. |
| 2801 | * @mboxq: pointer to mailbox data structure. |
| 2802 | * |
| 2803 | * This function handles completion of init vfi mailbox command. |
| 2804 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2805 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2806 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2807 | { |
| 2808 | struct lpfc_vport *vport = mboxq->vport; |
| 2809 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2810 | /* |
| 2811 | * VFI not supported on interface type 0, just do the flogi |
| 2812 | * Also continue if the VFI is in use - just use the same one. |
| 2813 | */ |
| 2814 | if (mboxq->u.mb.mbxStatus && |
| 2815 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2816 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2817 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2818 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 2819 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2820 | mboxq->u.mb.mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2821 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2822 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2823 | return; |
| 2824 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2825 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2826 | lpfc_initial_flogi(vport); |
| 2827 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2828 | return; |
| 2829 | } |
| 2830 | |
| 2831 | /** |
| 2832 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2833 | * @vport: pointer to lpfc_vport data structure. |
| 2834 | * |
| 2835 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2836 | * VPI for the physical port. |
| 2837 | */ |
| 2838 | void |
| 2839 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2840 | { |
| 2841 | LPFC_MBOXQ_t *mboxq; |
| 2842 | int rc; |
| 2843 | struct lpfc_hba *phba = vport->phba; |
| 2844 | |
| 2845 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2846 | if (!mboxq) { |
| 2847 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2848 | LOG_TRACE_EVENT, "2892 Failed to allocate " |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2849 | "init_vfi mailbox\n"); |
| 2850 | return; |
| 2851 | } |
| 2852 | lpfc_init_vfi(mboxq, vport); |
| 2853 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2854 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2855 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2856 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 2857 | "2893 Failed to issue init_vfi mailbox\n"); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2858 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2863 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2864 | * @phba: pointer to lpfc hba data structure. |
| 2865 | * @mboxq: pointer to mailbox data structure. |
| 2866 | * |
| 2867 | * This function handles completion of init vpi mailbox command. |
| 2868 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2869 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2870 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2871 | { |
| 2872 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2873 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2874 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2875 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2876 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2877 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 2878 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2879 | mboxq->u.mb.mbxStatus); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2880 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2881 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2882 | return; |
| 2883 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2884 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2885 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2886 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2887 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2888 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2889 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2890 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2891 | if (!ndlp) |
| 2892 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2893 | LOG_TRACE_EVENT, |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2894 | "2731 Cannot find fabric " |
| 2895 | "controller node\n"); |
| 2896 | else |
| 2897 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2898 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2899 | return; |
| 2900 | } |
| 2901 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2902 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2903 | lpfc_initial_fdisc(vport); |
| 2904 | else { |
| 2905 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2906 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2907 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2908 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2909 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2910 | return; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2914 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2915 | * @vport: pointer to lpfc_vport data structure. |
| 2916 | * |
| 2917 | * This function issue a init_vpi mailbox command to initialize |
| 2918 | * VPI for the vport. |
| 2919 | */ |
| 2920 | void |
| 2921 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2922 | { |
| 2923 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2924 | int rc, vpi; |
| 2925 | |
| 2926 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2927 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2928 | if (!vpi) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2929 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2930 | "3303 Failed to obtain vport vpi\n"); |
| 2931 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2932 | return; |
| 2933 | } |
| 2934 | vport->vpi = vpi; |
| 2935 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2936 | |
| 2937 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2938 | if (!mboxq) { |
| 2939 | lpfc_printf_vlog(vport, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2940 | LOG_TRACE_EVENT, "2607 Failed to allocate " |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2941 | "init_vpi mailbox\n"); |
| 2942 | return; |
| 2943 | } |
| 2944 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2945 | mboxq->vport = vport; |
| 2946 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2947 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2948 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 2950 | "2608 Failed to issue init_vpi mailbox\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2951 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2956 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2957 | * @phba: pointer to lpfc hba data structure. |
| 2958 | * |
| 2959 | * This function loops through the list of vports on the @phba and issues an |
| 2960 | * FDISC if possible. |
| 2961 | */ |
| 2962 | void |
| 2963 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2964 | { |
| 2965 | struct lpfc_vport **vports; |
| 2966 | int i; |
| 2967 | |
| 2968 | vports = lpfc_create_vport_work_array(phba); |
| 2969 | if (vports != NULL) { |
| 2970 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2971 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2972 | continue; |
| 2973 | /* There are no vpi for this vport */ |
| 2974 | if (vports[i]->vpi > phba->max_vpi) { |
| 2975 | lpfc_vport_set_state(vports[i], |
| 2976 | FC_VPORT_FAILED); |
| 2977 | continue; |
| 2978 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2979 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2980 | lpfc_vport_set_state(vports[i], |
| 2981 | FC_VPORT_LINKDOWN); |
| 2982 | continue; |
| 2983 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2984 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2985 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2986 | continue; |
| 2987 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2988 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2989 | lpfc_initial_fdisc(vports[i]); |
| 2990 | else { |
| 2991 | lpfc_vport_set_state(vports[i], |
| 2992 | FC_VPORT_NO_FABRIC_SUPP); |
| 2993 | lpfc_printf_vlog(vports[i], KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2994 | LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2995 | "0259 No NPIV " |
| 2996 | "Fabric support\n"); |
| 2997 | } |
| 2998 | } |
| 2999 | } |
| 3000 | lpfc_destroy_vport_work_array(phba, vports); |
| 3001 | } |
| 3002 | |
| 3003 | void |
| 3004 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 3005 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3006 | struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3007 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3008 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3009 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 3010 | /* |
| 3011 | * VFI not supported for interface type 0, so ignore any mailbox |
| 3012 | * error (except VFI in use) and continue with the discovery. |
| 3013 | */ |
| 3014 | if (mboxq->u.mb.mbxStatus && |
| 3015 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3016 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 3017 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3018 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 3019 | "2018 REG_VFI mbxStatus error x%x " |
| 3020 | "HBA state x%x\n", |
| 3021 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3022 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3023 | /* FLOGI failed, use loop map to make discovery list */ |
| 3024 | lpfc_disc_list_loopmap(vport); |
| 3025 | /* Start discovery */ |
| 3026 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3027 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3028 | } |
| 3029 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3030 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3031 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3032 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3033 | /* If the VFI is already registered, there is nothing else to do |
| 3034 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 3035 | * we should drop through to set the port state to ready. |
| 3036 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3037 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3038 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 3039 | vport->fc_flag & FC_PT2PT)) |
| 3040 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 3041 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3042 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3043 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3044 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3045 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3046 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 3047 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3048 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3049 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3050 | /* In case SLI4 FC loopback test, we are ready */ |
| 3051 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 3052 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 3053 | phba->link_state = LPFC_HBA_READY; |
| 3054 | goto out_free_mem; |
| 3055 | } |
| 3056 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3057 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3058 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 3059 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 3060 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 3061 | vport->phba->alpa_map[0], |
| 3062 | phba->link_state, phba->fc_topology); |
| 3063 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3064 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 3065 | /* |
| 3066 | * For private loop or for NPort pt2pt, |
| 3067 | * just start discovery and we are done. |
| 3068 | */ |
| 3069 | if ((vport->fc_flag & FC_PT2PT) || |
| 3070 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 3071 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 3072 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3073 | /* Use loop map to make discovery list */ |
| 3074 | lpfc_disc_list_loopmap(vport); |
| 3075 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3076 | if (vport->fc_flag & FC_PT2PT) |
| 3077 | vport->port_state = LPFC_VPORT_READY; |
| 3078 | else |
| 3079 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3080 | } else { |
| 3081 | lpfc_start_fdiscs(phba); |
| 3082 | lpfc_do_scr_ns_plogi(phba, vport); |
| 3083 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3086 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3087 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3088 | if (dmabuf) { |
| 3089 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 3090 | kfree(dmabuf); |
| 3091 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3092 | return; |
| 3093 | } |
| 3094 | |
| 3095 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3098 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3099 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3100 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3101 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3102 | struct serv_parm *sp = &vport->fc_sparam; |
| 3103 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | |
| 3105 | /* Check for error */ |
| 3106 | if (mb->mbxStatus) { |
| 3107 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3108 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3109 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3110 | "hba state x%x>\n", |
| 3111 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | goto out; |
| 3114 | } |
| 3115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3118 | |
| 3119 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3120 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3121 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3122 | |
| 3123 | phba->fc_edtov = ed_tov; |
| 3124 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3125 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3126 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3127 | phba->fc_ratov = FF_DEF_RATOV; |
| 3128 | } |
| 3129 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3130 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3131 | 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] | 3132 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3133 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3134 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3135 | } |
| 3136 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3138 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3139 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 3140 | |
| 3141 | /* Check if sending the FLOGI is being deferred to after we get |
| 3142 | * up to date CSPs from MBX_READ_SPARAM. |
| 3143 | */ |
| 3144 | if (phba->hba_flag & HBA_DEFER_FLOGI) { |
| 3145 | lpfc_initial_flogi(vport); |
| 3146 | phba->hba_flag &= ~HBA_DEFER_FLOGI; |
| 3147 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | return; |
| 3149 | |
| 3150 | out: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3151 | pmb->ctx_buf = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3152 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3153 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3154 | lpfc_issue_clear_la(phba, vport); |
| 3155 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3156 | return; |
| 3157 | } |
| 3158 | |
| 3159 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3160 | 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] | 3161 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3163 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3164 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3165 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3166 | struct lpfc_dmabuf *mp; |
| 3167 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3168 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3169 | uint32_t fc_flags = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3170 | unsigned long iflags; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3171 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3172 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3173 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3174 | |
| 3175 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3176 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3177 | case LPFC_LINK_SPEED_1GHZ: |
| 3178 | case LPFC_LINK_SPEED_2GHZ: |
| 3179 | case LPFC_LINK_SPEED_4GHZ: |
| 3180 | case LPFC_LINK_SPEED_8GHZ: |
| 3181 | case LPFC_LINK_SPEED_10GHZ: |
| 3182 | case LPFC_LINK_SPEED_16GHZ: |
| 3183 | case LPFC_LINK_SPEED_32GHZ: |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 3184 | case LPFC_LINK_SPEED_64GHZ: |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 3185 | case LPFC_LINK_SPEED_128GHZ: |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3186 | break; |
| 3187 | default: |
| 3188 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3189 | break; |
| 3190 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | } |
| 3192 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3193 | if (phba->fc_topology && |
| 3194 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3195 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3196 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3197 | phba->fc_topology, |
| 3198 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3199 | phba->fc_topology_changed = 1; |
| 3200 | } |
| 3201 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3202 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 3203 | phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3204 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3205 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3206 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3207 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3208 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3209 | /* if npiv is enabled and this adapter supports npiv log |
| 3210 | * a message that npiv is not supported in this topology |
| 3211 | */ |
| 3212 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3213 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3214 | "1309 Link Up Event npiv not supported in loop " |
| 3215 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3216 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3217 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3218 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3219 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3220 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3221 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | |
| 3223 | if (i == 0) { |
| 3224 | phba->alpa_map[0] = 0; |
| 3225 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3226 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | int numalpa, j, k; |
| 3228 | union { |
| 3229 | uint8_t pamap[16]; |
| 3230 | struct { |
| 3231 | uint32_t wd1; |
| 3232 | uint32_t wd2; |
| 3233 | uint32_t wd3; |
| 3234 | uint32_t wd4; |
| 3235 | } pa; |
| 3236 | } un; |
| 3237 | numalpa = phba->alpa_map[0]; |
| 3238 | j = 0; |
| 3239 | while (j < numalpa) { |
| 3240 | memset(un.pamap, 0, 16); |
| 3241 | for (k = 1; j < numalpa; k++) { |
| 3242 | un.pamap[k - 1] = |
| 3243 | phba->alpa_map[j + 1]; |
| 3244 | j++; |
| 3245 | if (k == 16) |
| 3246 | break; |
| 3247 | } |
| 3248 | /* Link Up Event ALPA map */ |
| 3249 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3250 | KERN_WARNING, |
| 3251 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3252 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3253 | "ALPA map Data: x%x " |
| 3254 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3255 | un.pa.wd1, un.pa.wd2, |
| 3256 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3262 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3263 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3265 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3267 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3269 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3271 | if (fc_flags) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3272 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3273 | vport->fc_flag |= fc_flags; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3274 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3275 | } |
| 3276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | lpfc_linkup(phba); |
James Smart | 835214f | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 3278 | sparam_mbox = NULL; |
| 3279 | |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3280 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3281 | if (!sparam_mbox) |
| 3282 | goto out; |
| 3283 | |
| 3284 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3285 | if (rc) { |
| 3286 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3287 | goto out; |
| 3288 | } |
| 3289 | sparam_mbox->vport = vport; |
| 3290 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3291 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3292 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3293 | mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3294 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3295 | kfree(mp); |
| 3296 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3297 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | } |
| 3299 | |
James Smart | 7f04839 | 2020-09-11 13:01:47 -0700 | [diff] [blame] | 3300 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3301 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3302 | if (!cfglink_mbox) |
| 3303 | goto out; |
| 3304 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| 3305 | lpfc_config_link(phba, cfglink_mbox); |
| 3306 | cfglink_mbox->vport = vport; |
| 3307 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
| 3308 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
| 3309 | if (rc == MBX_NOT_FINISHED) { |
| 3310 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3311 | goto out; |
| 3312 | } |
| 3313 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3314 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3315 | /* |
| 3316 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3317 | * is phase 1 implementation that support FCF index 0 and driver |
| 3318 | * defaults. |
| 3319 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3320 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3321 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3322 | GFP_KERNEL); |
| 3323 | if (unlikely(!fcf_record)) { |
| 3324 | lpfc_printf_log(phba, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3325 | LOG_TRACE_EVENT, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3326 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3327 | "fcf record\n"); |
| 3328 | rc = -ENODEV; |
| 3329 | goto out; |
| 3330 | } |
| 3331 | |
| 3332 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3333 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3334 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3335 | if (unlikely(rc)) { |
| 3336 | lpfc_printf_log(phba, KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3337 | LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3338 | "2013 Could not manually add FCF " |
| 3339 | "record 0, status %d\n", rc); |
| 3340 | rc = -ENODEV; |
| 3341 | kfree(fcf_record); |
| 3342 | goto out; |
| 3343 | } |
| 3344 | kfree(fcf_record); |
| 3345 | } |
| 3346 | /* |
| 3347 | * The driver is expected to do FIP/FCF. Call the port |
| 3348 | * and get the FCF Table. |
| 3349 | */ |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3350 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3351 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3352 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3353 | return; |
| 3354 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3355 | /* This is the initial FCF discovery scan */ |
| 3356 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3357 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3358 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3359 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3360 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3361 | LPFC_FCOE_FCF_GET_FIRST); |
| 3362 | if (rc) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3363 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3364 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3365 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3366 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3367 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3368 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3369 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3371 | |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 3372 | /* Prepare for LINK up registrations */ |
| 3373 | memset(phba->os_host_name, 0, sizeof(phba->os_host_name)); |
| 3374 | scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s", |
| 3375 | init_utsname()->nodename); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3376 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3377 | out: |
| 3378 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3379 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 3380 | "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3381 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3382 | lpfc_issue_clear_la(phba, vport); |
| 3383 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3387 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3389 | uint32_t control; |
| 3390 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3393 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3394 | control = readl(phba->HCregaddr); |
| 3395 | control |= HC_LAINT_ENA; |
| 3396 | writel(control, phba->HCregaddr); |
| 3397 | readl(phba->HCregaddr); /* flush */ |
| 3398 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | } |
| 3401 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3402 | static void |
| 3403 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3404 | { |
| 3405 | lpfc_linkdown(phba); |
| 3406 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3407 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3408 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3409 | } |
| 3410 | |
| 3411 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3413 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3415 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3416 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | */ |
| 3418 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3419 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3421 | struct lpfc_vport *vport = pmb->vport; |
| 3422 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3423 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3424 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3425 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3426 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3427 | uint8_t attn_type; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3428 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3430 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3431 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 3432 | if (pring) |
| 3433 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3434 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | /* Check for error */ |
| 3436 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3437 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3438 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3439 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3442 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | } |
| 3444 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3445 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3446 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | |
| 3448 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3449 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3450 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3451 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3452 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3453 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3454 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3455 | spin_unlock_irqrestore(shost->host_lock, iflags); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3456 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3457 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3459 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | if (phba->fc_eventTag != 0) |
| 3461 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | |
| 3464 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3465 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3466 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3467 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3468 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3469 | else |
| 3470 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3471 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3474 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3475 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3476 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3478 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3479 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3480 | "1306 Link Up Event in loop back mode " |
| 3481 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3482 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3483 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3484 | la), |
| 3485 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3486 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3487 | } else { |
| 3488 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3489 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3490 | "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] | 3491 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3492 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3493 | la), |
| 3494 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3495 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3496 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3497 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3498 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3499 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3500 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3501 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3502 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3504 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3505 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3506 | "1308 Link Down Event in loop back mode " |
| 3507 | "x%x received " |
| 3508 | "Data: x%x x%x x%x\n", |
| 3509 | la->eventTag, phba->fc_eventTag, |
| 3510 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3511 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3512 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | b9da814 | 2019-11-04 16:57:04 -0800 | [diff] [blame] | 3513 | "1313 Link Down Unexpected FA WWPN Event x%x " |
| 3514 | "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] | 3515 | la->eventTag, phba->fc_eventTag, |
| 3516 | phba->pport->port_state, vport->fc_flag, |
| 3517 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3518 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3519 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3520 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3521 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3522 | "Data: x%x x%x x%x x%x x%x\n", |
| 3523 | la->eventTag, phba->fc_eventTag, |
| 3524 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3525 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3526 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3527 | lpfc_mbx_issue_link_down(phba); |
| 3528 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3529 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3530 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3531 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3532 | phba->fc_stat.LinkDown++; |
| 3533 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3534 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3536 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3538 | lpfc_mbx_issue_link_down(phba); |
| 3539 | } else |
| 3540 | lpfc_enable_la(phba); |
| 3541 | |
| 3542 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3543 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3544 | "Data: x%x x%x x%x\n", |
| 3545 | la->eventTag, phba->fc_eventTag, |
| 3546 | phba->pport->port_state, vport->fc_flag); |
| 3547 | /* |
| 3548 | * The cmnd that triggered this will be waiting for this |
| 3549 | * signal. |
| 3550 | */ |
| 3551 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3552 | if (phba->wait_4_mlo_maint_flg) { |
| 3553 | phba->wait_4_mlo_maint_flg = 0; |
| 3554 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3555 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3556 | } |
| 3557 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3558 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3559 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3560 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3561 | lpfc_issue_clear_la(phba, vport); |
| 3562 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3563 | "1311 fa %d\n", |
| 3564 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3565 | } |
| 3566 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3567 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3569 | kfree(mp); |
| 3570 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3571 | return; |
| 3572 | } |
| 3573 | |
| 3574 | /* |
| 3575 | * This routine handles processing a REG_LOGIN mailbox |
| 3576 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3577 | * as the completion routine when the command is |
| 3578 | * handed off to the SLI layer. |
| 3579 | */ |
| 3580 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3581 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3583 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3584 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 3585 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3587 | pmb->ctx_buf = NULL; |
| 3588 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 3590 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3591 | "0002 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3592 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3593 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3594 | ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3595 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3596 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3597 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3598 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3599 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3600 | /* We rcvd a rscn after issuing this |
| 3601 | * mbox reg login, we may have cycled |
| 3602 | * back through the state and be |
| 3603 | * back at reg login state so this |
| 3604 | * mbox needs to be ignored becase |
| 3605 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3606 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3607 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3608 | spin_lock_irq(&ndlp->lock); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3609 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3610 | spin_unlock_irq(&ndlp->lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3611 | |
| 3612 | /* |
| 3613 | * We cannot leave the RPI registered because |
| 3614 | * if we go thru discovery again for this ndlp |
| 3615 | * a subsequent REG_RPI will fail. |
| 3616 | */ |
| 3617 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3618 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | /* Call state machine */ |
| 3622 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3625 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3627 | /* decrement the node reference count held for this callback |
| 3628 | * function. |
| 3629 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3630 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | |
| 3632 | return; |
| 3633 | } |
| 3634 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3635 | static void |
| 3636 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3637 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3638 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3639 | struct lpfc_vport *vport = pmb->vport; |
| 3640 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3641 | |
| 3642 | switch (mb->mbxStatus) { |
| 3643 | case 0x0011: |
| 3644 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3645 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3646 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3647 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3648 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3649 | /* If VPI is busy, reset the HBA */ |
| 3650 | case 0x9700: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3651 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3652 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3653 | vport->vpi, mb->mbxStatus); |
| 3654 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3655 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3656 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3657 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3658 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3659 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3660 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3661 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3662 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3663 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3664 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3665 | /* |
| 3666 | * This shost reference might have been taken at the beginning of |
| 3667 | * lpfc_vport_delete() |
| 3668 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3669 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3670 | scsi_host_put(shost); |
| 3671 | } |
| 3672 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3673 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3674 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3675 | { |
| 3676 | struct lpfc_hba *phba = vport->phba; |
| 3677 | LPFC_MBOXQ_t *mbox; |
| 3678 | int rc; |
| 3679 | |
| 3680 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3681 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3682 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3683 | |
| 3684 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3685 | mbox->vport = vport; |
| 3686 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3687 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3688 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3689 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3690 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3691 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3692 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3693 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3694 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3695 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | static void |
| 3699 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3700 | { |
| 3701 | struct lpfc_vport *vport = pmb->vport; |
| 3702 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3703 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3704 | |
| 3705 | switch (mb->mbxStatus) { |
| 3706 | case 0x0011: |
| 3707 | case 0x9601: |
| 3708 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3709 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3710 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3711 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3712 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3713 | spin_lock_irq(shost->host_lock); |
| 3714 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3715 | spin_unlock_irq(shost->host_lock); |
| 3716 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3717 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3718 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3719 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3720 | if (phba->nvmet_support) |
| 3721 | lpfc_nvmet_update_targetport(phba); |
| 3722 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3723 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3724 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3725 | goto out; |
| 3726 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3727 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3728 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3729 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3730 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3731 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3732 | vport->num_disc_nodes = 0; |
| 3733 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3734 | if (vport->fc_npr_cnt) |
| 3735 | lpfc_els_disc_plogi(vport); |
| 3736 | |
| 3737 | if (!vport->num_disc_nodes) { |
| 3738 | spin_lock_irq(shost->host_lock); |
| 3739 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3740 | spin_unlock_irq(shost->host_lock); |
| 3741 | lpfc_can_disctmo(vport); |
| 3742 | } |
| 3743 | vport->port_state = LPFC_VPORT_READY; |
| 3744 | |
| 3745 | out: |
| 3746 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3747 | return; |
| 3748 | } |
| 3749 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3750 | /** |
| 3751 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3752 | * @phba: pointer to lpfc hba data structure. |
| 3753 | * |
| 3754 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3755 | * the list of static vports to be created. The function create vports |
| 3756 | * based on the information returned from the HBA. |
| 3757 | **/ |
| 3758 | void |
| 3759 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3760 | { |
| 3761 | LPFC_MBOXQ_t *pmb = NULL; |
| 3762 | MAILBOX_t *mb; |
| 3763 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3764 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3765 | struct fc_vport_identifiers vport_id; |
| 3766 | struct fc_vport *new_fc_vport; |
| 3767 | struct Scsi_Host *shost; |
| 3768 | struct lpfc_vport *vport; |
| 3769 | uint16_t offset = 0; |
| 3770 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3771 | struct lpfc_dmabuf *mp; |
| 3772 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3773 | |
| 3774 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3775 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3776 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3777 | "0542 lpfc_create_static_vport failed to" |
| 3778 | " allocate mailbox memory\n"); |
| 3779 | return; |
| 3780 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3781 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3782 | mb = &pmb->u.mb; |
| 3783 | |
| 3784 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3785 | if (!vport_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3786 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3787 | "0543 lpfc_create_static_vport failed to" |
| 3788 | " allocate vport_info\n"); |
| 3789 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3790 | return; |
| 3791 | } |
| 3792 | |
| 3793 | vport_buff = (uint8_t *) vport_info; |
| 3794 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3795 | /* free dma buffer from previous round */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3796 | if (pmb->ctx_buf) { |
| 3797 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3798 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3799 | kfree(mp); |
| 3800 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3801 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3802 | goto out; |
| 3803 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3804 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3805 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3806 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3807 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3808 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3809 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3810 | "0544 lpfc_create_static_vport failed to" |
| 3811 | " issue dump mailbox command ret 0x%x " |
| 3812 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3813 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3814 | goto out; |
| 3815 | } |
| 3816 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3817 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3818 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3819 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3820 | if (byte_count > sizeof(struct static_vport_info) - |
| 3821 | offset) |
| 3822 | byte_count = sizeof(struct static_vport_info) |
| 3823 | - offset; |
| 3824 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3825 | offset += byte_count; |
| 3826 | } else { |
| 3827 | if (mb->un.varDmp.word_cnt > |
| 3828 | sizeof(struct static_vport_info) - offset) |
| 3829 | mb->un.varDmp.word_cnt = |
| 3830 | sizeof(struct static_vport_info) |
| 3831 | - offset; |
| 3832 | byte_count = mb->un.varDmp.word_cnt; |
| 3833 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3834 | vport_buff + offset, |
| 3835 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3836 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3837 | offset += byte_count; |
| 3838 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3839 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3840 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3841 | offset < sizeof(struct static_vport_info)); |
| 3842 | |
| 3843 | |
| 3844 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3845 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3846 | != VPORT_INFO_REV)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3847 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3848 | "0545 lpfc_create_static_vport bad" |
| 3849 | " information header 0x%x 0x%x\n", |
| 3850 | le32_to_cpu(vport_info->signature), |
| 3851 | le32_to_cpu(vport_info->rev) & |
| 3852 | VPORT_INFO_REV_MASK); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3853 | |
| 3854 | goto out; |
| 3855 | } |
| 3856 | |
| 3857 | shost = lpfc_shost_from_vport(phba->pport); |
| 3858 | |
| 3859 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3860 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3861 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3862 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3863 | if (!vport_id.port_name || !vport_id.node_name) |
| 3864 | continue; |
| 3865 | |
| 3866 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3867 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3868 | vport_id.disable = false; |
| 3869 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3870 | |
| 3871 | if (!new_fc_vport) { |
| 3872 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3873 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3874 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3875 | continue; |
| 3876 | } |
| 3877 | |
| 3878 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3879 | vport->vport_flag |= STATIC_VPORT; |
| 3880 | } |
| 3881 | |
| 3882 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3883 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3884 | if (mbx_wait_rc != MBX_TIMEOUT) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3885 | if (pmb->ctx_buf) { |
| 3886 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3887 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3888 | kfree(mp); |
| 3889 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3890 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3891 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3892 | |
| 3893 | return; |
| 3894 | } |
| 3895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | /* |
| 3897 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3898 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3899 | * as the completion routine when the command is |
| 3900 | * handed off to the SLI layer. |
| 3901 | */ |
| 3902 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3903 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3905 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3906 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3907 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3908 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3909 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3910 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3911 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 3912 | pmb->ctx_ndlp = NULL; |
| 3913 | pmb->ctx_buf = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3914 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3916 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3917 | "0258 Register Fabric login error: 0x%x\n", |
| 3918 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3920 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3921 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3923 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3924 | /* FLOGI failed, use loop map to make discovery list */ |
| 3925 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3927 | /* Start discovery */ |
| 3928 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3929 | /* Decrement the reference count to ndlp after the |
| 3930 | * reference to the ndlp are done. |
| 3931 | */ |
| 3932 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3933 | return; |
| 3934 | } |
| 3935 | |
| 3936 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3937 | /* Decrement the reference count to ndlp after the reference |
| 3938 | * to the ndlp are done. |
| 3939 | */ |
| 3940 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | return; |
| 3942 | } |
| 3943 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3944 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3945 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3946 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3947 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3948 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3951 | /* when physical port receive logo donot start |
| 3952 | * vport discovery */ |
| 3953 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3954 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3955 | else { |
| 3956 | shost = lpfc_shost_from_vport(vport); |
| 3957 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3958 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3959 | spin_unlock_irq(shost->host_lock); |
| 3960 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3961 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3965 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3966 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3967 | |
| 3968 | /* Drop the reference count from the mbox at the end after |
| 3969 | * all the current reference to the ndlp have been done. |
| 3970 | */ |
| 3971 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | return; |
| 3973 | } |
| 3974 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3975 | /* |
| 3976 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3977 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3978 | */ |
| 3979 | int |
| 3980 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3981 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3982 | /* Good status, issue CT Request to NameServer */ |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3983 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3984 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3985 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3986 | /* Cannot issue NameServer FCP Query, so finish up |
| 3987 | * discovery |
| 3988 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3989 | lpfc_printf_vlog(vport, KERN_ERR, |
| 3990 | LOG_TRACE_EVENT, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3991 | "0604 %s FC TYPE %x %s\n", |
| 3992 | "Failed to issue GID_FT to ", |
| 3993 | FC_TYPE_FCP, |
| 3994 | "Finishing discovery."); |
| 3995 | return 0; |
| 3996 | } |
| 3997 | vport->gidft_inp++; |
| 3998 | } |
| 3999 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4000 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4001 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4002 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 4003 | /* Cannot issue NameServer NVME Query, so finish up |
| 4004 | * discovery |
| 4005 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4006 | lpfc_printf_vlog(vport, KERN_ERR, |
| 4007 | LOG_TRACE_EVENT, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4008 | "0605 %s FC_TYPE %x %s %d\n", |
| 4009 | "Failed to issue GID_FT to ", |
| 4010 | FC_TYPE_NVME, |
| 4011 | "Finishing discovery: gidftinp ", |
| 4012 | vport->gidft_inp); |
| 4013 | if (vport->gidft_inp == 0) |
| 4014 | return 0; |
| 4015 | } else |
| 4016 | vport->gidft_inp++; |
| 4017 | } |
| 4018 | return vport->gidft_inp; |
| 4019 | } |
| 4020 | |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 4021 | /** |
| 4022 | * lpfc_issue_gidpt - issue a GID_PT for all N_Ports |
| 4023 | * @vport: The virtual port for which this call is being executed. |
| 4024 | * |
| 4025 | * This routine will issue a GID_PT to get a list of all N_Ports |
| 4026 | * |
| 4027 | * Return value : |
| 4028 | * 0 - Failure to issue a GID_PT |
| 4029 | * 1 - GID_PT issued |
| 4030 | **/ |
| 4031 | int |
| 4032 | lpfc_issue_gidpt(struct lpfc_vport *vport) |
| 4033 | { |
| 4034 | /* Good status, issue CT Request to NameServer */ |
| 4035 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) { |
| 4036 | /* Cannot issue NameServer FCP Query, so finish up |
| 4037 | * discovery |
| 4038 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4039 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 4040 | "0606 %s Port TYPE %x %s\n", |
| 4041 | "Failed to issue GID_PT to ", |
| 4042 | GID_PT_N_PORT, |
| 4043 | "Finishing discovery."); |
| 4044 | return 0; |
| 4045 | } |
| 4046 | vport->gidft_inp++; |
| 4047 | return 1; |
| 4048 | } |
| 4049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | /* |
| 4051 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 4052 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4053 | * as the completion routine when the command is |
| 4054 | * handed off to the SLI layer. |
| 4055 | */ |
| 4056 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4059 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4060 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4061 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4062 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4064 | pmb->ctx_buf = NULL; |
| 4065 | pmb->ctx_ndlp = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4066 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4067 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | if (mb->mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4069 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4070 | "0260 Register NameServer error: 0x%x\n", |
| 4071 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4072 | |
| 4073 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4074 | /* decrement the node reference count held for this |
| 4075 | * callback function. |
| 4076 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4077 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4079 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4080 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4081 | |
James Smart | 52edb2c | 2020-11-15 11:26:35 -0800 | [diff] [blame] | 4082 | /* If the node is not registered with the scsi or nvme |
| 4083 | * transport, remove the fabric node. The failed reg_login |
| 4084 | * is terminal. |
| 4085 | */ |
| 4086 | if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { |
| 4087 | spin_lock_irq(&ndlp->lock); |
| 4088 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 4089 | spin_unlock_irq(&ndlp->lock); |
| 4090 | lpfc_nlp_not_used(ndlp); |
| 4091 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4093 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4094 | /* |
| 4095 | * RegLogin failed, use loop map to make discovery |
| 4096 | * list |
| 4097 | */ |
| 4098 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4100 | /* Start discovery */ |
| 4101 | lpfc_disc_start(vport); |
| 4102 | return; |
| 4103 | } |
| 4104 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | return; |
| 4106 | } |
| 4107 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4108 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4109 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4110 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4111 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4112 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4113 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4114 | "0003 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4115 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4116 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4117 | ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4119 | if (vport->port_state < LPFC_VPORT_READY) { |
| 4120 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4121 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 4122 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 4123 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 4124 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4125 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4126 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4127 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4128 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 4129 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4130 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4131 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4132 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 4133 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4134 | |
| 4135 | /* Issue SCR just before NameServer GID_FT Query */ |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 4136 | lpfc_issue_els_scr(vport, 0); |
| 4137 | |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 4138 | if (!phba->cfg_enable_mi || |
| 4139 | phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT) |
| 4140 | lpfc_issue_els_rdf(vport, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | } |
| 4142 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4143 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4144 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4145 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4147 | /* |
| 4148 | * At this point in time we may need to wait for multiple |
| 4149 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 4150 | * |
| 4151 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4152 | * callback function. |
| 4153 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4154 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4156 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | |
| 4159 | return; |
| 4160 | } |
| 4161 | |
James Smart | fe83e3b | 2021-05-14 12:55:54 -0700 | [diff] [blame^] | 4162 | /* |
| 4163 | * This routine handles processing a Fabric Controller REG_LOGIN mailbox |
| 4164 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4165 | * as the completion routine when the command is handed off to the SLI layer. |
| 4166 | */ |
| 4167 | void |
| 4168 | lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4169 | { |
| 4170 | struct lpfc_vport *vport = pmb->vport; |
| 4171 | MAILBOX_t *mb = &pmb->u.mb; |
| 4172 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4173 | struct lpfc_nodelist *ndlp; |
| 4174 | |
| 4175 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 4176 | pmb->ctx_ndlp = NULL; |
| 4177 | pmb->ctx_buf = NULL; |
| 4178 | |
| 4179 | if (mb->mbxStatus) { |
| 4180 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 4181 | "0933 %s: Register FC login error: 0x%x\n", |
| 4182 | __func__, mb->mbxStatus); |
| 4183 | goto out; |
| 4184 | } |
| 4185 | |
| 4186 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4187 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| 4188 | |
| 4189 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4190 | "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n", |
| 4191 | __func__, ndlp->nlp_DID, ndlp->nlp_rpi, |
| 4192 | ndlp->nlp_state); |
| 4193 | |
| 4194 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 4195 | ndlp->nlp_type |= NLP_FABRIC; |
| 4196 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| 4197 | |
| 4198 | out: |
| 4199 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4200 | kfree(mp); |
| 4201 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4202 | |
| 4203 | /* Drop the reference count from the mbox at the end after |
| 4204 | * all the current reference to the ndlp have been done. |
| 4205 | */ |
| 4206 | lpfc_nlp_put(ndlp); |
| 4207 | } |
| 4208 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4210 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4213 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | struct lpfc_rport_data *rdata; |
| 4215 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | struct lpfc_hba *phba = vport->phba; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4217 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4219 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4220 | return; |
| 4221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4223 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4224 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | rport_ids.port_id = ndlp->nlp_DID; |
| 4226 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4228 | |
| 4229 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4230 | "rport add: did:x%x flg:x%x type x%x", |
| 4231 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4232 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4233 | /* Don't add the remote port if unloading. */ |
| 4234 | if (vport->load_flag & FC_UNLOADING) |
| 4235 | return; |
| 4236 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4237 | /* |
| 4238 | * Disassociate any older association between this ndlp and rport |
| 4239 | */ |
| 4240 | if (ndlp->rport) { |
| 4241 | rdata = ndlp->rport->dd_data; |
| 4242 | rdata->pnode = NULL; |
| 4243 | } |
| 4244 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 4246 | if (!rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4248 | "Warning: fc_remote_port_add failed\n"); |
| 4249 | return; |
| 4250 | } |
| 4251 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4252 | /* Successful port add. Complete initializing node data */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4254 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4256 | rdata->pnode = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 4257 | if (!rdata->pnode) { |
| 4258 | dev_warn(&phba->pcidev->dev, |
| 4259 | "Warning - node ref failed. Unreg rport\n"); |
| 4260 | fc_remote_port_delete(rport); |
| 4261 | ndlp->rport = NULL; |
| 4262 | return; |
| 4263 | } |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4264 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4265 | spin_lock_irqsave(&ndlp->lock, flags); |
| 4266 | ndlp->fc4_xpt_flags |= SCSI_XPT_REGD; |
| 4267 | spin_unlock_irqrestore(&ndlp->lock, flags); |
| 4268 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4269 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4270 | rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4271 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4272 | rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; |
| 4273 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) |
| 4274 | rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; |
| 4275 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4276 | rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; |
| 4277 | if (ndlp->nlp_type & NLP_NVME_DISCOVERY) |
| 4278 | rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4279 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4280 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4281 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4282 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4283 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4284 | "3183 %s rport x%px DID x%x, role x%x\n", |
| 4285 | __func__, rport, rport->port_id, rport->roles); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4286 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4287 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4288 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4289 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4290 | } |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 4291 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4292 | return; |
| 4293 | } |
| 4294 | |
| 4295 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4296 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4297 | { |
| 4298 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4299 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4300 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4301 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4302 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4303 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4304 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4305 | "rport delete: did:x%x flg:x%x type x%x", |
| 4306 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4307 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4308 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4309 | "3184 rport unregister x%06x, rport x%px " |
| 4310 | "xptflg x%x\n", |
| 4311 | ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4312 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4313 | fc_remote_port_delete(rport); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4314 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | } |
| 4316 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4317 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4319 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4321 | unsigned long iflags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4323 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4324 | switch (state) { |
| 4325 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4326 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4327 | break; |
| 4328 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4329 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4330 | break; |
| 4331 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4333 | break; |
| 4334 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4335 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4336 | break; |
| 4337 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4338 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4339 | break; |
| 4340 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4342 | break; |
| 4343 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4345 | break; |
| 4346 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4347 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4348 | vport->fc_npr_cnt = 0; |
| 4349 | else |
| 4350 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4351 | break; |
| 4352 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4353 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4354 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4355 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4356 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4358 | int old_state, int new_state) |
| 4359 | { |
| 4360 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4361 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4362 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4363 | } |
| 4364 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4365 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4366 | if (new_state == NLP_STE_NPR_NODE) |
| 4367 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4369 | /* FCP and NVME Transport interface */ |
| 4370 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4371 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 4372 | if (ndlp->rport && |
| 4373 | lpfc_valid_xpt_node(ndlp)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4374 | vport->phba->nport_event_cnt++; |
| 4375 | lpfc_unregister_remote_port(ndlp); |
| 4376 | } |
| 4377 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4378 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4379 | vport->phba->nport_event_cnt++; |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4380 | if (vport->phba->nvmet_support == 0) { |
| 4381 | /* Start devloss if target. */ |
| 4382 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4383 | lpfc_nvme_unregister_port(vport, ndlp); |
| 4384 | } else { |
James Smart | 6599e12 | 2017-06-01 21:07:00 -0700 | [diff] [blame] | 4385 | /* NVMET has no upcall. */ |
| 4386 | lpfc_nlp_put(ndlp); |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4387 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4388 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4389 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4390 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4391 | /* FCP and NVME Transport interfaces */ |
| 4392 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4393 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4394 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 07aaefd | 2021-01-04 10:02:29 -0800 | [diff] [blame] | 4395 | if (lpfc_valid_xpt_node(ndlp)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4396 | vport->phba->nport_event_cnt++; |
| 4397 | /* |
| 4398 | * Tell the fc transport about the port, if we haven't |
| 4399 | * already. If we have, and it's a scsi entity, be |
| 4400 | */ |
| 4401 | lpfc_register_remote_port(vport, ndlp); |
| 4402 | } |
| 4403 | /* Notify the NVME transport of this new rport. */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 4404 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
| 4405 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4406 | if (vport->phba->nvmet_support == 0) { |
| 4407 | /* Register this rport with the transport. |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4408 | * Only NVME Target Rports are registered with |
| 4409 | * the transport. |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4410 | */ |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4411 | if (ndlp->nlp_type & NLP_NVME_TARGET) { |
| 4412 | vport->phba->nport_event_cnt++; |
| 4413 | lpfc_nvme_register_port(vport, ndlp); |
| 4414 | } |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4415 | } else { |
| 4416 | /* Just take an NDLP ref count since the |
| 4417 | * target does not register rports. |
| 4418 | */ |
| 4419 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4420 | } |
| 4421 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4422 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4423 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4424 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4425 | (vport->stat_data_enabled)) { |
| 4426 | /* |
| 4427 | * A new target is discovered, if there is no buffer for |
| 4428 | * statistical data collection allocate buffer. |
| 4429 | */ |
| 4430 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4431 | sizeof(struct lpfc_scsicmd_bkt), |
| 4432 | GFP_KERNEL); |
| 4433 | |
| 4434 | if (!ndlp->lat_data) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4435 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4436 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4437 | "allocate statistical data buffer DID " |
| 4438 | "0x%x\n", ndlp->nlp_DID); |
| 4439 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4440 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4441 | * If the node just added to Mapped list was an FCP target, |
| 4442 | * but the remote port registration failed or assigned a target |
| 4443 | * id outside the presentable range - move the node to the |
| 4444 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4445 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4446 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4447 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4448 | (!ndlp->rport || |
| 4449 | ndlp->rport->scsi_target_id == -1 || |
| 4450 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4451 | spin_lock_irq(&ndlp->lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4452 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4453 | spin_unlock_irq(&ndlp->lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4456 | } |
| 4457 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4458 | static char * |
| 4459 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4460 | { |
| 4461 | static char *states[] = { |
| 4462 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4463 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4464 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4465 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4466 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4467 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4468 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4469 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4470 | [NLP_STE_NPR_NODE] = "NPR", |
| 4471 | }; |
| 4472 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4473 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4474 | strlcpy(buffer, states[state], size); |
| 4475 | else |
| 4476 | snprintf(buffer, size, "unknown (%d)", state); |
| 4477 | return buffer; |
| 4478 | } |
| 4479 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4480 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4482 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4483 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4484 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4485 | int old_state = ndlp->nlp_state; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4486 | int node_dropped = ndlp->nlp_flag & NLP_DROPPED; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4487 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4488 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4489 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4490 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4491 | ndlp->nlp_DID, |
| 4492 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4493 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4494 | |
| 4495 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4496 | "node statechg did:x%x old:%d ste:%d", |
| 4497 | ndlp->nlp_DID, old_state, state); |
| 4498 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4499 | if (node_dropped && old_state == NLP_STE_UNUSED_NODE && |
| 4500 | state != NLP_STE_UNUSED_NODE) { |
| 4501 | ndlp->nlp_flag &= ~NLP_DROPPED; |
| 4502 | lpfc_nlp_get(ndlp); |
| 4503 | } |
| 4504 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4505 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4506 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4507 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4508 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4509 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4510 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4511 | } |
| 4512 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4513 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | spin_lock_irq(shost->host_lock); |
| 4515 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4516 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4517 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4518 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4519 | |
| 4520 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4521 | lpfc_nlp_counters(vport, state, 1); |
| 4522 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4526 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4527 | { |
| 4528 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4529 | |
| 4530 | if (list_empty(&ndlp->nlp_listp)) { |
| 4531 | spin_lock_irq(shost->host_lock); |
| 4532 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4533 | spin_unlock_irq(shost->host_lock); |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4539 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4541 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4542 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4543 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4544 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4545 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4546 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4547 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4548 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4549 | NLP_STE_UNUSED_NODE); |
| 4550 | } |
| 4551 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4552 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4553 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4554 | * @vport: Pointer to Virtual Port object. |
| 4555 | * @ndlp: Pointer to FC node object. |
| 4556 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4557 | * |
| 4558 | * This function is always called when node object need to be initialized. |
| 4559 | * It initializes all the fields of the node object. Although the reference |
| 4560 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4561 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4562 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4563 | * the final release of ndlp is determined by its reference count. And, the |
| 4564 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4565 | **/ |
| 4566 | static inline void |
| 4567 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4568 | uint32_t did) |
| 4569 | { |
| 4570 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4571 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4572 | timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 4573 | INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp); |
| 4574 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4575 | ndlp->nlp_DID = did; |
| 4576 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4577 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4578 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4579 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4580 | kref_init(&ndlp->kref); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4581 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4582 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4583 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4584 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4585 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4586 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4588 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4589 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4590 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4591 | * 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] | 4592 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4593 | * until ALL other outstanding threads have completed. We check |
| 4594 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4595 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4596 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4597 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4598 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4599 | ndlp->nlp_flag |= NLP_DROPPED; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4600 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4601 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4602 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4603 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4604 | |
| 4605 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4606 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | /* |
| 4610 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4611 | */ |
| 4612 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4616 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | uint32_t tmo; |
| 4618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4620 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4621 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4622 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4623 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4624 | * FC spec states we need 3 * ratov for CT requests |
| 4625 | */ |
| 4626 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4627 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4629 | |
| 4630 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4631 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4632 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4633 | tmo, vport->port_state, vport->fc_flag); |
| 4634 | } |
| 4635 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4636 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4637 | spin_lock_irq(shost->host_lock); |
| 4638 | vport->fc_flag |= FC_DISC_TMO; |
| 4639 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4640 | |
| 4641 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4642 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4643 | "0247 Start Discovery Timer state x%x " |
| 4644 | "Data: x%x x%lx x%x x%x\n", |
| 4645 | vport->port_state, tmo, |
| 4646 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4647 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | |
| 4649 | return; |
| 4650 | } |
| 4651 | |
| 4652 | /* |
| 4653 | * Cancel rescue timer for Discovery / RSCN handling |
| 4654 | */ |
| 4655 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4656 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4658 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4659 | unsigned long iflags; |
| 4660 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4662 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4663 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4666 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4667 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4668 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4669 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4670 | del_timer_sync(&vport->fc_disctmo); |
| 4671 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4672 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4673 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4677 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4678 | "0248 Cancel Discovery Timer state x%x " |
| 4679 | "Data: x%x x%x x%x\n", |
| 4680 | vport->port_state, vport->fc_flag, |
| 4681 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4682 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | /* |
| 4686 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4687 | * Return true if iocb matches the specified nport |
| 4688 | */ |
| 4689 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4691 | struct lpfc_sli_ring *pring, |
| 4692 | struct lpfc_iocbq *iocb, |
| 4693 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4695 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4696 | struct lpfc_vport *vport = ndlp->vport; |
| 4697 | |
| 4698 | if (iocb->vport != vport) |
| 4699 | return 0; |
| 4700 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4701 | if (pring->ringno == LPFC_ELS_RING) { |
| 4702 | switch (icmd->ulpCommand) { |
| 4703 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4704 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4705 | return 1; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4706 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4708 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4709 | return 1; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4710 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | case CMD_XMIT_ELS_RSP64_CX: |
| 4712 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4713 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4715 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4716 | /* Skip match check if waiting to relogin to FCP target */ |
| 4717 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4718 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4719 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | } |
| 4721 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4722 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4723 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4725 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | } |
| 4727 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4728 | static void |
| 4729 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4730 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4731 | struct list_head *dequeue_list) |
| 4732 | { |
| 4733 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4734 | |
| 4735 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4736 | /* Check to see if iocb matches the nport */ |
| 4737 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4738 | /* match, dequeue */ |
| 4739 | list_move_tail(&iocb->list, dequeue_list); |
| 4740 | } |
| 4741 | } |
| 4742 | |
| 4743 | static void |
| 4744 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4745 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4746 | { |
| 4747 | struct lpfc_sli *psli = &phba->sli; |
| 4748 | uint32_t i; |
| 4749 | |
| 4750 | spin_lock_irq(&phba->hbalock); |
| 4751 | for (i = 0; i < psli->num_rings; i++) |
| 4752 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4753 | dequeue_list); |
| 4754 | spin_unlock_irq(&phba->hbalock); |
| 4755 | } |
| 4756 | |
| 4757 | static void |
| 4758 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4759 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4760 | { |
| 4761 | struct lpfc_sli_ring *pring; |
| 4762 | struct lpfc_queue *qp = NULL; |
| 4763 | |
| 4764 | spin_lock_irq(&phba->hbalock); |
| 4765 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4766 | pring = qp->pring; |
| 4767 | if (!pring) |
| 4768 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4769 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4770 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4771 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4772 | } |
| 4773 | spin_unlock_irq(&phba->hbalock); |
| 4774 | } |
| 4775 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | /* |
| 4777 | * Free resources / clean up outstanding I/Os |
| 4778 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4779 | */ |
| 4780 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4781 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4783 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4785 | lpfc_fabric_abort_nport(ndlp); |
| 4786 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | /* |
| 4788 | * Everything that matches on txcmplq will be returned |
| 4789 | * by firmware with a no rpi error. |
| 4790 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4791 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4792 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4793 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4794 | else |
| 4795 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4797 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4798 | /* Cancel all the IOCBs from the completions list */ |
| 4799 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4800 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4801 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4802 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4803 | } |
| 4804 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4805 | /** |
| 4806 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4807 | * @phba: Pointer to HBA context object. |
| 4808 | * @pmb: Pointer to mailbox object. |
| 4809 | * |
| 4810 | * This function will issue an ELS LOGO command after completing |
| 4811 | * the UNREG_RPI. |
| 4812 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4813 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4814 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4815 | { |
| 4816 | struct lpfc_vport *vport = pmb->vport; |
| 4817 | struct lpfc_nodelist *ndlp; |
| 4818 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4819 | ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4820 | if (!ndlp) |
| 4821 | return; |
| 4822 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4823 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4824 | |
| 4825 | /* Check to see if there are any deferred events to process */ |
| 4826 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 4827 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
| 4828 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4829 | "1434 UNREG cmpl deferred logo x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4830 | "on NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4831 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4832 | ndlp->nlp_defer_did, ndlp); |
| 4833 | |
| 4834 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 4835 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 4836 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4837 | } else { |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 4838 | /* NLP_RELEASE_RPI is only set for SLI4 ports. */ |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4839 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 4840 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 4841 | spin_lock_irq(&ndlp->lock); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4842 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4843 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 4844 | spin_unlock_irq(&ndlp->lock); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4845 | } |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 4846 | spin_lock_irq(&ndlp->lock); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4847 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 4848 | spin_unlock_irq(&ndlp->lock); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4849 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4850 | } |
| 4851 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | /* |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4853 | * Sets the mailbox completion handler to be used for the |
| 4854 | * unreg_rpi command. The handler varies based on the state of |
| 4855 | * the port and what will be happening to the rpi next. |
| 4856 | */ |
| 4857 | static void |
| 4858 | lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 4859 | struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox) |
| 4860 | { |
| 4861 | unsigned long iflags; |
| 4862 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 4863 | /* Driver always gets a reference on the mailbox job |
| 4864 | * in support of async jobs. |
| 4865 | */ |
| 4866 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
| 4867 | if (!mbox->ctx_ndlp) |
| 4868 | return; |
| 4869 | |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4870 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4871 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4872 | |
| 4873 | } else if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4874 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4875 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >= |
| 4876 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 4877 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4878 | mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr; |
| 4879 | } else { |
| 4880 | if (vport->load_flag & FC_UNLOADING) { |
| 4881 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4882 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4883 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 4884 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4885 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4886 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4887 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | * Free rpi associated with LPFC_NODELIST entry. |
| 4893 | * This routine is called from lpfc_freenode(), when we are removing |
| 4894 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4895 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4896 | * to the remote NPort. In addition, it is called after we receive |
| 4897 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4898 | * we are waiting to PLOGI back to the remote NPort. |
| 4899 | */ |
| 4900 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4901 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | struct lpfc_hba *phba = vport->phba; |
| 4904 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4905 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4906 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4908 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4909 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4910 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4911 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4912 | LOG_NODE | LOG_DISCOVERY, |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4913 | "3366 RPI x%x needs to be " |
| 4914 | "unregistered nlp_flag x%x " |
| 4915 | "did x%x\n", |
| 4916 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4917 | ndlp->nlp_DID); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4918 | |
| 4919 | /* If there is already an UNREG in progress for this ndlp, |
| 4920 | * no need to queue up another one. |
| 4921 | */ |
| 4922 | if (ndlp->nlp_flag & NLP_UNREG_INP) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4923 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4924 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4925 | "1436 unreg_rpi SKIP UNREG x%x on " |
| 4926 | "NPort x%x deferred x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4927 | "Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4928 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4929 | ndlp->nlp_defer_did, |
| 4930 | ndlp->nlp_flag, ndlp); |
| 4931 | goto out; |
| 4932 | } |
| 4933 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4934 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4935 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4936 | /* SLI4 ports require the physical rpi value. */ |
| 4937 | rpi = ndlp->nlp_rpi; |
| 4938 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4939 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4940 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4941 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4942 | mbox->vport = vport; |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4943 | lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox); |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 4944 | if (!mbox->ctx_ndlp) { |
| 4945 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4946 | return 1; |
| 4947 | } |
| 4948 | |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4949 | if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr) |
| 4950 | /* |
| 4951 | * accept PLOGIs after unreg_rpi_cmpl |
| 4952 | */ |
| 4953 | acc_plogi = 0; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4954 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != |
| 4955 | Fabric_DID_MASK) && |
| 4956 | (!(vport->fc_flag & FC_OFFLINE_MODE))) |
| 4957 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 4958 | |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4959 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4960 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4961 | "1433 unreg_rpi UNREG x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4962 | "NPort x%x deferred flg x%x " |
| 4963 | "Data:x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4964 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4965 | ndlp->nlp_flag, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4966 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4967 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4968 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4969 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4970 | acc_plogi = 1; |
| 4971 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 4972 | } else { |
| 4973 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4974 | LOG_NODE | LOG_DISCOVERY, |
| 4975 | "1444 Failed to allocate mempool " |
| 4976 | "unreg_rpi UNREG x%x, " |
| 4977 | "DID x%x, flag x%x, " |
| 4978 | "ndlp x%px\n", |
| 4979 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4980 | ndlp->nlp_flag, ndlp); |
| 4981 | |
| 4982 | /* Because mempool_alloc failed, we |
| 4983 | * will issue a LOGO here and keep the rpi alive if |
| 4984 | * not unloading. |
| 4985 | */ |
| 4986 | if (!(vport->load_flag & FC_UNLOADING)) { |
| 4987 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 4988 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 4989 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 4990 | lpfc_nlp_set_state(vport, ndlp, |
| 4991 | NLP_STE_NPR_NODE); |
| 4992 | } |
| 4993 | |
| 4994 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4995 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4996 | lpfc_no_rpi(phba, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4997 | out: |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4998 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4999 | ndlp->nlp_rpi = 0; |
| 5000 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 5001 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5002 | if (acc_plogi) |
| 5003 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5004 | return 1; |
| 5005 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 5006 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5007 | return 0; |
| 5008 | } |
| 5009 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5010 | /** |
| 5011 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 5012 | * @phba: pointer to lpfc hba data structure. |
| 5013 | * |
| 5014 | * This routine is invoked to unregister all the currently registered RPIs |
| 5015 | * to the HBA. |
| 5016 | **/ |
| 5017 | void |
| 5018 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 5019 | { |
| 5020 | struct lpfc_vport **vports; |
| 5021 | struct lpfc_nodelist *ndlp; |
| 5022 | struct Scsi_Host *shost; |
| 5023 | int i; |
| 5024 | |
| 5025 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5026 | if (!vports) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5027 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5028 | "2884 Vport array allocation failed \n"); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5029 | return; |
| 5030 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5031 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5032 | shost = lpfc_shost_from_vport(vports[i]); |
| 5033 | spin_lock_irq(shost->host_lock); |
| 5034 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5035 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5036 | /* The mempool_alloc might sleep */ |
| 5037 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5038 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5039 | spin_lock_irq(shost->host_lock); |
| 5040 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5041 | } |
| 5042 | spin_unlock_irq(shost->host_lock); |
| 5043 | } |
| 5044 | lpfc_destroy_vport_work_array(phba, vports); |
| 5045 | } |
| 5046 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5047 | void |
| 5048 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 5049 | { |
| 5050 | struct lpfc_hba *phba = vport->phba; |
| 5051 | LPFC_MBOXQ_t *mbox; |
| 5052 | int rc; |
| 5053 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5054 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 5055 | lpfc_sli4_unreg_all_rpis(vport); |
| 5056 | return; |
| 5057 | } |
| 5058 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5059 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5060 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5061 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 5062 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5063 | mbox->vport = vport; |
| 5064 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5065 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5066 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5067 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5068 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5069 | |
| 5070 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5071 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 5072 | "1836 Could not issue " |
| 5073 | "unreg_login(all_rpis) status %d\n", |
| 5074 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5075 | } |
| 5076 | } |
| 5077 | |
| 5078 | void |
| 5079 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 5080 | { |
| 5081 | struct lpfc_hba *phba = vport->phba; |
| 5082 | LPFC_MBOXQ_t *mbox; |
| 5083 | int rc; |
| 5084 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 5085 | /* Unreg DID is an SLI3 operation. */ |
| 5086 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 5087 | return; |
| 5088 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5089 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5090 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5091 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 5092 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5093 | mbox->vport = vport; |
| 5094 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5095 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5096 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5097 | if (rc != MBX_TIMEOUT) |
| 5098 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5099 | |
| 5100 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5101 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5102 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5103 | "unreg_did (default rpis) status %d\n", |
| 5104 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5105 | } |
| 5106 | } |
| 5107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5108 | /* |
| 5109 | * Free resources associated with LPFC_NODELIST entry |
| 5110 | * so it can be freed. |
| 5111 | */ |
| 5112 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5113 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5115 | struct lpfc_hba *phba = vport->phba; |
| 5116 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | |
| 5119 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5120 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5121 | "0900 Cleanup node for NPort x%x " |
| 5122 | "Data: x%x x%x x%x\n", |
| 5123 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5124 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5125 | lpfc_dequeue_node(vport, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5126 | |
| 5127 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 5128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5129 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 5130 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5131 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5132 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5133 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5134 | mb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5135 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5136 | } |
| 5137 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 5138 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5139 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5140 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 5141 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 5142 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5143 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5144 | (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp)) |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5145 | continue; |
| 5146 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5147 | mb->ctx_ndlp = NULL; |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5148 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5149 | } |
| 5150 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5151 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5152 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5153 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5154 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5155 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5156 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5157 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | kfree(mp); |
| 5159 | } |
| 5160 | list_del(&mb->list); |
| 5161 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5162 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 5163 | * the ndlp reference count as we are in the process |
| 5164 | * of lpfc_nlp_release. |
| 5165 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5166 | } |
| 5167 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5168 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5169 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5170 | lpfc_els_abort(phba, ndlp); |
| 5171 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5172 | spin_lock_irq(&ndlp->lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 5173 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5174 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5175 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5176 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 5178 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5179 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 5180 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5181 | list_del_init(&ndlp->recovery_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5182 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5183 | |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5184 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5185 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 5186 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5187 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | } |
| 5189 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5191 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5192 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5194 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | |
| 5196 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5197 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5199 | /* First check for Direct match */ |
| 5200 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5201 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | |
| 5203 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5204 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5205 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5206 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | matchdid.un.word = did; |
| 5210 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5211 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5212 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5213 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5214 | /* This code is supposed to match the ID |
| 5215 | * for a private loop device that is |
| 5216 | * connect to fl_port. But we need to |
| 5217 | * check that the port did not just go |
| 5218 | * from pt2pt to fabric or we could end |
| 5219 | * up matching ndlp->nlp_DID 000001 to |
| 5220 | * fabric DID 0x20101 |
| 5221 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | if ((ndlpdid.un.b.domain == 0) && |
| 5223 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5224 | if (ndlpdid.un.b.id && |
| 5225 | vport->phba->fc_topology == |
| 5226 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5227 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5229 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | matchdid.un.word = ndlp->nlp_DID; |
| 5233 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5234 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5235 | if ((matchdid.un.b.domain == 0) && |
| 5236 | (matchdid.un.b.area == 0)) { |
| 5237 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5238 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5242 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5243 | } |
| 5244 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5245 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | static struct lpfc_nodelist * |
| 5247 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5249 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5250 | uint32_t data1; |
| 5251 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5252 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5253 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5254 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5255 | ((uint32_t)ndlp->nlp_xri << 16) | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5256 | ((uint32_t)ndlp->nlp_type << 8) |
| 5257 | ); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5258 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5259 | "0929 FIND node DID " |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5260 | "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] | 5261 | ndlp, ndlp->nlp_DID, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5262 | ndlp->nlp_flag, data1, ndlp->nlp_rpi, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5263 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5264 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5265 | } |
| 5266 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5267 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5269 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5270 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | return NULL; |
| 5272 | } |
| 5273 | |
| 5274 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5275 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5277 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5278 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5279 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5281 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5282 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5283 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5284 | return ndlp; |
| 5285 | } |
| 5286 | |
| 5287 | struct lpfc_nodelist * |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5288 | lpfc_findnode_mapped(struct lpfc_vport *vport) |
| 5289 | { |
| 5290 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5291 | struct lpfc_nodelist *ndlp; |
| 5292 | uint32_t data1; |
| 5293 | unsigned long iflags; |
| 5294 | |
| 5295 | spin_lock_irqsave(shost->host_lock, iflags); |
| 5296 | |
| 5297 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5298 | if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || |
| 5299 | ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 5300 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5301 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5302 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5303 | ((uint32_t)ndlp->nlp_rpi & 0xff)); |
| 5304 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5305 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5306 | "2025 FIND node DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5307 | "Data: x%px x%x x%x x%x x%px\n", |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5308 | ndlp, ndlp->nlp_DID, |
| 5309 | ndlp->nlp_flag, data1, |
| 5310 | ndlp->active_rrqs_xri_bitmap); |
| 5311 | return ndlp; |
| 5312 | } |
| 5313 | } |
| 5314 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5315 | |
| 5316 | /* FIND node did <did> NOT FOUND */ |
| 5317 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5318 | "2026 FIND mapped did NOT FOUND.\n"); |
| 5319 | return NULL; |
| 5320 | } |
| 5321 | |
| 5322 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5323 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5324 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5325 | struct lpfc_nodelist *ndlp; |
| 5326 | |
| 5327 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5328 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5329 | if (vport->phba->nvmet_support) |
| 5330 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5331 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5332 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5334 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5335 | if (!ndlp) |
| 5336 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5337 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5338 | |
| 5339 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5340 | "6453 Setup New Node 2B_DISC x%x " |
| 5341 | "Data:x%x x%x x%x\n", |
| 5342 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5343 | ndlp->nlp_state, vport->fc_flag); |
| 5344 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5345 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5347 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5348 | return ndlp; |
| 5349 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5350 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5351 | /* The NVME Target does not want to actively manage an rport. |
| 5352 | * The goal is to allow the target to reset its state and clear |
| 5353 | * pending IO in preparation for the initiator to recover. |
| 5354 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5355 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5356 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5357 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5358 | |
| 5359 | /* Since this node is marked for discovery, |
| 5360 | * delay timeout is not needed. |
| 5361 | */ |
| 5362 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5363 | |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5364 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5365 | "6455 Setup RSCN Node 2B_DISC x%x " |
| 5366 | "Data:x%x x%x x%x\n", |
| 5367 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5368 | ndlp->nlp_state, vport->fc_flag); |
| 5369 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5370 | /* NVME Target mode waits until rport is known to be |
| 5371 | * impacted by the RSCN before it transitions. No |
| 5372 | * active management - just go to NPR provided the |
| 5373 | * node had a valid login. |
| 5374 | */ |
| 5375 | if (vport->phba->nvmet_support) |
| 5376 | return ndlp; |
| 5377 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5378 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5379 | * we don't need to try to discover it again. |
| 5380 | */ |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5381 | if (ndlp->nlp_flag & NLP_RCV_PLOGI && |
| 5382 | !(ndlp->nlp_type & |
| 5383 | (NLP_FCP_TARGET | NLP_NVME_TARGET))) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5384 | return NULL; |
| 5385 | |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5386 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 5387 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5388 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5389 | spin_lock_irq(&ndlp->lock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5390 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5391 | spin_unlock_irq(&ndlp->lock); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5392 | } else { |
| 5393 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5394 | "6456 Skip Setup RSCN Node x%x " |
| 5395 | "Data:x%x x%x x%x\n", |
| 5396 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5397 | ndlp->nlp_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5398 | ndlp = NULL; |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5399 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5400 | } else { |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5401 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5402 | "6457 Setup Active Node 2B_DISC x%x " |
| 5403 | "Data:x%x x%x x%x\n", |
| 5404 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5405 | ndlp->nlp_state, vport->fc_flag); |
| 5406 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5407 | /* If the initiator received a PLOGI from this NPort or if the |
| 5408 | * initiator is already in the process of discovery on it, |
| 5409 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5410 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5411 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5412 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5413 | (!vport->phba->nvmet_support && |
| 5414 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5415 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5416 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5417 | if (vport->phba->nvmet_support) |
| 5418 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5419 | |
| 5420 | /* Moving to NPR state clears unsolicited flags and |
| 5421 | * allows for rediscovery |
| 5422 | */ |
| 5423 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5424 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5425 | spin_lock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5427 | spin_unlock_irq(&ndlp->lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5428 | } |
| 5429 | return ndlp; |
| 5430 | } |
| 5431 | |
| 5432 | /* Build a list of nodes to discover based on the loopmap */ |
| 5433 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5434 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5436 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5437 | int j; |
| 5438 | uint32_t alpa, index; |
| 5439 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5440 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5442 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5443 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5444 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | |
| 5446 | /* Check for loop map present or not */ |
| 5447 | if (phba->alpa_map[0]) { |
| 5448 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5449 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5450 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5452 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | } |
| 5454 | } else { |
| 5455 | /* No alpamap, so try all alpa's */ |
| 5456 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5457 | /* If cfg_scan_down is set, start from highest |
| 5458 | * ALPA (0xef) to lowest (0x1). |
| 5459 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5460 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | index = j; |
| 5462 | else |
| 5463 | index = FC_MAXLOOP - j - 1; |
| 5464 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5465 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | } |
| 5469 | } |
| 5470 | return; |
| 5471 | } |
| 5472 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5473 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5475 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5477 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5478 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5479 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5480 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5481 | int rc; |
| 5482 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5483 | /* |
| 5484 | * if it's not a physical port or if we already send |
| 5485 | * clear_la then don't send it. |
| 5486 | */ |
| 5487 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5488 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5489 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5490 | return; |
| 5491 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5492 | /* Link up discovery */ |
| 5493 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5494 | phba->link_state = LPFC_CLEAR_LA; |
| 5495 | lpfc_clear_la(phba, mbox); |
| 5496 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5497 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5498 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5499 | if (rc == MBX_NOT_FINISHED) { |
| 5500 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5501 | lpfc_disc_flush_list(vport); |
| 5502 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5503 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5504 | phba->link_state = LPFC_HBA_ERROR; |
| 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5510 | void |
| 5511 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5512 | { |
| 5513 | LPFC_MBOXQ_t *regvpimbox; |
| 5514 | |
| 5515 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5516 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5517 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5518 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5519 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5520 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5521 | == MBX_NOT_FINISHED) { |
| 5522 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5523 | } |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5528 | void |
| 5529 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5530 | { |
| 5531 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5532 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5533 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5535 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5536 | if (!lpfc_is_link_up(phba)) { |
| 5537 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5538 | "3315 Link is not up %x\n", |
| 5539 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5541 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | |
| 5543 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | clear_la_pending = 1; |
| 5545 | else |
| 5546 | clear_la_pending = 0; |
| 5547 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5548 | if (vport->port_state < LPFC_VPORT_READY) |
| 5549 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5551 | lpfc_set_disctmo(vport); |
| 5552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5553 | vport->fc_prevDID = vport->fc_myDID; |
| 5554 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | |
| 5556 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5557 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5558 | "0202 Start Discovery port state x%x " |
| 5559 | "flg x%x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5560 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5561 | vport->fc_adisc_cnt, vport->fc_npr_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5562 | |
| 5563 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | |
| 5566 | if (num_sent) |
| 5567 | return; |
| 5568 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5569 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5570 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5571 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5572 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5573 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5574 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5575 | lpfc_issue_reg_vpi(phba, vport); |
| 5576 | return; |
| 5577 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5579 | /* |
| 5580 | * For SLI2, we need to set port_state to READY and continue |
| 5581 | * discovery. |
| 5582 | */ |
| 5583 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5584 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5585 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5586 | |
| 5587 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | vport->num_disc_nodes = 0; |
| 5589 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5590 | if (vport->fc_npr_cnt) |
| 5591 | lpfc_els_disc_plogi(vport); |
| 5592 | |
| 5593 | if (!vport->num_disc_nodes) { |
| 5594 | spin_lock_irq(shost->host_lock); |
| 5595 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5596 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5597 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5598 | } |
| 5599 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5600 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5601 | } else { |
| 5602 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5603 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5604 | |
| 5605 | if (num_sent) |
| 5606 | return; |
| 5607 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5608 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | /* Check to see if more RSCNs came in while we |
| 5610 | * were processing this one. |
| 5611 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5612 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5613 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5614 | spin_lock_irq(shost->host_lock); |
| 5615 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5616 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5617 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5618 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5619 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5620 | } |
| 5621 | } |
| 5622 | return; |
| 5623 | } |
| 5624 | |
| 5625 | /* |
| 5626 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5627 | * ring the match the sppecified nodelist. |
| 5628 | */ |
| 5629 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5630 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5631 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5632 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | IOCB_t *icmd; |
| 5634 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5635 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5637 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 5638 | if (unlikely(!pring)) |
| 5639 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | |
| 5641 | /* Error matching iocb on txq or txcmplq |
| 5642 | * First check the txq. |
| 5643 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5644 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5646 | if (iocb->context1 != ndlp) { |
| 5647 | continue; |
| 5648 | } |
| 5649 | icmd = &iocb->iocb; |
| 5650 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5651 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5652 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5653 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | /* Next check the txcmplq */ |
| 5658 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5659 | if (iocb->context1 != ndlp) { |
| 5660 | continue; |
| 5661 | } |
| 5662 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5663 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5664 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5665 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5666 | } |
| 5667 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5668 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5669 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 5670 | /* Make sure HBA is alive */ |
| 5671 | lpfc_issue_hb_tmo(phba); |
| 5672 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5673 | /* Cancel all the IOCBs from the completions list */ |
| 5674 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5675 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5676 | } |
| 5677 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5678 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5679 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5680 | { |
| 5681 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5682 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5683 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5684 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5685 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5686 | nlp_listp) { |
| 5687 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5688 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5689 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5690 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5691 | } |
| 5692 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | } |
| 5694 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5695 | void |
| 5696 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5697 | { |
| 5698 | lpfc_els_flush_rscn(vport); |
| 5699 | lpfc_els_flush_cmd(vport); |
| 5700 | lpfc_disc_flush_list(vport); |
| 5701 | } |
| 5702 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5703 | /*****************************************************************************/ |
| 5704 | /* |
| 5705 | * NAME: lpfc_disc_timeout |
| 5706 | * |
| 5707 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5708 | * |
| 5709 | * EXECUTION ENVIRONMENT: interrupt only |
| 5710 | * |
| 5711 | * CALLED FROM: |
| 5712 | * Timer function |
| 5713 | * |
| 5714 | * RETURNS: |
| 5715 | * none |
| 5716 | */ |
| 5717 | /*****************************************************************************/ |
| 5718 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5719 | lpfc_disc_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5720 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5721 | struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5722 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5723 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5724 | unsigned long flags = 0; |
| 5725 | |
| 5726 | if (unlikely(!phba)) |
| 5727 | return; |
| 5728 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5729 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5730 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5731 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5732 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5733 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5734 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5735 | if (!tmo_posted) |
| 5736 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5737 | return; |
| 5738 | } |
| 5739 | |
| 5740 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5741 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5742 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5743 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5744 | struct lpfc_hba *phba = vport->phba; |
| 5745 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5746 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5747 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5748 | int rc, clrlaerr = 0; |
| 5749 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5750 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5751 | return; |
| 5752 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5753 | spin_lock_irq(shost->host_lock); |
| 5754 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5755 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5756 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5757 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5758 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5759 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5760 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5761 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | |
| 5763 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5764 | /* |
| 5765 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5766 | * waiting for FAN timeout |
| 5767 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5768 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5769 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5770 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5771 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5772 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5773 | nlp_listp) { |
| 5774 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5775 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5776 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5777 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5778 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5779 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5780 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5781 | /* Fail outstanding IO now since device |
| 5782 | * is marked for PLOGI. |
| 5783 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5784 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5785 | } |
| 5786 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5787 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5788 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5789 | lpfc_initial_flogi(vport); |
| 5790 | else |
| 5791 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5792 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5793 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5794 | break; |
| 5795 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5796 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5797 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5798 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5799 | /* Initial FLOGI timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5800 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5801 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5802 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5803 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5804 | |
| 5805 | /* Assume no Fabric and go on with discovery. |
| 5806 | * Check for outstanding ELS FLOGI to abort. |
| 5807 | */ |
| 5808 | |
| 5809 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5810 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5811 | |
| 5812 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5813 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5814 | break; |
| 5815 | |
| 5816 | case LPFC_FABRIC_CFG_LINK: |
| 5817 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5818 | NameServer login */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5819 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5820 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5821 | "0223 Timeout while waiting for " |
| 5822 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5823 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5824 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5825 | if (ndlp) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5826 | lpfc_els_abort(phba, ndlp); |
| 5827 | |
| 5828 | /* ReStart discovery */ |
| 5829 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5830 | |
| 5831 | case LPFC_NS_QRY: |
| 5832 | /* Check for wait for NameServer Rsp timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5833 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5834 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5835 | "0224 NameServer Query timeout " |
| 5836 | "Data: x%x x%x\n", |
| 5837 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5838 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5839 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5840 | /* Try it one more time */ |
| 5841 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5842 | vport->gidft_inp = 0; |
| 5843 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5844 | if (rc == 0) |
| 5845 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5846 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5847 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5848 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5849 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5850 | /* |
| 5851 | * Discovery is over. |
| 5852 | * set port_state to PORT_READY if SLI2. |
| 5853 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5854 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5855 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5856 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5857 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5858 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5859 | lpfc_issue_clear_la(phba, vport); |
| 5860 | vport->port_state = LPFC_VPORT_READY; |
| 5861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5865 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5866 | if (!initlinkmbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5867 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5868 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5869 | "0206 Device Discovery " |
| 5870 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5871 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5872 | break; |
| 5873 | } |
| 5874 | |
| 5875 | lpfc_linkdown(phba); |
| 5876 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5877 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5878 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5879 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5880 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5881 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5882 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5883 | if (rc == MBX_NOT_FINISHED) |
| 5884 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5885 | |
| 5886 | break; |
| 5887 | |
| 5888 | case LPFC_DISC_AUTH: |
| 5889 | /* Node Authentication timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5890 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5891 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5892 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5893 | lpfc_disc_flush_list(vport); |
| 5894 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5895 | /* |
| 5896 | * set port_state to PORT_READY if SLI2. |
| 5897 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5898 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5899 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5900 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5901 | lpfc_issue_reg_vpi(phba, vport); |
| 5902 | else { /* NPIV Not enabled */ |
| 5903 | lpfc_issue_clear_la(phba, vport); |
| 5904 | vport->port_state = LPFC_VPORT_READY; |
| 5905 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5906 | } |
| 5907 | break; |
| 5908 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5909 | case LPFC_VPORT_READY: |
| 5910 | if (vport->fc_flag & FC_RSCN_MODE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5911 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5912 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5913 | "0231 RSCN timeout Data: x%x " |
| 5914 | "x%x\n", |
| 5915 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | |
| 5917 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5918 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5919 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5920 | lpfc_els_flush_rscn(vport); |
| 5921 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5922 | } |
| 5923 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5924 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5925 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5926 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5927 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5928 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5929 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5930 | break; |
| 5931 | } |
| 5932 | |
| 5933 | switch (phba->link_state) { |
| 5934 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5935 | /* CLEAR LA timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5936 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5937 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5938 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5939 | clrlaerr = 1; |
| 5940 | break; |
| 5941 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5942 | case LPFC_LINK_UP: |
| 5943 | lpfc_issue_clear_la(phba, vport); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 5944 | fallthrough; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5945 | case LPFC_LINK_UNKNOWN: |
| 5946 | case LPFC_WARM_START: |
| 5947 | case LPFC_INIT_START: |
| 5948 | case LPFC_INIT_MBX_CMDS: |
| 5949 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5950 | case LPFC_HBA_ERROR: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5951 | lpfc_printf_vlog(vport, KERN_ERR, |
| 5952 | LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5953 | "0230 Unexpected timeout, hba link " |
| 5954 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5955 | clrlaerr = 1; |
| 5956 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5957 | |
| 5958 | case LPFC_HBA_READY: |
| 5959 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5963 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5964 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 5965 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 5966 | ~LPFC_STOP_IOCB_EVENT; |
| 5967 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 5968 | ~LPFC_STOP_IOCB_EVENT; |
| 5969 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5970 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5972 | return; |
| 5973 | } |
| 5974 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5975 | /* |
| 5976 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5977 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5978 | * as the completion routine when the command is |
| 5979 | * handed off to the SLI layer. |
| 5980 | */ |
| 5981 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5982 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5983 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5984 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5985 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 5986 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5987 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5988 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5989 | pmb->ctx_buf = NULL; |
| 5990 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5991 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5992 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5993 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5994 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5995 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5996 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5997 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5998 | "0004 rpi:%x DID:%x flg:%x %d x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5999 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6000 | kref_read(&ndlp->kref), |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6001 | ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6002 | /* |
| 6003 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6004 | * 0xfffffa (FDMI well known port). |
| 6005 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 6006 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6007 | */ |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6008 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 6009 | phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6010 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6011 | } else { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6012 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
James Smart | a314dec | 2021-04-11 18:31:20 -0700 | [diff] [blame] | 6013 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6014 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6015 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6016 | /* decrement the node reference count held for this callback |
| 6017 | * function. |
| 6018 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6019 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6020 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6021 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6022 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6023 | |
| 6024 | return; |
| 6025 | } |
| 6026 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6027 | static int |
| 6028 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 6029 | { |
| 6030 | uint16_t *rpi = param; |
| 6031 | |
| 6032 | return ndlp->nlp_rpi == *rpi; |
| 6033 | } |
| 6034 | |
| 6035 | static int |
| 6036 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 6037 | { |
| 6038 | return memcmp(&ndlp->nlp_portname, param, |
| 6039 | sizeof(ndlp->nlp_portname)) == 0; |
| 6040 | } |
| 6041 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6042 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6043 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6044 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6045 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6046 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6047 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6048 | if (filter(ndlp, param)) { |
| 6049 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6050 | "3185 FIND node filter %ps DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6051 | "ndlp x%px did x%x flg x%x st x%x " |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6052 | "xri x%x type x%x rpi x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6053 | filter, ndlp, ndlp->nlp_DID, |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6054 | ndlp->nlp_flag, ndlp->nlp_state, |
| 6055 | ndlp->nlp_xri, ndlp->nlp_type, |
| 6056 | ndlp->nlp_rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6057 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6058 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6059 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6060 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6061 | "3186 FIND node filter %ps NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6062 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6063 | } |
| 6064 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6065 | /* |
| 6066 | * 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] | 6067 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6068 | */ |
| 6069 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6070 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6071 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6072 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6073 | } |
| 6074 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6075 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6076 | * 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] | 6077 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6078 | */ |
| 6079 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6080 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6081 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6082 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6083 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6084 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6085 | spin_lock_irq(shost->host_lock); |
| 6086 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 6087 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6088 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6089 | } |
| 6090 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6091 | /* |
| 6092 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 6093 | * is found, the routine returns the node element list pointer else |
| 6094 | * return NULL. |
| 6095 | */ |
| 6096 | struct lpfc_nodelist * |
| 6097 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 6098 | { |
| 6099 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6100 | struct lpfc_nodelist *ndlp; |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6101 | unsigned long flags; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6102 | |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6103 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6104 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6105 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6106 | return ndlp; |
| 6107 | } |
| 6108 | |
| 6109 | /** |
| 6110 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 6111 | * @phba: pointer to lpfc hba data structure. |
| 6112 | * @vpi: the physical host virtual N_Port identifier. |
| 6113 | * |
| 6114 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6115 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6116 | * of the vport with the matching @vpi. |
| 6117 | * |
| 6118 | * Return code |
| 6119 | * NULL - No vport with the matching @vpi found |
| 6120 | * Otherwise - Address to the vport with the matching @vpi. |
| 6121 | **/ |
| 6122 | struct lpfc_vport * |
| 6123 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6124 | { |
| 6125 | struct lpfc_vport *vport; |
| 6126 | unsigned long flags; |
| 6127 | int i = 0; |
| 6128 | |
| 6129 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 6130 | if (vpi > 0) { |
| 6131 | /* |
| 6132 | * Translate the physical vpi to the logical vpi. The |
| 6133 | * vport stores the logical vpi. |
| 6134 | */ |
James Smart | 58c36e8 | 2021-03-01 09:18:01 -0800 | [diff] [blame] | 6135 | for (i = 0; i <= phba->max_vpi; i++) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6136 | if (vpi == phba->vpi_ids[i]) |
| 6137 | break; |
| 6138 | } |
| 6139 | |
James Smart | 58c36e8 | 2021-03-01 09:18:01 -0800 | [diff] [blame] | 6140 | if (i > phba->max_vpi) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6141 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6142 | "2936 Could not find Vport mapped " |
| 6143 | "to vpi %d\n", vpi); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6144 | return NULL; |
| 6145 | } |
| 6146 | } |
| 6147 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6148 | spin_lock_irqsave(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6149 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 6150 | if (vport->vpi == i) { |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6151 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6152 | return vport; |
| 6153 | } |
| 6154 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6155 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6156 | return NULL; |
| 6157 | } |
| 6158 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6159 | struct lpfc_nodelist * |
| 6160 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6161 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6162 | struct lpfc_nodelist *ndlp; |
| 6163 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 6164 | |
| 6165 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 6166 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 6167 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 6168 | return NULL; |
| 6169 | } |
| 6170 | |
| 6171 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 6172 | if (!ndlp) { |
| 6173 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6174 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 6175 | return NULL; |
| 6176 | } |
| 6177 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6178 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6179 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6180 | spin_lock_init(&ndlp->lock); |
| 6181 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6182 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6183 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6184 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6185 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6186 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
| 6187 | "0007 Init New ndlp x%px, rpi:x%x DID:%x " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6188 | "flg:x%x refcnt:%d\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6189 | ndlp, ndlp->nlp_rpi, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6190 | ndlp->nlp_flag, kref_read(&ndlp->kref)); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6191 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6192 | ndlp->active_rrqs_xri_bitmap = |
| 6193 | mempool_alloc(vport->phba->active_rrq_pool, |
| 6194 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 6195 | if (ndlp->active_rrqs_xri_bitmap) |
| 6196 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 6197 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6198 | } |
| 6199 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 6200 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6201 | |
| 6202 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 6203 | "node init: did:x%x", |
| 6204 | ndlp->nlp_DID, 0, 0); |
| 6205 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6206 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6207 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6208 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6209 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 6210 | * and mempool_free's the nodelist. |
| 6211 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 6212 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6213 | lpfc_nlp_release(struct kref *kref) |
| 6214 | { |
| 6215 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 6216 | kref); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6217 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6218 | |
| 6219 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6220 | "node release: did:x%x flg:x%x type:x%x", |
| 6221 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 6222 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6223 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 6224 | "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n", |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6225 | __func__, ndlp, ndlp->nlp_DID, |
| 6226 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6227 | |
| 6228 | /* remove ndlp from action. */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6229 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 6230 | lpfc_cleanup_node(vport, ndlp); |
| 6231 | |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 6232 | /* Not all ELS transactions have registered the RPI with the port. |
| 6233 | * In these cases the rpi usage is temporary and the node is |
| 6234 | * released when the WQE is completed. Catch this case to free the |
| 6235 | * RPI to the pool. Because this node is in the release path, a lock |
| 6236 | * is unnecessary. All references are gone and the node has been |
| 6237 | * dequeued. |
| 6238 | */ |
| 6239 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 6240 | if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR && |
| 6241 | !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) { |
| 6242 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 6243 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | /* The node is not freed back to memory, it is released to a pool so |
| 6248 | * the node fields need to be cleaned up. |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6249 | */ |
| 6250 | ndlp->vport = NULL; |
| 6251 | ndlp->nlp_state = NLP_STE_FREED_NODE; |
| 6252 | ndlp->nlp_flag = 0; |
| 6253 | ndlp->fc4_xpt_flags = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6254 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6255 | /* free ndlp memory for final ndlp release */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6256 | kfree(ndlp->lat_data); |
| 6257 | if (ndlp->phba->sli_rev == LPFC_SLI_REV4) |
| 6258 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6259 | ndlp->phba->active_rrq_pool); |
| 6260 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6261 | } |
| 6262 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6263 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6264 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6265 | * is using it. |
| 6266 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6267 | struct lpfc_nodelist * |
| 6268 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6269 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6270 | unsigned long flags; |
| 6271 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6272 | if (ndlp) { |
| 6273 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6274 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6275 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6276 | kref_read(&ndlp->kref)); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6277 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6278 | /* The check of ndlp usage to prevent incrementing the |
| 6279 | * ndlp reference count that is in the process of being |
| 6280 | * released. |
| 6281 | */ |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6282 | spin_lock_irqsave(&ndlp->lock, flags); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6283 | if (!kref_get_unless_zero(&ndlp->kref)) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6284 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6285 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6286 | "0276 %s: ndlp:x%px refcnt:%d\n", |
| 6287 | __func__, (void *)ndlp, kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6288 | return NULL; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6289 | } |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6290 | spin_unlock_irqrestore(&ndlp->lock, flags); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6291 | } else { |
| 6292 | WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6293 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6294 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6295 | return ndlp; |
| 6296 | } |
| 6297 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6298 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6299 | * count goes to 0, this indicates the associated nodelist should be freed. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6300 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6301 | int |
| 6302 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6303 | { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6304 | if (ndlp) { |
| 6305 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6306 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6307 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6308 | kref_read(&ndlp->kref)); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6309 | } else { |
| 6310 | WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6311 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6312 | |
| 6313 | return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6314 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6315 | |
| 6316 | /* 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] | 6317 | * by any other discovery thread. This routine returns 1 if the |
| 6318 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6319 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6320 | */ |
| 6321 | int |
| 6322 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6323 | { |
| 6324 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6325 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6326 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6327 | kref_read(&ndlp->kref)); |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 6328 | |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6329 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6330 | if (lpfc_nlp_put(ndlp)) |
| 6331 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6332 | return 0; |
| 6333 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6334 | |
| 6335 | /** |
| 6336 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6337 | * @phba: Pointer to hba context object. |
| 6338 | * |
| 6339 | * This function iterate through all FC nodes associated |
| 6340 | * will all vports to check if there is any node with |
| 6341 | * fc_rports associated with it. If there is an fc_rport |
| 6342 | * associated with the node, then the node is either in |
| 6343 | * discovered state or its devloss_timer is pending. |
| 6344 | */ |
| 6345 | static int |
| 6346 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6347 | { |
| 6348 | struct lpfc_vport **vports; |
| 6349 | int i, ret = 0; |
| 6350 | struct lpfc_nodelist *ndlp; |
| 6351 | struct Scsi_Host *shost; |
| 6352 | |
| 6353 | vports = lpfc_create_vport_work_array(phba); |
| 6354 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6355 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6356 | if (!vports) |
| 6357 | return 1; |
| 6358 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6359 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6360 | shost = lpfc_shost_from_vport(vports[i]); |
| 6361 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6362 | /* |
| 6363 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6364 | * flogi. |
| 6365 | * If dev_loss fires while we are waiting we do not want to |
| 6366 | * unreg the fcf. |
| 6367 | */ |
| 6368 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6369 | spin_unlock_irq(shost->host_lock); |
| 6370 | ret = 1; |
| 6371 | goto out; |
| 6372 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6373 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6374 | if (ndlp->rport && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6375 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6376 | ret = 1; |
| 6377 | spin_unlock_irq(shost->host_lock); |
| 6378 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6379 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6380 | ret = 1; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6381 | lpfc_printf_log(phba, KERN_INFO, |
| 6382 | LOG_NODE | LOG_DISCOVERY, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6383 | "2624 RPI %x DID %x flag %x " |
| 6384 | "still logged in\n", |
| 6385 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6386 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6387 | } |
| 6388 | } |
| 6389 | spin_unlock_irq(shost->host_lock); |
| 6390 | } |
| 6391 | out: |
| 6392 | lpfc_destroy_vport_work_array(phba, vports); |
| 6393 | return ret; |
| 6394 | } |
| 6395 | |
| 6396 | /** |
| 6397 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6398 | * @phba: Pointer to hba context object. |
| 6399 | * @mboxq: Pointer to mailbox object. |
| 6400 | * |
| 6401 | * This function frees memory associated with the mailbox command. |
| 6402 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6403 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6404 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6405 | { |
| 6406 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6407 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6408 | |
| 6409 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6410 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6411 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6412 | "HBA state x%x\n", |
| 6413 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6414 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6415 | spin_lock_irq(shost->host_lock); |
| 6416 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6417 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6418 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6419 | return; |
| 6420 | } |
| 6421 | |
| 6422 | /** |
| 6423 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6424 | * @phba: Pointer to hba context object. |
| 6425 | * @mboxq: Pointer to mailbox object. |
| 6426 | * |
| 6427 | * This function frees memory associated with the mailbox command. |
| 6428 | */ |
| 6429 | static void |
| 6430 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6431 | { |
| 6432 | struct lpfc_vport *vport = mboxq->vport; |
| 6433 | |
| 6434 | if (mboxq->u.mb.mbxStatus) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6435 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6436 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6437 | "HBA state x%x\n", |
| 6438 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6439 | } |
| 6440 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6441 | return; |
| 6442 | } |
| 6443 | |
| 6444 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6445 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6446 | * @phba: Pointer to hba context object. |
| 6447 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6448 | * This function prepare the HBA for unregistering the currently registered |
| 6449 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6450 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6451 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6452 | int |
| 6453 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6454 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6455 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6456 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6457 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6458 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6459 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6460 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6461 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6462 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6463 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6464 | /* At this point, all discovery is aborted */ |
| 6465 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6466 | |
| 6467 | /* Unregister VPIs */ |
| 6468 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6469 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6470 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6471 | /* Stop FLOGI/FDISC retries */ |
| 6472 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6473 | if (ndlp) |
| 6474 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6475 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6476 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6477 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6478 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6479 | shost = lpfc_shost_from_vport(vports[i]); |
| 6480 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6481 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6482 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6483 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6484 | } |
| 6485 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6486 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6487 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6488 | if (ndlp) |
| 6489 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6490 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6491 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6492 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6493 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6494 | shost = lpfc_shost_from_vport(phba->pport); |
| 6495 | spin_lock_irq(shost->host_lock); |
| 6496 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6497 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6498 | spin_unlock_irq(shost->host_lock); |
| 6499 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6500 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6501 | /* Cleanup any outstanding ELS commands */ |
| 6502 | lpfc_els_flush_all_cmd(phba); |
| 6503 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6504 | /* Unregister the physical port VFI */ |
| 6505 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6506 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6507 | } |
| 6508 | |
| 6509 | /** |
| 6510 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6511 | * @phba: Pointer to hba context object. |
| 6512 | * |
| 6513 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6514 | * unregister the currently registered FCF record. The driver does not reset |
| 6515 | * the driver FCF usage state flags. |
| 6516 | * |
| 6517 | * Return 0 if successfully issued, none-zero otherwise. |
| 6518 | */ |
| 6519 | int |
| 6520 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6521 | { |
| 6522 | LPFC_MBOXQ_t *mbox; |
| 6523 | int rc; |
| 6524 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6525 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6526 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6527 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6528 | "2551 UNREG_FCFI mbox allocation failed" |
| 6529 | "HBA state x%x\n", phba->pport->port_state); |
| 6530 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6531 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6532 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6533 | mbox->vport = phba->pport; |
| 6534 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6535 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6536 | |
| 6537 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6538 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6539 | "2552 Unregister FCFI command failed rc x%x " |
| 6540 | "HBA state x%x\n", |
| 6541 | rc, phba->pport->port_state); |
| 6542 | return -EINVAL; |
| 6543 | } |
| 6544 | return 0; |
| 6545 | } |
| 6546 | |
| 6547 | /** |
| 6548 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6549 | * @phba: Pointer to hba context object. |
| 6550 | * |
| 6551 | * This function unregisters the currently reigstered FCF. This function |
| 6552 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6553 | */ |
| 6554 | void |
| 6555 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6556 | { |
| 6557 | int rc; |
| 6558 | |
| 6559 | /* Preparation for unregistering fcf */ |
| 6560 | rc = lpfc_unregister_fcf_prep(phba); |
| 6561 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6562 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6563 | "2748 Failed to prepare for unregistering " |
| 6564 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6565 | return; |
| 6566 | } |
| 6567 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6568 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6569 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6570 | if (rc) |
| 6571 | return; |
| 6572 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6573 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6574 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6575 | |
| 6576 | /* |
| 6577 | * If driver is not unloading, check if there is any other |
| 6578 | * FCF record that can be used for discovery. |
| 6579 | */ |
| 6580 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6581 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6582 | return; |
| 6583 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6584 | /* This is considered as the initial FCF discovery scan */ |
| 6585 | spin_lock_irq(&phba->hbalock); |
| 6586 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6587 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6588 | |
| 6589 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6590 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6591 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6592 | 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] | 6593 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6594 | if (rc) { |
| 6595 | spin_lock_irq(&phba->hbalock); |
| 6596 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6597 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6598 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6599 | "2553 lpfc_unregister_unused_fcf failed " |
| 6600 | "to read FCF record HBA state x%x\n", |
| 6601 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6602 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | /** |
| 6606 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6607 | * @phba: Pointer to hba context object. |
| 6608 | * |
| 6609 | * This function just unregisters the currently reigstered FCF. It does not |
| 6610 | * try to find another FCF for discovery. |
| 6611 | */ |
| 6612 | void |
| 6613 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6614 | { |
| 6615 | int rc; |
| 6616 | |
| 6617 | /* Preparation for unregistering fcf */ |
| 6618 | rc = lpfc_unregister_fcf_prep(phba); |
| 6619 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6620 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6621 | "2749 Failed to prepare for unregistering " |
| 6622 | "HBA's FCF record: rc=%d\n", rc); |
| 6623 | return; |
| 6624 | } |
| 6625 | |
| 6626 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6627 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6628 | if (rc) |
| 6629 | return; |
| 6630 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6631 | spin_lock_irq(&phba->hbalock); |
| 6632 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6633 | spin_unlock_irq(&phba->hbalock); |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6638 | * @phba: Pointer to hba context object. |
| 6639 | * |
| 6640 | * This function check if there are any connected remote port for the FCF and |
| 6641 | * if all the devices are disconnected, this function unregister FCFI. |
| 6642 | * This function also tries to use another FCF for discovery. |
| 6643 | */ |
| 6644 | void |
| 6645 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6646 | { |
| 6647 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6648 | * If HBA is not running in FIP mode, if HBA does not support |
| 6649 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6650 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6651 | */ |
| 6652 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6653 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6654 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6655 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6656 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6657 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6658 | spin_unlock_irq(&phba->hbalock); |
| 6659 | return; |
| 6660 | } |
| 6661 | spin_unlock_irq(&phba->hbalock); |
| 6662 | |
| 6663 | if (lpfc_fcf_inuse(phba)) |
| 6664 | return; |
| 6665 | |
| 6666 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | /** |
| 6670 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6671 | * @phba: Pointer to hba context object. |
| 6672 | * @buff: Buffer containing the FCF connection table as in the config |
| 6673 | * region. |
| 6674 | * This function create driver data structure for the FCF connection |
| 6675 | * record table read from config region 23. |
| 6676 | */ |
| 6677 | static void |
| 6678 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6679 | uint8_t *buff) |
| 6680 | { |
| 6681 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6682 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6683 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6684 | uint32_t record_count; |
| 6685 | int i; |
| 6686 | |
| 6687 | /* Free the current connect table */ |
| 6688 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6689 | &phba->fcf_conn_rec_list, list) { |
| 6690 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6691 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6692 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6693 | |
| 6694 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6695 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6696 | sizeof(struct lpfc_fcf_conn_rec); |
| 6697 | |
| 6698 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6699 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6700 | |
| 6701 | for (i = 0; i < record_count; i++) { |
| 6702 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6703 | continue; |
| 6704 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6705 | GFP_KERNEL); |
| 6706 | if (!conn_entry) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6707 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6708 | "2566 Failed to allocate connection" |
| 6709 | " table entry\n"); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6710 | return; |
| 6711 | } |
| 6712 | |
| 6713 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6714 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6715 | list_add_tail(&conn_entry->list, |
| 6716 | &phba->fcf_conn_rec_list); |
| 6717 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6718 | |
| 6719 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6720 | i = 0; |
| 6721 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6722 | list) { |
| 6723 | conn_rec = &conn_entry->conn_rec; |
| 6724 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6725 | "3345 FCF connection list rec[%02d]: " |
| 6726 | "flags:x%04x, vtag:x%04x, " |
| 6727 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6728 | "%02x:%02x:%02x:%02x, " |
| 6729 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6730 | "%02x:%02x:%02x:%02x\n", i++, |
| 6731 | conn_rec->flags, conn_rec->vlan_tag, |
| 6732 | conn_rec->fabric_name[0], |
| 6733 | conn_rec->fabric_name[1], |
| 6734 | conn_rec->fabric_name[2], |
| 6735 | conn_rec->fabric_name[3], |
| 6736 | conn_rec->fabric_name[4], |
| 6737 | conn_rec->fabric_name[5], |
| 6738 | conn_rec->fabric_name[6], |
| 6739 | conn_rec->fabric_name[7], |
| 6740 | conn_rec->switch_name[0], |
| 6741 | conn_rec->switch_name[1], |
| 6742 | conn_rec->switch_name[2], |
| 6743 | conn_rec->switch_name[3], |
| 6744 | conn_rec->switch_name[4], |
| 6745 | conn_rec->switch_name[5], |
| 6746 | conn_rec->switch_name[6], |
| 6747 | conn_rec->switch_name[7]); |
| 6748 | } |
| 6749 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /** |
| 6753 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6754 | * @phba: Pointer to hba context object. |
| 6755 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6756 | * |
| 6757 | * This function update driver data structure with config |
| 6758 | * parameters read from config region 23. |
| 6759 | */ |
| 6760 | static void |
| 6761 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6762 | uint8_t *buff) |
| 6763 | { |
| 6764 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6765 | struct lpfc_fcoe_params *fcoe_param; |
| 6766 | |
| 6767 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6768 | buff; |
| 6769 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6770 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6771 | |
| 6772 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6773 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6774 | return; |
| 6775 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6776 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6777 | phba->valid_vlan = 1; |
| 6778 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6779 | 0xFFF; |
| 6780 | } |
| 6781 | |
| 6782 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6783 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6784 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6785 | return; |
| 6786 | } |
| 6787 | |
| 6788 | /** |
| 6789 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6790 | * @buff: Buffer containing config region 23 data. |
| 6791 | * @size: Size of the data buffer. |
| 6792 | * @rec_type: Record type to be searched. |
| 6793 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6794 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6795 | * of the record specified by record_type. If record found, this |
| 6796 | * function return pointer to the record else return NULL. |
| 6797 | */ |
| 6798 | static uint8_t * |
| 6799 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6800 | { |
| 6801 | uint32_t offset = 0, rec_length; |
| 6802 | |
| 6803 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6804 | (size < sizeof(uint32_t))) |
| 6805 | return NULL; |
| 6806 | |
| 6807 | rec_length = buff[offset + 1]; |
| 6808 | |
| 6809 | /* |
| 6810 | * One TLV record has one word header and number of data words |
| 6811 | * specified in the rec_length field of the record header. |
| 6812 | */ |
| 6813 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6814 | <= size) { |
| 6815 | if (buff[offset] == rec_type) |
| 6816 | return &buff[offset]; |
| 6817 | |
| 6818 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6819 | return NULL; |
| 6820 | |
| 6821 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6822 | rec_length = buff[offset + 1]; |
| 6823 | } |
| 6824 | return NULL; |
| 6825 | } |
| 6826 | |
| 6827 | /** |
| 6828 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6829 | * @phba: Pointer to lpfc_hba data structure. |
| 6830 | * @buff: Buffer containing config region 23 data. |
| 6831 | * @size: Size of the data buffer. |
| 6832 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6833 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6834 | * populate driver data structure with the parameters. |
| 6835 | */ |
| 6836 | void |
| 6837 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6838 | uint8_t *buff, |
| 6839 | uint32_t size) |
| 6840 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6841 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6842 | uint8_t *rec_ptr; |
| 6843 | |
| 6844 | /* |
| 6845 | * If data size is less than 2 words signature and version cannot be |
| 6846 | * verified. |
| 6847 | */ |
| 6848 | if (size < 2*sizeof(uint32_t)) |
| 6849 | return; |
| 6850 | |
| 6851 | /* Check the region signature first */ |
| 6852 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6853 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6854 | "2567 Config region 23 has bad signature\n"); |
| 6855 | return; |
| 6856 | } |
| 6857 | |
| 6858 | offset += 4; |
| 6859 | |
| 6860 | /* Check the data structure version */ |
| 6861 | if (buff[offset] != LPFC_REGION23_VERSION) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6862 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6863 | "2568 Config region 23 has bad version\n"); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6864 | return; |
| 6865 | } |
| 6866 | offset += 4; |
| 6867 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6868 | /* Read FCoE param record */ |
| 6869 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6870 | size - offset, FCOE_PARAM_TYPE); |
| 6871 | if (rec_ptr) |
| 6872 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6873 | |
| 6874 | /* Read FCF connection table */ |
| 6875 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6876 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6877 | if (rec_ptr) |
| 6878 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6879 | |
| 6880 | } |