| 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 | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 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> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
| 37 | |
| 38 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 40 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 42 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_disc.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 47 | #include "lpfc_scsi.h" |
| 48 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_logmsg.h" |
| 50 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 52 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | |
| 54 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 55 | static uint8_t lpfcAlpaArray[] = { |
| 56 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 57 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 58 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 59 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 60 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 61 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 62 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 63 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 64 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 65 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 66 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 67 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 68 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 69 | }; |
| 70 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 71 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 72 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 73 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 74 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 76 | void |
| 77 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 79 | struct lpfc_rport_data *rdata; |
| 80 | struct lpfc_nodelist * ndlp; |
| 81 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 83 | rdata = rport->dd_data; |
| 84 | ndlp = rdata->pnode; |
| 85 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 86 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 87 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 88 | printk(KERN_ERR "Cannot find remote node" |
| 89 | " to terminate I/O Data x%x\n", |
| 90 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 94 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 95 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 96 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 97 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 98 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 99 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 100 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 101 | lpfc_sli_abort_iocb(ndlp->vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 102 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 103 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 104 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * This function will be called when dev_loss_tmo fire. |
| 109 | */ |
| 110 | void |
| 111 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 112 | { |
| 113 | struct lpfc_rport_data *rdata; |
| 114 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 115 | struct lpfc_vport *vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 116 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 117 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 118 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 119 | int put_node; |
| 120 | int put_rport; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 121 | unsigned long iflags; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 122 | |
| 123 | rdata = rport->dd_data; |
| 124 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 125 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 126 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 127 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 128 | vport = ndlp->vport; |
| 129 | phba = vport->phba; |
| 130 | |
| 131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 132 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 133 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 134 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 135 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 136 | "3181 dev_loss_callbk x%06x, rport %p flg x%x\n", |
| 137 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 138 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 139 | /* Don't defer this if we are in the process of deleting the vport |
| 140 | * or unloading the driver. The unload will cleanup the node |
| 141 | * appropriately we just need to cleanup the ndlp rport info here. |
| 142 | */ |
| 143 | if (vport->load_flag & FC_UNLOADING) { |
| 144 | put_node = rdata->pnode != NULL; |
| 145 | put_rport = ndlp->rport != NULL; |
| 146 | rdata->pnode = NULL; |
| 147 | ndlp->rport = NULL; |
| 148 | if (put_node) |
| 149 | lpfc_nlp_put(ndlp); |
| 150 | if (put_rport) |
| 151 | put_device(&rport->dev); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 156 | return; |
| 157 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 158 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
| 159 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 160 | "6789 rport name %llx != node port name %llx", |
| 161 | rport->port_name, |
| 162 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 164 | evtp = &ndlp->dev_loss_evt; |
| 165 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 166 | if (!list_empty(&evtp->evt_listp)) { |
| 167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 168 | "6790 rport name %llx dev_loss_evt pending", |
| 169 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 170 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 171 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 172 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 173 | shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 174 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 175 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 176 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 177 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 178 | /* We need to hold the node by incrementing the reference |
| 179 | * count until this queued work is done |
| 180 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 181 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 182 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 183 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 184 | if (evtp->evt_arg1) { |
| 185 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 186 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 187 | lpfc_worker_wake_up(phba); |
| 188 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 189 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 190 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 194 | /** |
| 195 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 196 | * @ndlp: Pointer to remote node object. |
| 197 | * |
| 198 | * This function is called from the worker thread when devloss timeout timer |
| 199 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 200 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 201 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 202 | * when devloss timeout happened to this @ndlp. |
| 203 | **/ |
| 204 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 205 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 206 | { |
| 207 | struct lpfc_rport_data *rdata; |
| 208 | struct fc_rport *rport; |
| 209 | struct lpfc_vport *vport; |
| 210 | struct lpfc_hba *phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 211 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 212 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 213 | int put_node; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 214 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 215 | int fcf_inuse = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 216 | unsigned long iflags; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 217 | |
| 218 | rport = ndlp->rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 219 | vport = ndlp->vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 220 | shost = lpfc_shost_from_vport(vport); |
| 221 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 222 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 223 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 224 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 225 | |
| 226 | if (!rport) |
| 227 | return fcf_inuse; |
| 228 | |
| 229 | name = (uint8_t *) &ndlp->nlp_portname; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 230 | phba = vport->phba; |
| 231 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 232 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 233 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 234 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 235 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 236 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 237 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 238 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 239 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 240 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", |
| 241 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 242 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 243 | /* |
| 244 | * lpfc_nlp_remove if reached with dangling rport drops the |
| 245 | * reference. To make sure that does not happen clear rport |
| 246 | * pointer in ndlp before lpfc_nlp_put. |
| 247 | */ |
| 248 | rdata = rport->dd_data; |
| 249 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 250 | /* Don't defer this if we are in the process of deleting the vport |
| 251 | * or unloading the driver. The unload will cleanup the node |
| 252 | * appropriately we just need to cleanup the ndlp rport info here. |
| 253 | */ |
| 254 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 255 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 256 | /* flush the target */ |
| 257 | lpfc_sli_abort_iocb(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 258 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
| 259 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 260 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 261 | put_node = rdata->pnode != NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 262 | rdata->pnode = NULL; |
| 263 | ndlp->rport = NULL; |
| 264 | if (put_node) |
| 265 | lpfc_nlp_put(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 266 | put_device(&rport->dev); |
| 267 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 268 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 269 | } |
| 270 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 271 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 273 | "0284 Devloss timeout Ignored on " |
| 274 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 275 | "NPort x%x\n", |
| 276 | *name, *(name+1), *(name+2), *(name+3), |
| 277 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 278 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 279 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 280 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 281 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 282 | put_node = rdata->pnode != NULL; |
| 283 | rdata->pnode = NULL; |
| 284 | ndlp->rport = NULL; |
| 285 | if (put_node) |
| 286 | lpfc_nlp_put(ndlp); |
| 287 | put_device(&rport->dev); |
| 288 | |
| 289 | if (ndlp->nlp_type & NLP_FABRIC) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 290 | return fcf_inuse; |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 293 | warn_on = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 294 | lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 295 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 297 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 298 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 299 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 300 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 301 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 302 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 303 | *name, *(name+1), *(name+2), *(name+3), |
| 304 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 305 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 306 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 307 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 308 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 309 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 310 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 311 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 312 | *name, *(name+1), *(name+2), *(name+3), |
| 313 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 314 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 315 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 316 | } |
| 317 | |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 318 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 319 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 320 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 321 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 322 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 323 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 324 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 325 | return fcf_inuse; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 330 | * @phba: Pointer to hba context object. |
| 331 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 332 | * @nlp_did: remote node identifer with devloss timeout. |
| 333 | * |
| 334 | * This function is called from the worker thread after invoking devloss |
| 335 | * timeout handler and releasing the reference count for the ndlp with |
| 336 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 337 | * timeout of the last remote node which had been in use of FCF, when this |
| 338 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 339 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 340 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 341 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 342 | * engine is in FCF discovery process, the devloss timeout state shall |
| 343 | * be set for either the FCF table scan process or roundrobin failover |
| 344 | * process to unregister the in-use FCF. |
| 345 | **/ |
| 346 | static void |
| 347 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 348 | uint32_t nlp_did) |
| 349 | { |
| 350 | /* If devloss timeout happened to a remote node when FCF had no |
| 351 | * longer been in-use, do nothing. |
| 352 | */ |
| 353 | if (!fcf_inuse) |
| 354 | return; |
| 355 | |
| 356 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 357 | spin_lock_irq(&phba->hbalock); |
| 358 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 359 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 360 | spin_unlock_irq(&phba->hbalock); |
| 361 | return; |
| 362 | } |
| 363 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 364 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 365 | "2847 Last remote node (x%x) using " |
| 366 | "FCF devloss tmo\n", nlp_did); |
| 367 | } |
| 368 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 369 | spin_unlock_irq(&phba->hbalock); |
| 370 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 371 | "2868 Devloss tmo to FCF rediscovery " |
| 372 | "in progress\n"); |
| 373 | return; |
| 374 | } |
| 375 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 376 | spin_unlock_irq(&phba->hbalock); |
| 377 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 378 | "2869 Devloss tmo to idle FIP engine, " |
| 379 | "unreg in-use FCF and rescan.\n"); |
| 380 | /* Unregister in-use FCF and rescan */ |
| 381 | lpfc_unregister_fcf_rescan(phba); |
| 382 | return; |
| 383 | } |
| 384 | spin_unlock_irq(&phba->hbalock); |
| 385 | if (phba->hba_flag & FCF_TS_INPROG) |
| 386 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 387 | "2870 FCF table scan in progress\n"); |
| 388 | if (phba->hba_flag & FCF_RR_INPROG) |
| 389 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 390 | "2871 FLOGI roundrobin FCF failover " |
| 391 | "in progress\n"); |
| 392 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 393 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 394 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 395 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 397 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 398 | * @phba: Pointer to hba context object. |
| 399 | * |
| 400 | * This function is called from the functions which need to post |
| 401 | * events from interrupt context. This function allocates data |
| 402 | * structure required for posting event. It also keeps track of |
| 403 | * number of events pending and prevent event storm when there are |
| 404 | * too many events. |
| 405 | **/ |
| 406 | struct lpfc_fast_path_event * |
| 407 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 408 | struct lpfc_fast_path_event *ret; |
| 409 | |
| 410 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 411 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 412 | return NULL; |
| 413 | |
| 414 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 415 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 416 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 417 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 418 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 419 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 420 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 425 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 426 | * @phba: Pointer to hba context object. |
| 427 | * @evt: Event object which need to be freed. |
| 428 | * |
| 429 | * This function frees the data structure required for posting |
| 430 | * events. |
| 431 | **/ |
| 432 | void |
| 433 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 434 | struct lpfc_fast_path_event *evt) { |
| 435 | |
| 436 | atomic_dec(&phba->fast_event_count); |
| 437 | kfree(evt); |
| 438 | } |
| 439 | |
| 440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 441 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 442 | * @phba: Pointer to hba context object. |
| 443 | * @evtp: Event data structure. |
| 444 | * |
| 445 | * This function is called from worker thread, when the interrupt |
| 446 | * context need to post an event. This function posts the event |
| 447 | * to fc transport netlink interface. |
| 448 | **/ |
| 449 | static void |
| 450 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 451 | struct lpfc_work_evt *evtp) |
| 452 | { |
| 453 | unsigned long evt_category, evt_sub_category; |
| 454 | struct lpfc_fast_path_event *fast_evt_data; |
| 455 | char *evt_data; |
| 456 | uint32_t evt_data_size; |
| 457 | struct Scsi_Host *shost; |
| 458 | |
| 459 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 460 | work_evt); |
| 461 | |
| 462 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 463 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 464 | fabric_evt.subcategory; |
| 465 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 466 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 467 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 468 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 469 | evt_data_size = sizeof(fast_evt_data->un. |
| 470 | read_check_error); |
| 471 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 472 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 473 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 474 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 475 | } else { |
| 476 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 477 | return; |
| 478 | } |
| 479 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 480 | switch (evt_sub_category) { |
| 481 | case LPFC_EVENT_QFULL: |
| 482 | case LPFC_EVENT_DEVBSY: |
| 483 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 484 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 485 | break; |
| 486 | case LPFC_EVENT_CHECK_COND: |
| 487 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 488 | evt_data_size = sizeof(fast_evt_data->un. |
| 489 | check_cond_evt); |
| 490 | break; |
| 491 | case LPFC_EVENT_VARQUEDEPTH: |
| 492 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 493 | evt_data_size = sizeof(fast_evt_data->un. |
| 494 | queue_depth_evt); |
| 495 | break; |
| 496 | default: |
| 497 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 498 | return; |
| 499 | } |
| 500 | } else { |
| 501 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 502 | return; |
| 503 | } |
| 504 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 505 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 506 | fc_host_post_vendor_event(shost, |
| 507 | fc_get_event_number(), |
| 508 | evt_data_size, |
| 509 | evt_data, |
| 510 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 511 | |
| 512 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 513 | return; |
| 514 | } |
| 515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 517 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | { |
| 519 | struct lpfc_work_evt *evtp = NULL; |
| 520 | struct lpfc_nodelist *ndlp; |
| 521 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 522 | int fcf_inuse; |
| 523 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 525 | spin_lock_irq(&phba->hbalock); |
| 526 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 528 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 529 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 531 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 533 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 535 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 536 | /* decrement the node reference count held |
| 537 | * for this queued work |
| 538 | */ |
| 539 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 540 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 541 | case LPFC_EVT_DEV_LOSS: |
| 542 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 543 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 544 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 545 | /* decrement the node reference count held for |
| 546 | * this queued work |
| 547 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 548 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 549 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 550 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 551 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 552 | fcf_inuse, |
| 553 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 554 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 555 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 556 | if (phba->link_state < LPFC_LINK_DOWN) |
| 557 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 558 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 559 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 560 | complete((struct completion *)(evtp->evt_arg2)); |
| 561 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 562 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 563 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 564 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 565 | *(int *)(evtp->evt_arg1) = 0; |
| 566 | complete((struct completion *)(evtp->evt_arg2)); |
| 567 | break; |
| 568 | case LPFC_EVT_OFFLINE: |
| 569 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 570 | lpfc_sli_brdrestart(phba); |
| 571 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 572 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 573 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 574 | complete((struct completion *)(evtp->evt_arg2)); |
| 575 | break; |
| 576 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 577 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 578 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 579 | lpfc_sli_brdreset(phba); |
| 580 | lpfc_hba_down_post(phba); |
| 581 | *(int *)(evtp->evt_arg1) = |
| 582 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 583 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 584 | complete((struct completion *)(evtp->evt_arg2)); |
| 585 | break; |
| 586 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 587 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 588 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 589 | = (phba->pport->stopped) |
| 590 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 591 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | complete((struct completion *)(evtp->evt_arg2)); |
| 593 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 594 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 595 | lpfc_send_fastpath_evt(phba, evtp); |
| 596 | free_evt = 0; |
| 597 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 598 | case LPFC_EVT_RESET_HBA: |
| 599 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 600 | lpfc_reset_hba(phba); |
| 601 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | } |
| 603 | if (free_evt) |
| 604 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 605 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 607 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | |
| 609 | } |
| 610 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 611 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 612 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | { |
| 614 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 615 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 616 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 617 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 618 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 620 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | ha_copy = phba->work_ha; |
| 622 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 623 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 625 | /* First, try to post the next mailbox command to SLI4 device */ |
| 626 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 627 | lpfc_sli4_post_async_mbox(phba); |
| 628 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 629 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 630 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | lpfc_handle_eratt(phba); |
| 632 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 633 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | lpfc_sli_handle_mb_event(phba); |
| 635 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 636 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 637 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 638 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 639 | /* Process SLI4 events */ |
| 640 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 641 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 642 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 643 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 644 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 645 | if (phba->hba_flag & ASYNC_EVENT) |
| 646 | lpfc_sli4_async_event_proc(phba); |
| 647 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 648 | spin_lock_irq(&phba->hbalock); |
| 649 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 650 | spin_unlock_irq(&phba->hbalock); |
| 651 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 652 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 653 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 654 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 655 | } |
| 656 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 657 | vports = lpfc_create_vport_work_array(phba); |
| 658 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 659 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 660 | /* |
| 661 | * We could have no vports in array if unloading, so if |
| 662 | * this happens then just use the pport |
| 663 | */ |
| 664 | if (vports[i] == NULL && i == 0) |
| 665 | vport = phba->pport; |
| 666 | else |
| 667 | vport = vports[i]; |
| 668 | if (vport == NULL) |
| 669 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 670 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 671 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 672 | vport->work_port_events &= ~work_port_events; |
| 673 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 674 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 675 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 676 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 677 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 678 | if (work_port_events & WORKER_HB_TMO) |
| 679 | lpfc_hb_timeout_handler(phba); |
| 680 | if (work_port_events & WORKER_MBOX_TMO) |
| 681 | lpfc_mbox_timeout_handler(phba); |
| 682 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 683 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 684 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 685 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 686 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 687 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 688 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 689 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 690 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 691 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 692 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 693 | status >>= (4*LPFC_ELS_RING); |
James Smart | 0c9c6a7 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 694 | if (pring && (status & HA_RXMASK || |
| 695 | pring->flag & LPFC_DEFERRED_RING_EVENT || |
| 696 | phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 697 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 698 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 161df4f0 | 2018-01-30 15:58:54 -0800 | [diff] [blame] | 699 | /* Preserve legacy behavior. */ |
| 700 | if (!(phba->hba_flag & HBA_SP_QUEUE_EVT)) |
| 701 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 702 | } else { |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 703 | if (phba->link_state >= LPFC_LINK_UP || |
| 704 | phba->link_flag & LS_MDS_LOOPBACK) { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 705 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 706 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 707 | (status & |
| 708 | HA_RXMASK)); |
| 709 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 710 | } |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 711 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 712 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 713 | /* |
| 714 | * Turn on Ring interrupts |
| 715 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 716 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 717 | spin_lock_irq(&phba->hbalock); |
| 718 | control = readl(phba->HCregaddr); |
| 719 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 720 | lpfc_debugfs_slow_ring_trc(phba, |
| 721 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 722 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 723 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 724 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 725 | writel(control, phba->HCregaddr); |
| 726 | readl(phba->HCregaddr); /* flush */ |
| 727 | } else { |
| 728 | lpfc_debugfs_slow_ring_trc(phba, |
| 729 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 730 | control, ha_copy, 0); |
| 731 | } |
| 732 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | } |
| 734 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | } |
| 737 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | int |
| 739 | lpfc_do_work(void *p) |
| 740 | { |
| 741 | struct lpfc_hba *phba = p; |
| 742 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 744 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 745 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 746 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 748 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 749 | /* wait and check worker queue activities */ |
| 750 | rc = wait_event_interruptible(phba->work_waitq, |
| 751 | (test_and_clear_bit(LPFC_DATA_READY, |
| 752 | &phba->data_flags) |
| 753 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 754 | /* Signal wakeup shall terminate the worker thread */ |
| 755 | if (rc) { |
| 756 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 757 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 759 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 761 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 764 | phba->worker_thread = NULL; |
| 765 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 766 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * 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] | 772 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | * embedding it in the IOCB. |
| 774 | */ |
| 775 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 776 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | uint32_t evt) |
| 778 | { |
| 779 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 780 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | |
| 782 | /* |
| 783 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 784 | * be queued to worker thread for processing |
| 785 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 786 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | if (!evtp) |
| 788 | return 0; |
| 789 | |
| 790 | evtp->evt_arg1 = arg1; |
| 791 | evtp->evt_arg2 = arg2; |
| 792 | evtp->evt = evt; |
| 793 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 794 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 795 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 796 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 798 | lpfc_worker_wake_up(phba); |
| 799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | return 1; |
| 801 | } |
| 802 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | void |
| 804 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 805 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 806 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 807 | struct lpfc_hba *phba = vport->phba; |
| 808 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | |
| 810 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 811 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 812 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 814 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 815 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 816 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 817 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | lpfc_unreg_rpi(vport, ndlp); |
| 819 | |
| 820 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 821 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 822 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 823 | continue; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 824 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 825 | remove |
| 826 | ? NLP_EVT_DEVICE_RM |
| 827 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 828 | } |
| 829 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 830 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 831 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 833 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 834 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 835 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 839 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 840 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 841 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 842 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 843 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 844 | /* Cleanup any outstanding received buffers */ |
| 845 | lpfc_cleanup_rcv_buffers(vport); |
| 846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 847 | /* Cleanup any outstanding RSCN activity */ |
| 848 | lpfc_els_flush_rscn(vport); |
| 849 | |
| 850 | /* Cleanup any outstanding ELS commands */ |
| 851 | lpfc_els_flush_cmd(vport); |
| 852 | |
| 853 | lpfc_cleanup_rpis(vport, 0); |
| 854 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 855 | /* Turn off discovery timer if its running */ |
| 856 | lpfc_can_disctmo(vport); |
| 857 | } |
| 858 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 859 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 860 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 861 | { |
| 862 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 863 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 864 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 865 | fc_host_post_event(shost, fc_get_event_number(), |
| 866 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 867 | |
| 868 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 869 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 870 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 871 | |
| 872 | lpfc_port_link_failure(vport); |
| 873 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 874 | /* Stop delayed Nport discovery */ |
| 875 | spin_lock_irq(shost->host_lock); |
| 876 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 877 | spin_unlock_irq(shost->host_lock); |
| 878 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 879 | } |
| 880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 882 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | struct lpfc_vport *vport = phba->pport; |
| 885 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 886 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 887 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 888 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 890 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 891 | return 0; |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 892 | |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 893 | /* Block all SCSI stack I/Os */ |
| 894 | lpfc_scsi_dev_block(phba); |
| 895 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 896 | phba->defer_flogi_acc_flag = false; |
| 897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 898 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 899 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 900 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 901 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 902 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 903 | if (phba->sli4_hba.conf_trunk) { |
| 904 | phba->trunk_link.link0.state = 0; |
| 905 | phba->trunk_link.link1.state = 0; |
| 906 | phba->trunk_link.link2.state = 0; |
| 907 | phba->trunk_link.link3.state = 0; |
| 908 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 909 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 910 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 911 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 912 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 913 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 914 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 915 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 916 | /* Issue a LINK DOWN event to all nodes */ |
| 917 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 918 | |
| 919 | vports[i]->fc_myDID = 0; |
| 920 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 921 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 922 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 923 | if (phba->nvmet_support) |
| 924 | lpfc_nvmet_update_targetport(phba); |
| 925 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 926 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 927 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 928 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 929 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 930 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 931 | |
| 932 | /* Clean up any SLI3 firmware default rpi's */ |
| 933 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 934 | goto skip_unreg_did; |
| 935 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 936 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 937 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 938 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 939 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 940 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 941 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 943 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 947 | skip_unreg_did: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 949 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 951 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 953 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 954 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 955 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 957 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | } |
| 959 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 960 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 962 | phba->pport->rcv_flogi_cnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 963 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 964 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 965 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 966 | } |
| 967 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | static void |
| 969 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 971 | struct lpfc_nodelist *ndlp; |
| 972 | |
| 973 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | a3da825 | 2018-03-05 12:04:06 -0800 | [diff] [blame] | 974 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 975 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 976 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 977 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 978 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 979 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 980 | /* On Linkup its safe to clean up the ndlp |
| 981 | * from Fabric connections. |
| 982 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | if (ndlp->nlp_DID != Fabric_DID) |
| 984 | lpfc_unreg_rpi(vport, ndlp); |
| 985 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 986 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 987 | /* Fail outstanding IO now since device is |
| 988 | * marked for PLOGI. |
| 989 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | lpfc_unreg_rpi(vport, ndlp); |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | static void |
| 996 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 997 | { |
| 998 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | struct lpfc_hba *phba = vport->phba; |
| 1000 | |
| 1001 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 1002 | return; |
| 1003 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1004 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1005 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 1006 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 1007 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1008 | /* If NPIV is not enabled, only bring the physical port up */ |
| 1009 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1010 | (vport != phba->pport)) |
| 1011 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1013 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1014 | fc_host_post_event(shost, fc_get_event_number(), |
| 1015 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1016 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1017 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1018 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1019 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1020 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1021 | vport->fc_ns_retry = 0; |
| 1022 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1024 | if (vport->fc_flag & FC_LBIT) |
| 1025 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static int |
| 1030 | lpfc_linkup(struct lpfc_hba *phba) |
| 1031 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1032 | struct lpfc_vport **vports; |
| 1033 | int i; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1034 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1035 | |
| 1036 | phba->link_state = LPFC_LINK_UP; |
| 1037 | |
| 1038 | /* Unblock fabric iocbs if they are blocked */ |
| 1039 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1040 | del_timer_sync(&phba->fabric_block_timer); |
| 1041 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1042 | vports = lpfc_create_vport_work_array(phba); |
| 1043 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1044 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1045 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1046 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1048 | /* Clear the pport flogi counter in case the link down was |
| 1049 | * absorbed without an ACQE. No lock here - in worker thread |
| 1050 | * and discovery is synchronized. |
| 1051 | */ |
| 1052 | spin_lock_irq(shost->host_lock); |
| 1053 | phba->pport->rcv_flogi_cnt = 0; |
| 1054 | spin_unlock_irq(shost->host_lock); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1055 | |
| 1056 | /* reinitialize initial FLOGI flag */ |
| 1057 | phba->hba_flag &= ~(HBA_FLOGI_ISSUED); |
| 1058 | phba->defer_flogi_acc_flag = false; |
| 1059 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * This routine handles processing a CLEAR_LA mailbox |
| 1065 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1066 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1067 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1069 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1070 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1072 | struct lpfc_vport *vport = pmb->vport; |
| 1073 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1074 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1075 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | uint32_t control; |
| 1077 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1079 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1080 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | /* Check for error */ |
| 1083 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1084 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1085 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1086 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1087 | "state x%x\n", |
| 1088 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1089 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | goto out; |
| 1091 | } |
| 1092 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1093 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1094 | phba->link_state = LPFC_HBA_READY; |
| 1095 | |
| 1096 | spin_lock_irq(&phba->hbalock); |
| 1097 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1098 | control = readl(phba->HCregaddr); |
| 1099 | control |= HC_LAINT_ENA; |
| 1100 | writel(control, phba->HCregaddr); |
| 1101 | readl(phba->HCregaddr); /* flush */ |
| 1102 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1103 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1104 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | out: |
| 1107 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1108 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1109 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1112 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1113 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1114 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1116 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | |
| 1118 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1119 | |
| 1120 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1122 | control = readl(phba->HCregaddr); |
| 1123 | control |= HC_LAINT_ENA; |
| 1124 | writel(control, phba->HCregaddr); |
| 1125 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | |
| 1128 | return; |
| 1129 | } |
| 1130 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1131 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1132 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1133 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1136 | uint8_t bbscn = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1137 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1138 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1139 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1140 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1141 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1142 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1143 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1144 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1145 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1146 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1147 | return; |
| 1148 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1149 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1150 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1151 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1152 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1153 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1154 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1155 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1157 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1160 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1161 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1162 | */ |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1163 | if (vport->port_state != LPFC_FLOGI) { |
| 1164 | if (phba->bbcredit_support && phba->cfg_enable_bbcr) { |
| 1165 | bbscn = bf_get(lpfc_bbscn_def, |
| 1166 | &phba->sli4_hba.bbscn_params); |
| 1167 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 1168 | vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4); |
| 1169 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1170 | lpfc_initial_flogi(vport); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1171 | } else if (vport->fc_flag & FC_PT2PT) { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1172 | lpfc_disc_start(vport); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1173 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1174 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | |
| 1176 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1177 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1178 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1179 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1180 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1181 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1182 | |
| 1183 | lpfc_linkdown(phba); |
| 1184 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1185 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1186 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1187 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1189 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | return; |
| 1191 | } |
| 1192 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1193 | /** |
| 1194 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1195 | * @phba pointer to the struct lpfc_hba for this port. |
| 1196 | * This fucnction resets the round robin bit mask and clears the |
| 1197 | * fcf priority list. The list deletions are done while holding the |
| 1198 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1199 | * from the lpfc_fcf_pri record. |
| 1200 | **/ |
| 1201 | void |
| 1202 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1203 | { |
| 1204 | struct lpfc_fcf_pri *fcf_pri; |
| 1205 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1206 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1207 | spin_lock_irq(&phba->hbalock); |
| 1208 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1209 | &phba->fcf.fcf_pri_list, list) { |
| 1210 | list_del_init(&fcf_pri->list); |
| 1211 | fcf_pri->fcf_rec.flag = 0; |
| 1212 | } |
| 1213 | spin_unlock_irq(&phba->hbalock); |
| 1214 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1216 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1217 | { |
| 1218 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1219 | |
| 1220 | if (mboxq->u.mb.mbxStatus) { |
| 1221 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1222 | "2017 REG_FCFI mbxStatus error x%x " |
| 1223 | "HBA state x%x\n", |
| 1224 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1225 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1229 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1230 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1231 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1232 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1233 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1234 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1235 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1236 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1237 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1238 | goto fail_out; |
| 1239 | |
| 1240 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1241 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1242 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1243 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1244 | if (vport->port_state != LPFC_FLOGI) { |
| 1245 | phba->hba_flag |= FCF_RR_INPROG; |
| 1246 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1247 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1248 | goto out; |
| 1249 | } |
| 1250 | spin_unlock_irq(&phba->hbalock); |
| 1251 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1252 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1253 | fail_out: |
| 1254 | spin_lock_irq(&phba->hbalock); |
| 1255 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1256 | spin_unlock_irq(&phba->hbalock); |
| 1257 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1258 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1263 | * @fab_name: pointer to fabric name. |
| 1264 | * @new_fcf_record: pointer to fcf record. |
| 1265 | * |
| 1266 | * This routine compare the fcf record's fabric name with provided |
| 1267 | * fabric name. If the fabric name are identical this function |
| 1268 | * returns 1 else return 0. |
| 1269 | **/ |
| 1270 | static uint32_t |
| 1271 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1272 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1273 | 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] | 1274 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1275 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1276 | return 0; |
| 1277 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1278 | return 0; |
| 1279 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1280 | return 0; |
| 1281 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1282 | return 0; |
| 1283 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1284 | return 0; |
| 1285 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1286 | return 0; |
| 1287 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1288 | return 0; |
| 1289 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1293 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1294 | * @fab_name: pointer to fabric name. |
| 1295 | * @new_fcf_record: pointer to fcf record. |
| 1296 | * |
| 1297 | * This routine compare the fcf record's switch name with provided |
| 1298 | * switch name. If the switch name are identical this function |
| 1299 | * returns 1 else return 0. |
| 1300 | **/ |
| 1301 | static uint32_t |
| 1302 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1303 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1304 | 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] | 1305 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1306 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1307 | return 0; |
| 1308 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1309 | return 0; |
| 1310 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1311 | return 0; |
| 1312 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1313 | return 0; |
| 1314 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1315 | return 0; |
| 1316 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1317 | return 0; |
| 1318 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1319 | return 0; |
| 1320 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1324 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1325 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1326 | * @new_fcf_record: pointer to fcf record. |
| 1327 | * |
| 1328 | * This routine compare the fcf record's mac address with HBA's |
| 1329 | * FCF mac address. If the mac addresses are identical this function |
| 1330 | * returns 1 else return 0. |
| 1331 | **/ |
| 1332 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1333 | 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] | 1334 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1335 | 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] | 1336 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1337 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1338 | return 0; |
| 1339 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1340 | return 0; |
| 1341 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1342 | return 0; |
| 1343 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1344 | return 0; |
| 1345 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1346 | return 0; |
| 1347 | return 1; |
| 1348 | } |
| 1349 | |
| 1350 | static bool |
| 1351 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1352 | { |
| 1353 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1357 | * lpfc_update_fcf_record - Update driver fcf record |
| 1358 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1359 | * @phba: pointer to lpfc hba data structure. |
| 1360 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1361 | * @new_fcf_record: pointer to hba fcf record. |
| 1362 | * |
| 1363 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1364 | * record. This routine is called with the host lock held. |
| 1365 | **/ |
| 1366 | static void |
| 1367 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1368 | struct fcf_record *new_fcf_record |
| 1369 | ) |
| 1370 | { |
| 1371 | struct lpfc_fcf_pri *fcf_pri; |
| 1372 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1373 | lockdep_assert_held(&phba->hbalock); |
| 1374 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1375 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1376 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1377 | /* FCF record priority */ |
| 1378 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1379 | |
| 1380 | } |
| 1381 | |
| 1382 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1383 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1384 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1385 | * @new_fcf_record: pointer to fcf record. |
| 1386 | * |
| 1387 | * This routine copies the FCF information from the FCF |
| 1388 | * record to lpfc_hba data structure. |
| 1389 | **/ |
| 1390 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1391 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1392 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1393 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1394 | /* Fabric name */ |
| 1395 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1396 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1397 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1398 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1399 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1400 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1401 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1402 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1403 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1404 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1405 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1406 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1407 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1408 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1409 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1410 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1411 | /* Mac address */ |
| 1412 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1413 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1414 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1415 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1416 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1417 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1418 | /* FCF record index */ |
| 1419 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1420 | /* FCF record priority */ |
| 1421 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1422 | /* Switch name */ |
| 1423 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1424 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1425 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1426 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1427 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1428 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1429 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1430 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1431 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1432 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1433 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1434 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1435 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1436 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1437 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1438 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1442 | * lpfc_update_fcf_record - Update driver fcf record |
| 1443 | * @phba: pointer to lpfc hba data structure. |
| 1444 | * @fcf_rec: pointer to driver fcf record. |
| 1445 | * @new_fcf_record: pointer to hba fcf record. |
| 1446 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1447 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1448 | * @flag: flag bits to be set to the driver fcf record. |
| 1449 | * |
| 1450 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1451 | * together with the address mode, vlan_id, and other informations. This |
| 1452 | * routine is called with the host lock held. |
| 1453 | **/ |
| 1454 | static void |
| 1455 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1456 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1457 | uint16_t vlan_id, uint32_t flag) |
| 1458 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1459 | lockdep_assert_held(&phba->hbalock); |
| 1460 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1461 | /* Copy the fields from the HBA's FCF record */ |
| 1462 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1463 | /* Update other fields of driver FCF record */ |
| 1464 | fcf_rec->addr_mode = addr_mode; |
| 1465 | fcf_rec->vlan_id = vlan_id; |
| 1466 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1467 | __lpfc_update_fcf_record_pri(phba, |
| 1468 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1469 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1473 | * lpfc_register_fcf - Register the FCF with hba. |
| 1474 | * @phba: pointer to lpfc hba data structure. |
| 1475 | * |
| 1476 | * This routine issues a register fcfi mailbox command to register |
| 1477 | * the fcf with HBA. |
| 1478 | **/ |
| 1479 | static void |
| 1480 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1481 | { |
| 1482 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1483 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1484 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1485 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1486 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1487 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1488 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1489 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | /* The FCF is already registered, start discovery */ |
| 1494 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1495 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1496 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1497 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1498 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1499 | phba->hba_flag |= FCF_RR_INPROG; |
| 1500 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1501 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1502 | return; |
| 1503 | } |
| 1504 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1505 | return; |
| 1506 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1507 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1508 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1509 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1510 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1511 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1512 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1513 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1514 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1515 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1516 | |
| 1517 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1518 | fcf_mbxq->vport = phba->pport; |
| 1519 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1520 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1521 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1522 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1523 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1524 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1525 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1526 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1527 | |
| 1528 | return; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1533 | * @phba: pointer to lpfc hba data structure. |
| 1534 | * @new_fcf_record: pointer to fcf record. |
| 1535 | * @boot_flag: Indicates if this record used by boot bios. |
| 1536 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1537 | * @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] | 1538 | * |
| 1539 | * This routine compare the fcf record with connect list obtained from the |
| 1540 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1541 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1542 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1543 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1544 | * used for this FCF when the function returns. |
| 1545 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1546 | * 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] | 1547 | * 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] | 1548 | **/ |
| 1549 | static int |
| 1550 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1551 | struct fcf_record *new_fcf_record, |
| 1552 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1553 | uint16_t *vlan_id) |
| 1554 | { |
| 1555 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1556 | int i, j, fcf_vlan_id = 0; |
| 1557 | |
| 1558 | /* Find the lowest VLAN id in the FCF record */ |
| 1559 | for (i = 0; i < 512; i++) { |
| 1560 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1561 | fcf_vlan_id = i * 8; |
| 1562 | j = 0; |
| 1563 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1564 | j++; |
| 1565 | fcf_vlan_id++; |
| 1566 | } |
| 1567 | break; |
| 1568 | } |
| 1569 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1570 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1571 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1572 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1573 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1574 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1575 | return 0; |
| 1576 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1577 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1578 | *boot_flag = 0; |
| 1579 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1580 | new_fcf_record); |
| 1581 | if (phba->valid_vlan) |
| 1582 | *vlan_id = phba->vlan_id; |
| 1583 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1584 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1585 | return 1; |
| 1586 | } |
| 1587 | |
| 1588 | /* |
| 1589 | * If there are no FCF connection table entry, driver connect to all |
| 1590 | * FCFs. |
| 1591 | */ |
| 1592 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1593 | *boot_flag = 0; |
| 1594 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1595 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1596 | |
| 1597 | /* |
| 1598 | * When there are no FCF connect entries, use driver's default |
| 1599 | * addressing mode - FPMA. |
| 1600 | */ |
| 1601 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1602 | *addr_mode = LPFC_FCF_FPMA; |
| 1603 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1604 | /* If FCF record report a vlan id use that vlan id */ |
| 1605 | if (fcf_vlan_id) |
| 1606 | *vlan_id = fcf_vlan_id; |
| 1607 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1608 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1609 | return 1; |
| 1610 | } |
| 1611 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1612 | list_for_each_entry(conn_entry, |
| 1613 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1614 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1615 | continue; |
| 1616 | |
| 1617 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1618 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1619 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1620 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1621 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1622 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1623 | new_fcf_record)) |
| 1624 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1625 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1626 | /* |
| 1627 | * If the vlan bit map does not have the bit set for the |
| 1628 | * vlan id to be used, then it is not a match. |
| 1629 | */ |
| 1630 | if (!(new_fcf_record->vlan_bitmap |
| 1631 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1632 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1633 | continue; |
| 1634 | } |
| 1635 | |
| 1636 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1637 | * If connection record does not support any addressing mode, |
| 1638 | * skip the FCF record. |
| 1639 | */ |
| 1640 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1641 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1642 | continue; |
| 1643 | |
| 1644 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1645 | * Check if the connection record specifies a required |
| 1646 | * addressing mode. |
| 1647 | */ |
| 1648 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1649 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1650 | |
| 1651 | /* |
| 1652 | * If SPMA required but FCF not support this continue. |
| 1653 | */ |
| 1654 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1655 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1656 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1657 | continue; |
| 1658 | |
| 1659 | /* |
| 1660 | * If FPMA required but FCF not support this continue. |
| 1661 | */ |
| 1662 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1663 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1664 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1665 | continue; |
| 1666 | } |
| 1667 | |
| 1668 | /* |
| 1669 | * This fcf record matches filtering criteria. |
| 1670 | */ |
| 1671 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1672 | *boot_flag = 1; |
| 1673 | else |
| 1674 | *boot_flag = 0; |
| 1675 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1676 | /* |
| 1677 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1678 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1679 | * by FCF, allow fabric to pick the addressing mode. |
| 1680 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1681 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1682 | new_fcf_record); |
| 1683 | /* |
| 1684 | * If the user specified a required address mode, assign that |
| 1685 | * address mode |
| 1686 | */ |
| 1687 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1688 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1689 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1690 | FCFCNCT_AM_SPMA) ? |
| 1691 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1692 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1693 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1694 | * addr mode only if FCF support the addr_mode. |
| 1695 | */ |
| 1696 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1697 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1698 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1699 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1700 | *addr_mode = LPFC_FCF_SPMA; |
| 1701 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1702 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1703 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1704 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1705 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1706 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1707 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1708 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1709 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1710 | /* |
| 1711 | * If no vlan id is specified in connect list, use the vlan id |
| 1712 | * in the FCF record |
| 1713 | */ |
| 1714 | else if (fcf_vlan_id) |
| 1715 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1716 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1717 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1718 | |
| 1719 | return 1; |
| 1720 | } |
| 1721 | |
| 1722 | return 0; |
| 1723 | } |
| 1724 | |
| 1725 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1726 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1727 | * @phba: pointer to lpfc hba data structure. |
| 1728 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1729 | * |
| 1730 | * This function check if there is any fcoe event pending while driver |
| 1731 | * scan FCF entries. If there is any pending event, it will restart the |
| 1732 | * FCF saning and return 1 else return 0. |
| 1733 | */ |
| 1734 | int |
| 1735 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1736 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1737 | /* |
| 1738 | * If the Link is up and no FCoE events while in the |
| 1739 | * FCF discovery, no need to restart FCF discovery. |
| 1740 | */ |
| 1741 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1742 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1743 | return 0; |
| 1744 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1745 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1746 | "2768 Pending link or FCF event during current " |
| 1747 | "handling of the previous event: link_state:x%x, " |
| 1748 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1749 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1750 | phba->fcoe_eventtag); |
| 1751 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1752 | spin_lock_irq(&phba->hbalock); |
| 1753 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1754 | spin_unlock_irq(&phba->hbalock); |
| 1755 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1756 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1757 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1758 | "2780 Restart FCF table scan due to " |
| 1759 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1760 | "evt_tag_current:x%x\n", |
| 1761 | phba->fcoe_eventtag_at_fcf_scan, |
| 1762 | phba->fcoe_eventtag); |
| 1763 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1764 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1765 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1766 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1767 | * flag |
| 1768 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1769 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1770 | "2833 Stop FCF discovery process due to link " |
| 1771 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1772 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1773 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1774 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1775 | spin_unlock_irq(&phba->hbalock); |
| 1776 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1777 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1778 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1779 | if (unreg_fcf) { |
| 1780 | spin_lock_irq(&phba->hbalock); |
| 1781 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1782 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1783 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1784 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1785 | return 1; |
| 1786 | } |
| 1787 | |
| 1788 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1789 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1790 | * @phba: pointer to lpfc hba data structure. |
| 1791 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1792 | * |
| 1793 | * This function makes an running random selection decision on FCF record to |
| 1794 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1795 | * probability. To perform integer manunipulation of random numbers with |
| 1796 | * 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] | 1797 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1798 | * |
| 1799 | * Returns true when outcome is for the newly read FCF record should be |
| 1800 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1801 | * chosen FCF record. |
| 1802 | **/ |
| 1803 | static bool |
| 1804 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1805 | { |
| 1806 | uint32_t rand_num; |
| 1807 | |
| 1808 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1809 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1810 | |
| 1811 | /* Decision with probability 1/fcf_cnt */ |
| 1812 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1813 | return true; |
| 1814 | else |
| 1815 | return false; |
| 1816 | } |
| 1817 | |
| 1818 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1819 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1820 | * @phba: pointer to lpfc hba data structure. |
| 1821 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1822 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1823 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1824 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1825 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1826 | * SGE parsing, and endianness swapping. |
| 1827 | * |
| 1828 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1829 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1830 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1831 | static struct fcf_record * |
| 1832 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1833 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1834 | { |
| 1835 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1836 | struct lpfc_mbx_sge sge; |
| 1837 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1838 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1839 | union lpfc_sli4_cfg_shdr *shdr; |
| 1840 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1841 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1842 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1843 | * routine only uses a single SGE. |
| 1844 | */ |
| 1845 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1846 | if (unlikely(!mboxq->sge_array)) { |
| 1847 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1848 | "2524 Failed to get the non-embedded SGE " |
| 1849 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1850 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1851 | } |
| 1852 | virt_addr = mboxq->sge_array->addr[0]; |
| 1853 | |
| 1854 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1855 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1856 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1857 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1858 | 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] | 1859 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1860 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1861 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1862 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1863 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1864 | "2726 READ_FCF_RECORD Indicates empty " |
| 1865 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1866 | else |
| 1867 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1868 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1869 | "with status x%x add_status x%x, " |
| 1870 | "mbx\n", shdr_status, shdr_add_status); |
| 1871 | return 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 | |
| 1874 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1875 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1876 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1877 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1878 | *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] | 1879 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1880 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1881 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1882 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1883 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1884 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1885 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1886 | return new_fcf_record; |
| 1887 | } |
| 1888 | |
| 1889 | /** |
| 1890 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1891 | * @phba: pointer to lpfc hba data structure. |
| 1892 | * @fcf_record: pointer to the fcf record. |
| 1893 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1894 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1895 | * |
| 1896 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1897 | * enabled. |
| 1898 | **/ |
| 1899 | static void |
| 1900 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1901 | struct fcf_record *fcf_record, |
| 1902 | uint16_t vlan_id, |
| 1903 | uint16_t next_fcf_index) |
| 1904 | { |
| 1905 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1906 | "2764 READ_FCF_RECORD:\n" |
| 1907 | "\tFCF_Index : x%x\n" |
| 1908 | "\tFCF_Avail : x%x\n" |
| 1909 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1910 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1911 | "\tFIP_Priority : x%x\n" |
| 1912 | "\tMAC_Provider : x%x\n" |
| 1913 | "\tLowest VLANID : x%x\n" |
| 1914 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1915 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1916 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1917 | "\tNext_FCF_Index: x%x\n", |
| 1918 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1919 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1920 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1921 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1922 | fcf_record->fip_priority, |
| 1923 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1924 | vlan_id, |
| 1925 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1926 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1927 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1928 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1929 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1930 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1931 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1932 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1933 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1934 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1935 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1936 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1937 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1938 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1939 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1940 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1941 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1942 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1943 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1944 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1945 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1946 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1947 | next_fcf_index); |
| 1948 | } |
| 1949 | |
| 1950 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1951 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1952 | * @phba: pointer to lpfc hba data structure. |
| 1953 | * @fcf_rec: pointer to an existing FCF record. |
| 1954 | * @new_fcf_record: pointer to a new FCF record. |
| 1955 | * @new_vlan_id: vlan id from the new FCF record. |
| 1956 | * |
| 1957 | * This function performs matching test of a new FCF record against an existing |
| 1958 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1959 | * will not be used as part of the FCF record matching criteria. |
| 1960 | * |
| 1961 | * Returns true if all the fields matching, otherwise returns false. |
| 1962 | */ |
| 1963 | static bool |
| 1964 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1965 | struct lpfc_fcf_rec *fcf_rec, |
| 1966 | struct fcf_record *new_fcf_record, |
| 1967 | uint16_t new_vlan_id) |
| 1968 | { |
| 1969 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1970 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1971 | return false; |
| 1972 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1973 | return false; |
| 1974 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1975 | return false; |
| 1976 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1977 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1978 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1979 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1980 | return true; |
| 1981 | } |
| 1982 | |
| 1983 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1984 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1985 | * @vport: Pointer to vport object. |
| 1986 | * @fcf_index: index to next fcf. |
| 1987 | * |
| 1988 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1989 | * When this function is invoked, there will be a current fcf registered |
| 1990 | * for flogi. |
| 1991 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1992 | * 1 for stop flogi on currently registered fcf; |
| 1993 | */ |
| 1994 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1995 | { |
| 1996 | struct lpfc_hba *phba = vport->phba; |
| 1997 | int rc; |
| 1998 | |
| 1999 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 2000 | spin_lock_irq(&phba->hbalock); |
| 2001 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2002 | spin_unlock_irq(&phba->hbalock); |
| 2003 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2004 | "2872 Devloss tmo with no eligible " |
| 2005 | "FCF, unregister in-use FCF (x%x) " |
| 2006 | "and rescan FCF table\n", |
| 2007 | phba->fcf.current_rec.fcf_indx); |
| 2008 | lpfc_unregister_fcf_rescan(phba); |
| 2009 | goto stop_flogi_current_fcf; |
| 2010 | } |
| 2011 | /* Mark the end to FLOGI roundrobin failover */ |
| 2012 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 2013 | /* Allow action to new fcf asynchronous event */ |
| 2014 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 2015 | spin_unlock_irq(&phba->hbalock); |
| 2016 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2017 | "2865 No FCF available, stop roundrobin FCF " |
| 2018 | "failover and change port state:x%x/x%x\n", |
| 2019 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 2020 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 2021 | |
| 2022 | if (!phba->fcf.fcf_redisc_attempted) { |
| 2023 | lpfc_unregister_fcf(phba); |
| 2024 | |
| 2025 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 2026 | if (!rc) { |
| 2027 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2028 | "3195 Rediscover FCF table\n"); |
| 2029 | phba->fcf.fcf_redisc_attempted = 1; |
| 2030 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 2031 | } else { |
| 2032 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2033 | "3196 Rediscover FCF table " |
| 2034 | "failed. Status:x%x\n", rc); |
| 2035 | } |
| 2036 | } else { |
| 2037 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2038 | "3197 Already rediscover FCF table " |
| 2039 | "attempted. No more retry\n"); |
| 2040 | } |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2041 | goto stop_flogi_current_fcf; |
| 2042 | } else { |
| 2043 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 2044 | "2794 Try FLOGI roundrobin FCF failover to " |
| 2045 | "(x%x)\n", fcf_index); |
| 2046 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 2047 | if (rc) |
| 2048 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 2049 | "2761 FLOGI roundrobin FCF failover " |
| 2050 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 2051 | rc, phba->fcf.current_rec.fcf_indx); |
| 2052 | else |
| 2053 | goto stop_flogi_current_fcf; |
| 2054 | } |
| 2055 | return 0; |
| 2056 | |
| 2057 | stop_flogi_current_fcf: |
| 2058 | lpfc_can_disctmo(vport); |
| 2059 | return 1; |
| 2060 | } |
| 2061 | |
| 2062 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2063 | * lpfc_sli4_fcf_pri_list_del |
| 2064 | * @phba: pointer to lpfc hba data structure. |
| 2065 | * @fcf_index the index of the fcf record to delete |
| 2066 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2067 | * If it is one the list then it is removed from the list, and the flag |
| 2068 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2069 | * record from the list. |
| 2070 | **/ |
| 2071 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2072 | uint16_t fcf_index) |
| 2073 | { |
| 2074 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2075 | |
| 2076 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2077 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2078 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2079 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2080 | new_fcf_pri->fcf_rec.flag); |
| 2081 | spin_lock_irq(&phba->hbalock); |
| 2082 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2083 | if (phba->fcf.current_rec.priority == |
| 2084 | new_fcf_pri->fcf_rec.priority) |
| 2085 | phba->fcf.eligible_fcf_cnt--; |
| 2086 | list_del_init(&new_fcf_pri->list); |
| 2087 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2088 | } |
| 2089 | spin_unlock_irq(&phba->hbalock); |
| 2090 | } |
| 2091 | |
| 2092 | /** |
| 2093 | * lpfc_sli4_set_fcf_flogi_fail |
| 2094 | * @phba: pointer to lpfc hba data structure. |
| 2095 | * @fcf_index the index of the fcf record to update |
| 2096 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2097 | * flag so the the round robin slection for the particular priority level |
| 2098 | * will try a different fcf record that does not have this bit set. |
| 2099 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2100 | * adding it to the priority list. |
| 2101 | **/ |
| 2102 | void |
| 2103 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2104 | { |
| 2105 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2106 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2107 | spin_lock_irq(&phba->hbalock); |
| 2108 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2109 | spin_unlock_irq(&phba->hbalock); |
| 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * lpfc_sli4_fcf_pri_list_add |
| 2114 | * @phba: pointer to lpfc hba data structure. |
| 2115 | * @fcf_index the index of the fcf record to add |
| 2116 | * This routine checks the priority of the fcf_index to be added. |
| 2117 | * If it is a lower priority than the current head of the fcf_pri list |
| 2118 | * then it is added to the list in the right order. |
| 2119 | * If it is the same priority as the current head of the list then it |
| 2120 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2121 | * If the fcf_index to be added is of a higher priority than the current |
| 2122 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2123 | * rr_bmask and it is added to the head of the list. |
| 2124 | * returns: |
| 2125 | * 0=success 1=failure |
| 2126 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2127 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2128 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2129 | struct fcf_record *new_fcf_record) |
| 2130 | { |
| 2131 | uint16_t current_fcf_pri; |
| 2132 | uint16_t last_index; |
| 2133 | struct lpfc_fcf_pri *fcf_pri; |
| 2134 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2135 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2136 | int ret; |
| 2137 | |
| 2138 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2139 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2140 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2141 | fcf_index, new_fcf_record->fip_priority, |
| 2142 | new_fcf_pri->fcf_rec.flag); |
| 2143 | spin_lock_irq(&phba->hbalock); |
| 2144 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2145 | list_del_init(&new_fcf_pri->list); |
| 2146 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2147 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2148 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2149 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2150 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2151 | new_fcf_pri->fcf_rec.fcf_index); |
| 2152 | goto out; |
| 2153 | } |
| 2154 | |
| 2155 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2156 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2157 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2158 | ret = 0; /* Empty rr list */ |
| 2159 | goto out; |
| 2160 | } |
| 2161 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2162 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2163 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2164 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2165 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2166 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2167 | /* fcfs_at_this_priority_level = 1; */ |
| 2168 | phba->fcf.eligible_fcf_cnt = 1; |
| 2169 | } else |
| 2170 | /* fcfs_at_this_priority_level++; */ |
| 2171 | phba->fcf.eligible_fcf_cnt++; |
| 2172 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2173 | new_fcf_pri->fcf_rec.fcf_index); |
| 2174 | goto out; |
| 2175 | } |
| 2176 | |
| 2177 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2178 | &phba->fcf.fcf_pri_list, list) { |
| 2179 | if (new_fcf_pri->fcf_rec.priority <= |
| 2180 | fcf_pri->fcf_rec.priority) { |
| 2181 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2182 | list_add(&new_fcf_pri->list, |
| 2183 | &phba->fcf.fcf_pri_list); |
| 2184 | else |
| 2185 | list_add(&new_fcf_pri->list, |
| 2186 | &((struct lpfc_fcf_pri *) |
| 2187 | fcf_pri->list.prev)->list); |
| 2188 | ret = 0; |
| 2189 | goto out; |
| 2190 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2191 | || new_fcf_pri->fcf_rec.priority < |
| 2192 | next_fcf_pri->fcf_rec.priority) { |
| 2193 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2194 | ret = 0; |
| 2195 | goto out; |
| 2196 | } |
| 2197 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2198 | continue; |
| 2199 | |
| 2200 | } |
| 2201 | ret = 1; |
| 2202 | out: |
| 2203 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2204 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2205 | spin_unlock_irq(&phba->hbalock); |
| 2206 | return ret; |
| 2207 | } |
| 2208 | |
| 2209 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2210 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2211 | * @phba: pointer to lpfc hba data structure. |
| 2212 | * @mboxq: pointer to mailbox object. |
| 2213 | * |
| 2214 | * This function iterates through all the fcf records available in |
| 2215 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2216 | * the FCF for discovery it registers the FCF record and kicks start |
| 2217 | * discovery. |
| 2218 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2219 | * use an FCF record which matches fabric name and mac address of the |
| 2220 | * currently used FCF record. |
| 2221 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2222 | * used by BOOT_BIOS. |
| 2223 | */ |
| 2224 | void |
| 2225 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2226 | { |
| 2227 | struct fcf_record *new_fcf_record; |
| 2228 | uint32_t boot_flag, addr_mode; |
| 2229 | uint16_t fcf_index, next_fcf_index; |
| 2230 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2231 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2232 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2233 | int rc; |
| 2234 | |
| 2235 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2236 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2237 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2238 | return; |
| 2239 | } |
| 2240 | |
| 2241 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2242 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2243 | &next_fcf_index); |
| 2244 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2245 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2246 | "2765 Mailbox command READ_FCF_RECORD " |
| 2247 | "failed to retrieve a FCF record.\n"); |
| 2248 | /* Let next new FCF event trigger fast failover */ |
| 2249 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2250 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2251 | spin_unlock_irq(&phba->hbalock); |
| 2252 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2253 | return; |
| 2254 | } |
| 2255 | |
| 2256 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2257 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2258 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2259 | |
| 2260 | /* Log the FCF record information if turned on */ |
| 2261 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2262 | next_fcf_index); |
| 2263 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2264 | /* |
| 2265 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2266 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2267 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2268 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2269 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2270 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2271 | bf_get(lpfc_fcf_record_fcf_index, |
| 2272 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2273 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2274 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2275 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2276 | bf_get(lpfc_fcf_record_fcf_index, |
| 2277 | new_fcf_record), |
| 2278 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2279 | new_fcf_record), |
| 2280 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2281 | new_fcf_record), |
| 2282 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2283 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2284 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2285 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2286 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2287 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2288 | phba->fcf.current_rec.fcf_indx) { |
| 2289 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2290 | "2862 FCF (x%x) matches property " |
| 2291 | "of in-use FCF (x%x)\n", |
| 2292 | bf_get(lpfc_fcf_record_fcf_index, |
| 2293 | new_fcf_record), |
| 2294 | phba->fcf.current_rec.fcf_indx); |
| 2295 | goto read_next_fcf; |
| 2296 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2297 | /* |
| 2298 | * In case the current in-use FCF record becomes |
| 2299 | * invalid/unavailable during FCF discovery that |
| 2300 | * was not triggered by fast FCF failover process, |
| 2301 | * treat it as fast FCF failover. |
| 2302 | */ |
| 2303 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2304 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2305 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2306 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2307 | "(x%x), enter FCF failover " |
| 2308 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2309 | phba->fcf.current_rec.fcf_indx); |
| 2310 | spin_lock_irq(&phba->hbalock); |
| 2311 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2312 | spin_unlock_irq(&phba->hbalock); |
| 2313 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2314 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2315 | LPFC_FCOE_FCF_GET_FIRST); |
| 2316 | return; |
| 2317 | } |
| 2318 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2319 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2320 | } else { |
| 2321 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2322 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2323 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2324 | if (rc) |
| 2325 | goto read_next_fcf; |
| 2326 | } |
| 2327 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2328 | /* |
| 2329 | * 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] | 2330 | * FCF record for the discovery. The condition that a rescan |
| 2331 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2332 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2333 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2334 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2335 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2336 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2337 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2338 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2339 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2340 | phba->fcf.current_rec.fcf_indx) { |
| 2341 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2342 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2343 | /* Stop FCF redisc wait timer */ |
| 2344 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2345 | phba); |
| 2346 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2347 | /* Fast failover, mark completed */ |
| 2348 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2349 | spin_unlock_irq(&phba->hbalock); |
| 2350 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2351 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2352 | "FCF (x%x), port_state:x%x, " |
| 2353 | "fc_flag:x%x\n", |
| 2354 | phba->fcf.current_rec.fcf_indx, |
| 2355 | phba->pport->port_state, |
| 2356 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2357 | goto out; |
| 2358 | } else |
| 2359 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2360 | "2863 New FCF (x%x) matches " |
| 2361 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2362 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2363 | new_fcf_record), |
| 2364 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2365 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2366 | /* |
| 2367 | * Read next FCF record from HBA searching for the matching |
| 2368 | * with in-use record only if not during the fast failover |
| 2369 | * period. In case of fast failover period, it shall try to |
| 2370 | * determine whether the FCF record just read should be the |
| 2371 | * next candidate. |
| 2372 | */ |
| 2373 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2374 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2375 | goto read_next_fcf; |
| 2376 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2377 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2378 | /* |
| 2379 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2380 | * period; otherwise, update on current FCF record. |
| 2381 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2382 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2383 | fcf_rec = &phba->fcf.failover_rec; |
| 2384 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2385 | fcf_rec = &phba->fcf.current_rec; |
| 2386 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2387 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2388 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2389 | * If the driver FCF record does not have boot flag |
| 2390 | * set and new hba fcf record has boot flag set, use |
| 2391 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2392 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2393 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2394 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2395 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2396 | "2837 Update current FCF record " |
| 2397 | "(x%x) with new FCF record (x%x)\n", |
| 2398 | fcf_rec->fcf_indx, |
| 2399 | bf_get(lpfc_fcf_record_fcf_index, |
| 2400 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2401 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2402 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2403 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2404 | goto read_next_fcf; |
| 2405 | } |
| 2406 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2407 | * If the driver FCF record has boot flag set and the |
| 2408 | * new hba FCF record does not have boot flag, read |
| 2409 | * the next FCF record. |
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 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2412 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2413 | goto read_next_fcf; |
| 2414 | } |
| 2415 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2416 | * If the new hba FCF record has lower priority value |
| 2417 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2418 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2419 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2420 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2421 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2422 | "2838 Update current FCF record " |
| 2423 | "(x%x) with new FCF record (x%x)\n", |
| 2424 | fcf_rec->fcf_indx, |
| 2425 | bf_get(lpfc_fcf_record_fcf_index, |
| 2426 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2427 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2428 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2429 | /* Reset running random FCF selection count */ |
| 2430 | phba->fcf.eligible_fcf_cnt = 1; |
| 2431 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2432 | /* Update running random FCF selection count */ |
| 2433 | phba->fcf.eligible_fcf_cnt++; |
| 2434 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2435 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2436 | if (select_new_fcf) { |
| 2437 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2438 | "2839 Update current FCF record " |
| 2439 | "(x%x) with new FCF record (x%x)\n", |
| 2440 | fcf_rec->fcf_indx, |
| 2441 | bf_get(lpfc_fcf_record_fcf_index, |
| 2442 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2443 | /* Choose the new FCF by random selection */ |
| 2444 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2445 | new_fcf_record, |
| 2446 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2447 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2448 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2449 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2450 | goto read_next_fcf; |
| 2451 | } |
| 2452 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2453 | * This is the first suitable FCF record, choose this record for |
| 2454 | * initial best-fit FCF. |
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 (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2457 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2458 | "2840 Update initial FCF candidate " |
| 2459 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2460 | bf_get(lpfc_fcf_record_fcf_index, |
| 2461 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2462 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2463 | addr_mode, vlan_id, (boot_flag ? |
| 2464 | BOOT_ENABLE : 0)); |
| 2465 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2466 | /* Setup initial running random FCF selection count */ |
| 2467 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2468 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2469 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2470 | goto read_next_fcf; |
| 2471 | |
| 2472 | read_next_fcf: |
| 2473 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2474 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2475 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2476 | /* |
| 2477 | * Case of FCF fast failover scan |
| 2478 | */ |
| 2479 | |
| 2480 | /* |
| 2481 | * It has not found any suitable FCF record, cancel |
| 2482 | * FCF scan inprogress, and do nothing |
| 2483 | */ |
| 2484 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2485 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2486 | "2782 No suitable FCF found: " |
| 2487 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2488 | phba->fcoe_eventtag_at_fcf_scan, |
| 2489 | bf_get(lpfc_fcf_record_fcf_index, |
| 2490 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2491 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2492 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2493 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2494 | spin_unlock_irq(&phba->hbalock); |
| 2495 | /* Unregister in-use FCF and rescan */ |
| 2496 | lpfc_printf_log(phba, KERN_INFO, |
| 2497 | LOG_FIP, |
| 2498 | "2864 On devloss tmo " |
| 2499 | "unreg in-use FCF and " |
| 2500 | "rescan FCF table\n"); |
| 2501 | lpfc_unregister_fcf_rescan(phba); |
| 2502 | return; |
| 2503 | } |
| 2504 | /* |
| 2505 | * Let next new FCF event trigger fast failover |
| 2506 | */ |
| 2507 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2508 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2509 | return; |
| 2510 | } |
| 2511 | /* |
| 2512 | * It has found a suitable FCF record that is not |
| 2513 | * the same as in-use FCF record, unregister the |
| 2514 | * in-use FCF record, replace the in-use FCF record |
| 2515 | * with the new FCF record, mark FCF fast failover |
| 2516 | * completed, and then start register the new FCF |
| 2517 | * record. |
| 2518 | */ |
| 2519 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2520 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2521 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2522 | |
| 2523 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2524 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2525 | "2842 Replace in-use FCF (x%x) " |
| 2526 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2527 | phba->fcf.current_rec.fcf_indx, |
| 2528 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2529 | memcpy(&phba->fcf.current_rec, |
| 2530 | &phba->fcf.failover_rec, |
| 2531 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2532 | /* |
| 2533 | * Mark the fast FCF failover rediscovery completed |
| 2534 | * and the start of the first round of the roundrobin |
| 2535 | * FCF failover. |
| 2536 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2537 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2538 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2539 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2540 | /* Register to the new FCF record */ |
| 2541 | lpfc_register_fcf(phba); |
| 2542 | } else { |
| 2543 | /* |
| 2544 | * In case of transaction period to fast FCF failover, |
| 2545 | * do nothing when search to the end of the FCF table. |
| 2546 | */ |
| 2547 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2548 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2549 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2550 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2551 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2552 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2553 | /* |
| 2554 | * In case the current in-use FCF record no |
| 2555 | * longer existed during FCF discovery that |
| 2556 | * was not triggered by fast FCF failover |
| 2557 | * process, treat it as fast FCF failover. |
| 2558 | */ |
| 2559 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2560 | "2841 In-use FCF record (x%x) " |
| 2561 | "not reported, entering fast " |
| 2562 | "FCF failover mode scanning.\n", |
| 2563 | phba->fcf.current_rec.fcf_indx); |
| 2564 | spin_lock_irq(&phba->hbalock); |
| 2565 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2566 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2567 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2568 | LPFC_FCOE_FCF_GET_FIRST); |
| 2569 | return; |
| 2570 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2571 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2572 | lpfc_register_fcf(phba); |
| 2573 | } |
| 2574 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2575 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2576 | return; |
| 2577 | |
| 2578 | out: |
| 2579 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2580 | lpfc_register_fcf(phba); |
| 2581 | |
| 2582 | return; |
| 2583 | } |
| 2584 | |
| 2585 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2586 | * 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] | 2587 | * @phba: pointer to lpfc hba data structure. |
| 2588 | * @mboxq: pointer to mailbox object. |
| 2589 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2590 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2591 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2592 | * performing the failover. If the FCF read back is not valid/available, it |
| 2593 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2594 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2595 | * newly read FCF record to the failover FCF record, unregister currently |
| 2596 | * registered FCF record, copy the failover FCF record to the current |
| 2597 | * FCF record, and then register the current FCF record before proceeding |
| 2598 | * to trying FLOGI on the new failover FCF. |
| 2599 | */ |
| 2600 | void |
| 2601 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2602 | { |
| 2603 | struct fcf_record *new_fcf_record; |
| 2604 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2605 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2606 | uint16_t current_fcf_index; |
| 2607 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2608 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2609 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2610 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2611 | if (phba->link_state < LPFC_LINK_UP) { |
| 2612 | spin_lock_irq(&phba->hbalock); |
| 2613 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2614 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2615 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2616 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2620 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2621 | &next_fcf_index); |
| 2622 | if (!new_fcf_record) { |
| 2623 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2624 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2625 | "failed to retrieve a FCF record. " |
| 2626 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2627 | phba->fcf.fcf_flag); |
| 2628 | lpfc_unregister_fcf_rescan(phba); |
| 2629 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2633 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2634 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2635 | |
| 2636 | /* Log the FCF record information if turned on */ |
| 2637 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2638 | next_fcf_index); |
| 2639 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2640 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2641 | if (!rc) { |
| 2642 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2643 | "2848 Remove ineligible FCF (x%x) from " |
| 2644 | "from roundrobin bmask\n", fcf_index); |
| 2645 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2646 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2647 | /* Perform next round of roundrobin FCF failover */ |
| 2648 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2649 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2650 | if (rc) |
| 2651 | goto out; |
| 2652 | goto error_out; |
| 2653 | } |
| 2654 | |
| 2655 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2656 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2657 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2658 | "FCF (x%x) back to FCF (x%x)\n", |
| 2659 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2660 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2661 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2662 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2663 | goto out; |
| 2664 | } |
| 2665 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2666 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2667 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2668 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2669 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2670 | spin_lock_irq(&phba->hbalock); |
| 2671 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2672 | new_fcf_record, addr_mode, vlan_id, |
| 2673 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2674 | spin_unlock_irq(&phba->hbalock); |
| 2675 | |
| 2676 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2677 | |
| 2678 | /* Unregister the current in-use FCF record */ |
| 2679 | lpfc_unregister_fcf(phba); |
| 2680 | |
| 2681 | /* Replace in-use record with the new record */ |
| 2682 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2683 | sizeof(struct lpfc_fcf_rec)); |
| 2684 | |
| 2685 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2686 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2687 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2688 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2689 | error_out: |
| 2690 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2691 | out: |
| 2692 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | /** |
| 2696 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2697 | * @phba: pointer to lpfc hba data structure. |
| 2698 | * @mboxq: pointer to mailbox object. |
| 2699 | * |
| 2700 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2701 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2702 | * failover when a new FCF event happened. If the FCF read back is |
| 2703 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2704 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2705 | */ |
| 2706 | void |
| 2707 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2708 | { |
| 2709 | struct fcf_record *new_fcf_record; |
| 2710 | uint32_t boot_flag, addr_mode; |
| 2711 | uint16_t fcf_index, next_fcf_index; |
| 2712 | uint16_t vlan_id; |
| 2713 | int rc; |
| 2714 | |
| 2715 | /* If link state is not up, no need to proceed */ |
| 2716 | if (phba->link_state < LPFC_LINK_UP) |
| 2717 | goto out; |
| 2718 | |
| 2719 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2720 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2721 | goto out; |
| 2722 | |
| 2723 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2724 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2725 | &next_fcf_index); |
| 2726 | if (!new_fcf_record) { |
| 2727 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2728 | "2767 Mailbox command READ_FCF_RECORD " |
| 2729 | "failed to retrieve a FCF record.\n"); |
| 2730 | goto out; |
| 2731 | } |
| 2732 | |
| 2733 | /* Check the connection list for eligibility */ |
| 2734 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2735 | &addr_mode, &vlan_id); |
| 2736 | |
| 2737 | /* Log the FCF record information if turned on */ |
| 2738 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2739 | next_fcf_index); |
| 2740 | |
| 2741 | if (!rc) |
| 2742 | goto out; |
| 2743 | |
| 2744 | /* Update the eligible FCF record index bmask */ |
| 2745 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2746 | |
| 2747 | 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] | 2748 | |
| 2749 | out: |
| 2750 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2751 | } |
| 2752 | |
| 2753 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2754 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2755 | * @phba: pointer to lpfc hba data structure. |
| 2756 | * @mboxq: pointer to mailbox data structure. |
| 2757 | * |
| 2758 | * This function handles completion of init vfi mailbox command. |
| 2759 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2760 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2761 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2762 | { |
| 2763 | struct lpfc_vport *vport = mboxq->vport; |
| 2764 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2765 | /* |
| 2766 | * VFI not supported on interface type 0, just do the flogi |
| 2767 | * Also continue if the VFI is in use - just use the same one. |
| 2768 | */ |
| 2769 | if (mboxq->u.mb.mbxStatus && |
| 2770 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2771 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2772 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2773 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2774 | LOG_MBOX, |
| 2775 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2776 | mboxq->u.mb.mbxStatus); |
| 2777 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2778 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2779 | return; |
| 2780 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2781 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2782 | lpfc_initial_flogi(vport); |
| 2783 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2784 | return; |
| 2785 | } |
| 2786 | |
| 2787 | /** |
| 2788 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2789 | * @vport: pointer to lpfc_vport data structure. |
| 2790 | * |
| 2791 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2792 | * VPI for the physical port. |
| 2793 | */ |
| 2794 | void |
| 2795 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2796 | { |
| 2797 | LPFC_MBOXQ_t *mboxq; |
| 2798 | int rc; |
| 2799 | struct lpfc_hba *phba = vport->phba; |
| 2800 | |
| 2801 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2802 | if (!mboxq) { |
| 2803 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2804 | LOG_MBOX, "2892 Failed to allocate " |
| 2805 | "init_vfi mailbox\n"); |
| 2806 | return; |
| 2807 | } |
| 2808 | lpfc_init_vfi(mboxq, vport); |
| 2809 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2810 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2811 | if (rc == MBX_NOT_FINISHED) { |
| 2812 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2813 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2814 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2819 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2820 | * @phba: pointer to lpfc hba data structure. |
| 2821 | * @mboxq: pointer to mailbox data structure. |
| 2822 | * |
| 2823 | * This function handles completion of init vpi mailbox command. |
| 2824 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2825 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2826 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2827 | { |
| 2828 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2829 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2830 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2831 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2832 | if (mboxq->u.mb.mbxStatus) { |
| 2833 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2834 | LOG_MBOX, |
| 2835 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2836 | mboxq->u.mb.mbxStatus); |
| 2837 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2838 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2839 | return; |
| 2840 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2841 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2842 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2843 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2844 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2845 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2846 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2847 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2848 | if (!ndlp) |
| 2849 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2850 | LOG_DISCOVERY, |
| 2851 | "2731 Cannot find fabric " |
| 2852 | "controller node\n"); |
| 2853 | else |
| 2854 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2855 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2856 | return; |
| 2857 | } |
| 2858 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2859 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2860 | lpfc_initial_fdisc(vport); |
| 2861 | else { |
| 2862 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2863 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2864 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2865 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2866 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2867 | return; |
| 2868 | } |
| 2869 | |
| 2870 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2871 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2872 | * @vport: pointer to lpfc_vport data structure. |
| 2873 | * |
| 2874 | * This function issue a init_vpi mailbox command to initialize |
| 2875 | * VPI for the vport. |
| 2876 | */ |
| 2877 | void |
| 2878 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2879 | { |
| 2880 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2881 | int rc, vpi; |
| 2882 | |
| 2883 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2884 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2885 | if (!vpi) { |
| 2886 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2887 | LOG_MBOX, |
| 2888 | "3303 Failed to obtain vport vpi\n"); |
| 2889 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2890 | return; |
| 2891 | } |
| 2892 | vport->vpi = vpi; |
| 2893 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2894 | |
| 2895 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2896 | if (!mboxq) { |
| 2897 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2898 | LOG_MBOX, "2607 Failed to allocate " |
| 2899 | "init_vpi mailbox\n"); |
| 2900 | return; |
| 2901 | } |
| 2902 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2903 | mboxq->vport = vport; |
| 2904 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2905 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2906 | if (rc == MBX_NOT_FINISHED) { |
| 2907 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2908 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2909 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2914 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2915 | * @phba: pointer to lpfc hba data structure. |
| 2916 | * |
| 2917 | * This function loops through the list of vports on the @phba and issues an |
| 2918 | * FDISC if possible. |
| 2919 | */ |
| 2920 | void |
| 2921 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2922 | { |
| 2923 | struct lpfc_vport **vports; |
| 2924 | int i; |
| 2925 | |
| 2926 | vports = lpfc_create_vport_work_array(phba); |
| 2927 | if (vports != NULL) { |
| 2928 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2929 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2930 | continue; |
| 2931 | /* There are no vpi for this vport */ |
| 2932 | if (vports[i]->vpi > phba->max_vpi) { |
| 2933 | lpfc_vport_set_state(vports[i], |
| 2934 | FC_VPORT_FAILED); |
| 2935 | continue; |
| 2936 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2937 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2938 | lpfc_vport_set_state(vports[i], |
| 2939 | FC_VPORT_LINKDOWN); |
| 2940 | continue; |
| 2941 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2942 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2943 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2944 | continue; |
| 2945 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2946 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2947 | lpfc_initial_fdisc(vports[i]); |
| 2948 | else { |
| 2949 | lpfc_vport_set_state(vports[i], |
| 2950 | FC_VPORT_NO_FABRIC_SUPP); |
| 2951 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2952 | LOG_ELS, |
| 2953 | "0259 No NPIV " |
| 2954 | "Fabric support\n"); |
| 2955 | } |
| 2956 | } |
| 2957 | } |
| 2958 | lpfc_destroy_vport_work_array(phba, vports); |
| 2959 | } |
| 2960 | |
| 2961 | void |
| 2962 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2963 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2964 | struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2965 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2966 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2967 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2968 | /* |
| 2969 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2970 | * error (except VFI in use) and continue with the discovery. |
| 2971 | */ |
| 2972 | if (mboxq->u.mb.mbxStatus && |
| 2973 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2974 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2975 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2976 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2977 | "2018 REG_VFI mbxStatus error x%x " |
| 2978 | "HBA state x%x\n", |
| 2979 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2980 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2981 | /* FLOGI failed, use loop map to make discovery list */ |
| 2982 | lpfc_disc_list_loopmap(vport); |
| 2983 | /* Start discovery */ |
| 2984 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2985 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2986 | } |
| 2987 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2988 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2989 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2990 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2991 | /* If the VFI is already registered, there is nothing else to do |
| 2992 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2993 | * we should drop through to set the port state to ready. |
| 2994 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2995 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2996 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2997 | vport->fc_flag & FC_PT2PT)) |
| 2998 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2999 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3000 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3001 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3002 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3003 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3004 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 3005 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3006 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3007 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3008 | /* In case SLI4 FC loopback test, we are ready */ |
| 3009 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 3010 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 3011 | phba->link_state = LPFC_HBA_READY; |
| 3012 | goto out_free_mem; |
| 3013 | } |
| 3014 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3015 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3016 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 3017 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 3018 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 3019 | vport->phba->alpa_map[0], |
| 3020 | phba->link_state, phba->fc_topology); |
| 3021 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3022 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 3023 | /* |
| 3024 | * For private loop or for NPort pt2pt, |
| 3025 | * just start discovery and we are done. |
| 3026 | */ |
| 3027 | if ((vport->fc_flag & FC_PT2PT) || |
| 3028 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 3029 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 3030 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3031 | /* Use loop map to make discovery list */ |
| 3032 | lpfc_disc_list_loopmap(vport); |
| 3033 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3034 | if (vport->fc_flag & FC_PT2PT) |
| 3035 | vport->port_state = LPFC_VPORT_READY; |
| 3036 | else |
| 3037 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3038 | } else { |
| 3039 | lpfc_start_fdiscs(phba); |
| 3040 | lpfc_do_scr_ns_plogi(phba, vport); |
| 3041 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3044 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3045 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3046 | if (dmabuf) { |
| 3047 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 3048 | kfree(dmabuf); |
| 3049 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3050 | return; |
| 3051 | } |
| 3052 | |
| 3053 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3054 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3056 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3057 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3058 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3059 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3060 | struct serv_parm *sp = &vport->fc_sparam; |
| 3061 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | |
| 3063 | /* Check for error */ |
| 3064 | if (mb->mbxStatus) { |
| 3065 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3066 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3067 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3068 | "hba state x%x>\n", |
| 3069 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | goto out; |
| 3072 | } |
| 3073 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3074 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3076 | |
| 3077 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3078 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3079 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3080 | |
| 3081 | phba->fc_edtov = ed_tov; |
| 3082 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3083 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3084 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3085 | phba->fc_ratov = FF_DEF_RATOV; |
| 3086 | } |
| 3087 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3088 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3089 | 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] | 3090 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3091 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3092 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3093 | } |
| 3094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3096 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3097 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | return; |
| 3099 | |
| 3100 | out: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3101 | pmb->ctx_buf = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3102 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3103 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3104 | lpfc_issue_clear_la(phba, vport); |
| 3105 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | return; |
| 3107 | } |
| 3108 | |
| 3109 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3110 | 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] | 3111 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3112 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3113 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3114 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3115 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3116 | struct lpfc_dmabuf *mp; |
| 3117 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3118 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3119 | uint32_t fc_flags = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3120 | unsigned long iflags; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3121 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3122 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3123 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3124 | |
| 3125 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3126 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3127 | case LPFC_LINK_SPEED_1GHZ: |
| 3128 | case LPFC_LINK_SPEED_2GHZ: |
| 3129 | case LPFC_LINK_SPEED_4GHZ: |
| 3130 | case LPFC_LINK_SPEED_8GHZ: |
| 3131 | case LPFC_LINK_SPEED_10GHZ: |
| 3132 | case LPFC_LINK_SPEED_16GHZ: |
| 3133 | case LPFC_LINK_SPEED_32GHZ: |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 3134 | case LPFC_LINK_SPEED_64GHZ: |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 3135 | case LPFC_LINK_SPEED_128GHZ: |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3136 | break; |
| 3137 | default: |
| 3138 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3139 | break; |
| 3140 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | } |
| 3142 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3143 | if (phba->fc_topology && |
| 3144 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3145 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3146 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3147 | phba->fc_topology, |
| 3148 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3149 | phba->fc_topology_changed = 1; |
| 3150 | } |
| 3151 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3152 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3153 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3155 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3156 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3157 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3159 | /* if npiv is enabled and this adapter supports npiv log |
| 3160 | * a message that npiv is not supported in this topology |
| 3161 | */ |
| 3162 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3163 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3164 | "1309 Link Up Event npiv not supported in loop " |
| 3165 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3166 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3167 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3168 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3170 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3171 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | |
| 3173 | if (i == 0) { |
| 3174 | phba->alpa_map[0] = 0; |
| 3175 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3176 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | int numalpa, j, k; |
| 3178 | union { |
| 3179 | uint8_t pamap[16]; |
| 3180 | struct { |
| 3181 | uint32_t wd1; |
| 3182 | uint32_t wd2; |
| 3183 | uint32_t wd3; |
| 3184 | uint32_t wd4; |
| 3185 | } pa; |
| 3186 | } un; |
| 3187 | numalpa = phba->alpa_map[0]; |
| 3188 | j = 0; |
| 3189 | while (j < numalpa) { |
| 3190 | memset(un.pamap, 0, 16); |
| 3191 | for (k = 1; j < numalpa; k++) { |
| 3192 | un.pamap[k - 1] = |
| 3193 | phba->alpa_map[j + 1]; |
| 3194 | j++; |
| 3195 | if (k == 16) |
| 3196 | break; |
| 3197 | } |
| 3198 | /* Link Up Event ALPA map */ |
| 3199 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3200 | KERN_WARNING, |
| 3201 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3202 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3203 | "ALPA map Data: x%x " |
| 3204 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3205 | un.pa.wd1, un.pa.wd2, |
| 3206 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3211 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3212 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3213 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3214 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3215 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3217 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3219 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3220 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3221 | if (fc_flags) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3222 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3223 | vport->fc_flag |= fc_flags; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3224 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3225 | } |
| 3226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3228 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3229 | if (!sparam_mbox) |
| 3230 | goto out; |
| 3231 | |
| 3232 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3233 | if (rc) { |
| 3234 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3235 | goto out; |
| 3236 | } |
| 3237 | sparam_mbox->vport = vport; |
| 3238 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3239 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3240 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3241 | mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3242 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3243 | kfree(mp); |
| 3244 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3245 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | } |
| 3247 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3248 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3249 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3250 | if (!cfglink_mbox) |
| 3251 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3252 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3254 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3255 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3256 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3257 | if (rc == MBX_NOT_FINISHED) { |
| 3258 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3259 | goto out; |
| 3260 | } |
| 3261 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3262 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3263 | /* |
| 3264 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3265 | * is phase 1 implementation that support FCF index 0 and driver |
| 3266 | * defaults. |
| 3267 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3268 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3269 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3270 | GFP_KERNEL); |
| 3271 | if (unlikely(!fcf_record)) { |
| 3272 | lpfc_printf_log(phba, KERN_ERR, |
| 3273 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3274 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3275 | "fcf record\n"); |
| 3276 | rc = -ENODEV; |
| 3277 | goto out; |
| 3278 | } |
| 3279 | |
| 3280 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3281 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3282 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3283 | if (unlikely(rc)) { |
| 3284 | lpfc_printf_log(phba, KERN_ERR, |
| 3285 | LOG_MBOX | LOG_SLI, |
| 3286 | "2013 Could not manually add FCF " |
| 3287 | "record 0, status %d\n", rc); |
| 3288 | rc = -ENODEV; |
| 3289 | kfree(fcf_record); |
| 3290 | goto out; |
| 3291 | } |
| 3292 | kfree(fcf_record); |
| 3293 | } |
| 3294 | /* |
| 3295 | * The driver is expected to do FIP/FCF. Call the port |
| 3296 | * and get the FCF Table. |
| 3297 | */ |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3298 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3299 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3300 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3301 | return; |
| 3302 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3303 | /* This is the initial FCF discovery scan */ |
| 3304 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3305 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3306 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3307 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3308 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3309 | LPFC_FCOE_FCF_GET_FIRST); |
| 3310 | if (rc) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3311 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3312 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3313 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3314 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3315 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3316 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3317 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3319 | |
| 3320 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3321 | out: |
| 3322 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3323 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3324 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3325 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3326 | lpfc_issue_clear_la(phba, vport); |
| 3327 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3331 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3332 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | uint32_t control; |
| 3334 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3337 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3338 | control = readl(phba->HCregaddr); |
| 3339 | control |= HC_LAINT_ENA; |
| 3340 | writel(control, phba->HCregaddr); |
| 3341 | readl(phba->HCregaddr); /* flush */ |
| 3342 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3343 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | } |
| 3345 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3346 | static void |
| 3347 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3348 | { |
| 3349 | lpfc_linkdown(phba); |
| 3350 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3351 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3352 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3353 | } |
| 3354 | |
| 3355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3357 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3359 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3360 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | */ |
| 3362 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3363 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3365 | struct lpfc_vport *vport = pmb->vport; |
| 3366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3367 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3368 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3369 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3370 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3371 | uint8_t attn_type; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3372 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3374 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3375 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 3376 | if (pring) |
| 3377 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | /* Check for error */ |
| 3380 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3381 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3382 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3383 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3385 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3386 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | } |
| 3388 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3389 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3390 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | |
| 3392 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3393 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3394 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3395 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3397 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3398 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3399 | spin_unlock_irqrestore(shost->host_lock, iflags); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3400 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3401 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3402 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3403 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | if (phba->fc_eventTag != 0) |
| 3405 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3406 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | |
| 3408 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3409 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3410 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3411 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3412 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3413 | else |
| 3414 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 3415 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3416 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3418 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3419 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3420 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3421 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3423 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3424 | "1306 Link Up Event in loop back mode " |
| 3425 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3426 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3427 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3428 | la), |
| 3429 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3430 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3431 | } else { |
| 3432 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3433 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3434 | "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] | 3435 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3436 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3437 | la), |
| 3438 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3439 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3440 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3441 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3442 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3443 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3445 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3446 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3448 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3449 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3450 | "1308 Link Down Event in loop back mode " |
| 3451 | "x%x received " |
| 3452 | "Data: x%x x%x x%x\n", |
| 3453 | la->eventTag, phba->fc_eventTag, |
| 3454 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3455 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3456 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3457 | "1313 Link Down UNEXP WWPN Event x%x received " |
| 3458 | "Data: x%x x%x x%x x%x x%x\n", |
| 3459 | la->eventTag, phba->fc_eventTag, |
| 3460 | phba->pport->port_state, vport->fc_flag, |
| 3461 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3462 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3463 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3464 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3465 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3466 | "Data: x%x x%x x%x x%x x%x\n", |
| 3467 | la->eventTag, phba->fc_eventTag, |
| 3468 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3469 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3470 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3471 | lpfc_mbx_issue_link_down(phba); |
| 3472 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3473 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3474 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3475 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3476 | phba->fc_stat.LinkDown++; |
| 3477 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3478 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3480 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3481 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3482 | lpfc_mbx_issue_link_down(phba); |
| 3483 | } else |
| 3484 | lpfc_enable_la(phba); |
| 3485 | |
| 3486 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3487 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3488 | "Data: x%x x%x x%x\n", |
| 3489 | la->eventTag, phba->fc_eventTag, |
| 3490 | phba->pport->port_state, vport->fc_flag); |
| 3491 | /* |
| 3492 | * The cmnd that triggered this will be waiting for this |
| 3493 | * signal. |
| 3494 | */ |
| 3495 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3496 | if (phba->wait_4_mlo_maint_flg) { |
| 3497 | phba->wait_4_mlo_maint_flg = 0; |
| 3498 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3499 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3500 | } |
| 3501 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3502 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3503 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3504 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3505 | lpfc_issue_clear_la(phba, vport); |
| 3506 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3507 | "1311 fa %d\n", |
| 3508 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | } |
| 3510 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3511 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3513 | kfree(mp); |
| 3514 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3515 | return; |
| 3516 | } |
| 3517 | |
| 3518 | /* |
| 3519 | * This routine handles processing a REG_LOGIN mailbox |
| 3520 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3521 | * as the completion routine when the command is |
| 3522 | * handed off to the SLI layer. |
| 3523 | */ |
| 3524 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3525 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3527 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3528 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 3529 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3530 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3532 | pmb->ctx_buf = NULL; |
| 3533 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3535 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3536 | "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 3537 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3538 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3539 | ndlp->nlp_usg_map, ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3540 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3541 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3542 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3543 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3544 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3545 | /* We rcvd a rscn after issuing this |
| 3546 | * mbox reg login, we may have cycled |
| 3547 | * back through the state and be |
| 3548 | * back at reg login state so this |
| 3549 | * mbox needs to be ignored becase |
| 3550 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3551 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3552 | */ |
| 3553 | spin_lock_irq(shost->host_lock); |
| 3554 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3555 | spin_unlock_irq(shost->host_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3556 | |
| 3557 | /* |
| 3558 | * We cannot leave the RPI registered because |
| 3559 | * if we go thru discovery again for this ndlp |
| 3560 | * a subsequent REG_RPI will fail. |
| 3561 | */ |
| 3562 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3563 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b7 | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | /* Call state machine */ |
| 3567 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3570 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3571 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3572 | /* decrement the node reference count held for this callback |
| 3573 | * function. |
| 3574 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3575 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | |
| 3577 | return; |
| 3578 | } |
| 3579 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3580 | static void |
| 3581 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3582 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3583 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3584 | struct lpfc_vport *vport = pmb->vport; |
| 3585 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3586 | |
| 3587 | switch (mb->mbxStatus) { |
| 3588 | case 0x0011: |
| 3589 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3590 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3591 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3592 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3594 | /* If VPI is busy, reset the HBA */ |
| 3595 | case 0x9700: |
| 3596 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3597 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3598 | vport->vpi, mb->mbxStatus); |
| 3599 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3600 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3601 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3602 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3603 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3604 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3605 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3606 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3607 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3608 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3609 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3610 | /* |
| 3611 | * This shost reference might have been taken at the beginning of |
| 3612 | * lpfc_vport_delete() |
| 3613 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3614 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3615 | scsi_host_put(shost); |
| 3616 | } |
| 3617 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3618 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3619 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3620 | { |
| 3621 | struct lpfc_hba *phba = vport->phba; |
| 3622 | LPFC_MBOXQ_t *mbox; |
| 3623 | int rc; |
| 3624 | |
| 3625 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3626 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3627 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | |
| 3629 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3630 | mbox->vport = vport; |
| 3631 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3632 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3633 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3634 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3635 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3636 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3637 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3638 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3639 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3640 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | static void |
| 3644 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3645 | { |
| 3646 | struct lpfc_vport *vport = pmb->vport; |
| 3647 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3648 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3649 | |
| 3650 | switch (mb->mbxStatus) { |
| 3651 | case 0x0011: |
| 3652 | case 0x9601: |
| 3653 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3654 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3655 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3656 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3657 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3658 | spin_lock_irq(shost->host_lock); |
| 3659 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3660 | spin_unlock_irq(shost->host_lock); |
| 3661 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3662 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3663 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3664 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3665 | if (phba->nvmet_support) |
| 3666 | lpfc_nvmet_update_targetport(phba); |
| 3667 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3668 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3669 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3670 | goto out; |
| 3671 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3672 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3673 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3674 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3675 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3676 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3677 | vport->num_disc_nodes = 0; |
| 3678 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3679 | if (vport->fc_npr_cnt) |
| 3680 | lpfc_els_disc_plogi(vport); |
| 3681 | |
| 3682 | if (!vport->num_disc_nodes) { |
| 3683 | spin_lock_irq(shost->host_lock); |
| 3684 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3685 | spin_unlock_irq(shost->host_lock); |
| 3686 | lpfc_can_disctmo(vport); |
| 3687 | } |
| 3688 | vport->port_state = LPFC_VPORT_READY; |
| 3689 | |
| 3690 | out: |
| 3691 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3692 | return; |
| 3693 | } |
| 3694 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3695 | /** |
| 3696 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3697 | * @phba: pointer to lpfc hba data structure. |
| 3698 | * |
| 3699 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3700 | * the list of static vports to be created. The function create vports |
| 3701 | * based on the information returned from the HBA. |
| 3702 | **/ |
| 3703 | void |
| 3704 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3705 | { |
| 3706 | LPFC_MBOXQ_t *pmb = NULL; |
| 3707 | MAILBOX_t *mb; |
| 3708 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3709 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3710 | struct fc_vport_identifiers vport_id; |
| 3711 | struct fc_vport *new_fc_vport; |
| 3712 | struct Scsi_Host *shost; |
| 3713 | struct lpfc_vport *vport; |
| 3714 | uint16_t offset = 0; |
| 3715 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3716 | struct lpfc_dmabuf *mp; |
| 3717 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3718 | |
| 3719 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3720 | if (!pmb) { |
| 3721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3722 | "0542 lpfc_create_static_vport failed to" |
| 3723 | " allocate mailbox memory\n"); |
| 3724 | return; |
| 3725 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3726 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3727 | mb = &pmb->u.mb; |
| 3728 | |
| 3729 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3730 | if (!vport_info) { |
| 3731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3732 | "0543 lpfc_create_static_vport failed to" |
| 3733 | " allocate vport_info\n"); |
| 3734 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3735 | return; |
| 3736 | } |
| 3737 | |
| 3738 | vport_buff = (uint8_t *) vport_info; |
| 3739 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3740 | /* free dma buffer from previous round */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3741 | if (pmb->ctx_buf) { |
| 3742 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3743 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3744 | kfree(mp); |
| 3745 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3746 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3747 | goto out; |
| 3748 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3749 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3750 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3751 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3752 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3753 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3754 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3755 | "0544 lpfc_create_static_vport failed to" |
| 3756 | " issue dump mailbox command ret 0x%x " |
| 3757 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3758 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3759 | goto out; |
| 3760 | } |
| 3761 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3762 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3763 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3764 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3765 | if (byte_count > sizeof(struct static_vport_info) - |
| 3766 | offset) |
| 3767 | byte_count = sizeof(struct static_vport_info) |
| 3768 | - offset; |
| 3769 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3770 | offset += byte_count; |
| 3771 | } else { |
| 3772 | if (mb->un.varDmp.word_cnt > |
| 3773 | sizeof(struct static_vport_info) - offset) |
| 3774 | mb->un.varDmp.word_cnt = |
| 3775 | sizeof(struct static_vport_info) |
| 3776 | - offset; |
| 3777 | byte_count = mb->un.varDmp.word_cnt; |
| 3778 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3779 | vport_buff + offset, |
| 3780 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3781 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3782 | offset += byte_count; |
| 3783 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3784 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3785 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3786 | offset < sizeof(struct static_vport_info)); |
| 3787 | |
| 3788 | |
| 3789 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3790 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3791 | != VPORT_INFO_REV)) { |
| 3792 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3793 | "0545 lpfc_create_static_vport bad" |
| 3794 | " information header 0x%x 0x%x\n", |
| 3795 | le32_to_cpu(vport_info->signature), |
| 3796 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3797 | |
| 3798 | goto out; |
| 3799 | } |
| 3800 | |
| 3801 | shost = lpfc_shost_from_vport(phba->pport); |
| 3802 | |
| 3803 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3804 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3805 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3806 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3807 | if (!vport_id.port_name || !vport_id.node_name) |
| 3808 | continue; |
| 3809 | |
| 3810 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3811 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3812 | vport_id.disable = false; |
| 3813 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3814 | |
| 3815 | if (!new_fc_vport) { |
| 3816 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3817 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3818 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3819 | continue; |
| 3820 | } |
| 3821 | |
| 3822 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3823 | vport->vport_flag |= STATIC_VPORT; |
| 3824 | } |
| 3825 | |
| 3826 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3827 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3828 | if (mbx_wait_rc != MBX_TIMEOUT) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3829 | if (pmb->ctx_buf) { |
| 3830 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3831 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3832 | kfree(mp); |
| 3833 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3834 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3835 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3836 | |
| 3837 | return; |
| 3838 | } |
| 3839 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | /* |
| 3841 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3842 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3843 | * as the completion routine when the command is |
| 3844 | * handed off to the SLI layer. |
| 3845 | */ |
| 3846 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3849 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3850 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3851 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3853 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3855 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 3856 | pmb->ctx_ndlp = NULL; |
| 3857 | pmb->ctx_buf = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3858 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3861 | "0258 Register Fabric login error: 0x%x\n", |
| 3862 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3864 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3865 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3867 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3868 | /* FLOGI failed, use loop map to make discovery list */ |
| 3869 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3871 | /* Start discovery */ |
| 3872 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3873 | /* Decrement the reference count to ndlp after the |
| 3874 | * reference to the ndlp are done. |
| 3875 | */ |
| 3876 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3877 | return; |
| 3878 | } |
| 3879 | |
| 3880 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3881 | /* Decrement the reference count to ndlp after the reference |
| 3882 | * to the ndlp are done. |
| 3883 | */ |
| 3884 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | return; |
| 3886 | } |
| 3887 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3888 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3889 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3890 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3892 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3894 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3895 | /* when physical port receive logo donot start |
| 3896 | * vport discovery */ |
| 3897 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3898 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3899 | else { |
| 3900 | shost = lpfc_shost_from_vport(vport); |
| 3901 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3902 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3903 | spin_unlock_irq(shost->host_lock); |
| 3904 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3905 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3909 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3910 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3911 | |
| 3912 | /* Drop the reference count from the mbox at the end after |
| 3913 | * all the current reference to the ndlp have been done. |
| 3914 | */ |
| 3915 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | return; |
| 3917 | } |
| 3918 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3919 | /* |
| 3920 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3921 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3922 | */ |
| 3923 | int |
| 3924 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3925 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3926 | /* Good status, issue CT Request to NameServer */ |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3927 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3928 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3929 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3930 | /* Cannot issue NameServer FCP Query, so finish up |
| 3931 | * discovery |
| 3932 | */ |
| 3933 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3934 | "0604 %s FC TYPE %x %s\n", |
| 3935 | "Failed to issue GID_FT to ", |
| 3936 | FC_TYPE_FCP, |
| 3937 | "Finishing discovery."); |
| 3938 | return 0; |
| 3939 | } |
| 3940 | vport->gidft_inp++; |
| 3941 | } |
| 3942 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3943 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3944 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3945 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 3946 | /* Cannot issue NameServer NVME Query, so finish up |
| 3947 | * discovery |
| 3948 | */ |
| 3949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3950 | "0605 %s FC_TYPE %x %s %d\n", |
| 3951 | "Failed to issue GID_FT to ", |
| 3952 | FC_TYPE_NVME, |
| 3953 | "Finishing discovery: gidftinp ", |
| 3954 | vport->gidft_inp); |
| 3955 | if (vport->gidft_inp == 0) |
| 3956 | return 0; |
| 3957 | } else |
| 3958 | vport->gidft_inp++; |
| 3959 | } |
| 3960 | return vport->gidft_inp; |
| 3961 | } |
| 3962 | |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 3963 | /** |
| 3964 | * lpfc_issue_gidpt - issue a GID_PT for all N_Ports |
| 3965 | * @vport: The virtual port for which this call is being executed. |
| 3966 | * |
| 3967 | * This routine will issue a GID_PT to get a list of all N_Ports |
| 3968 | * |
| 3969 | * Return value : |
| 3970 | * 0 - Failure to issue a GID_PT |
| 3971 | * 1 - GID_PT issued |
| 3972 | **/ |
| 3973 | int |
| 3974 | lpfc_issue_gidpt(struct lpfc_vport *vport) |
| 3975 | { |
| 3976 | /* Good status, issue CT Request to NameServer */ |
| 3977 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) { |
| 3978 | /* Cannot issue NameServer FCP Query, so finish up |
| 3979 | * discovery |
| 3980 | */ |
| 3981 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3982 | "0606 %s Port TYPE %x %s\n", |
| 3983 | "Failed to issue GID_PT to ", |
| 3984 | GID_PT_N_PORT, |
| 3985 | "Finishing discovery."); |
| 3986 | return 0; |
| 3987 | } |
| 3988 | vport->gidft_inp++; |
| 3989 | return 1; |
| 3990 | } |
| 3991 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | /* |
| 3993 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3994 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3995 | * as the completion routine when the command is |
| 3996 | * handed off to the SLI layer. |
| 3997 | */ |
| 3998 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4001 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4002 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4003 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4006 | pmb->ctx_buf = NULL; |
| 4007 | pmb->ctx_ndlp = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4008 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4011 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4012 | "0260 Register NameServer error: 0x%x\n", |
| 4013 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4014 | |
| 4015 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4016 | /* decrement the node reference count held for this |
| 4017 | * callback function. |
| 4018 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4019 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4021 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4022 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4023 | |
| 4024 | /* If no other thread is using the ndlp, free it */ |
| 4025 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4027 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4028 | /* |
| 4029 | * RegLogin failed, use loop map to make discovery |
| 4030 | * list |
| 4031 | */ |
| 4032 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4034 | /* Start discovery */ |
| 4035 | lpfc_disc_start(vport); |
| 4036 | return; |
| 4037 | } |
| 4038 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | return; |
| 4040 | } |
| 4041 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4042 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4043 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4044 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4046 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4047 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4048 | "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", |
| 4049 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4050 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4051 | ndlp->nlp_usg_map, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4053 | if (vport->port_state < LPFC_VPORT_READY) { |
| 4054 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4055 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 4056 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 4057 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 4058 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4059 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4060 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4061 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4062 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 4063 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4064 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4065 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4066 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 4067 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4068 | |
| 4069 | /* Issue SCR just before NameServer GID_FT Query */ |
| 4070 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | } |
| 4072 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4073 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4074 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4077 | /* |
| 4078 | * At this point in time we may need to wait for multiple |
| 4079 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 4080 | * |
| 4081 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4082 | * callback function. |
| 4083 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4084 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4086 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | |
| 4089 | return; |
| 4090 | } |
| 4091 | |
| 4092 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4095 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4096 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | struct lpfc_rport_data *rdata; |
| 4098 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4101 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4102 | return; |
| 4103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4105 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4106 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | rport_ids.port_id = ndlp->nlp_DID; |
| 4108 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4110 | /* |
| 4111 | * We leave our node pointer in rport->dd_data when we unregister a |
| 4112 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 4113 | * rport->dd_data points. So, if we're reusing a previously |
| 4114 | * registered port, drop the reference that we took the last time we |
| 4115 | * registered the port. |
| 4116 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4117 | rport = ndlp->rport; |
| 4118 | if (rport) { |
| 4119 | rdata = rport->dd_data; |
| 4120 | /* break the link before dropping the ref */ |
| 4121 | ndlp->rport = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4122 | if (rdata) { |
| 4123 | if (rdata->pnode == ndlp) |
| 4124 | lpfc_nlp_put(ndlp); |
| 4125 | rdata->pnode = NULL; |
| 4126 | } |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4127 | /* drop reference for earlier registeration */ |
| 4128 | put_device(&rport->dev); |
| 4129 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4130 | |
| 4131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 4132 | "rport add: did:x%x flg:x%x type x%x", |
| 4133 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4134 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4135 | /* Don't add the remote port if unloading. */ |
| 4136 | if (vport->load_flag & FC_UNLOADING) |
| 4137 | return; |
| 4138 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4139 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4140 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4142 | "Warning: fc_remote_port_add failed\n"); |
| 4143 | return; |
| 4144 | } |
| 4145 | |
| 4146 | /* initialize static port data */ |
| 4147 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4148 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4150 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4151 | |
| 4152 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4153 | rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4154 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4155 | rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; |
| 4156 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) |
| 4157 | rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; |
| 4158 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4159 | rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; |
| 4160 | if (ndlp->nlp_type & NLP_NVME_DISCOVERY) |
| 4161 | rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4162 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4163 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4164 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4165 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4166 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4167 | "3183 rport register x%06x, rport %p role x%x\n", |
| 4168 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 4169 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4170 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4171 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4172 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4173 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4174 | return; |
| 4175 | } |
| 4176 | |
| 4177 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4179 | { |
| 4180 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4181 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4182 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4183 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4184 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4185 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4186 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4187 | "rport delete: did:x%x flg:x%x type x%x", |
| 4188 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4189 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4190 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4191 | "3184 rport unregister x%06x, rport %p\n", |
| 4192 | ndlp->nlp_DID, rport); |
| 4193 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4194 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4195 | |
| 4196 | return; |
| 4197 | } |
| 4198 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4199 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4200 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4201 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 4203 | unsigned long iflags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4204 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 4205 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4206 | switch (state) { |
| 4207 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4209 | break; |
| 4210 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4212 | break; |
| 4213 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4214 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4215 | break; |
| 4216 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4217 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4218 | break; |
| 4219 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4220 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4221 | break; |
| 4222 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4223 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4224 | break; |
| 4225 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4226 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4227 | break; |
| 4228 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4229 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4230 | vport->fc_npr_cnt = 0; |
| 4231 | else |
| 4232 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4233 | break; |
| 4234 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame^] | 4235 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4236 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4237 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4238 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4239 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4240 | int old_state, int new_state) |
| 4241 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4243 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4244 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4245 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4246 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4247 | } |
| 4248 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4249 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4250 | if (new_state == NLP_STE_NPR_NODE) |
| 4251 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4253 | /* FCP and NVME Transport interface */ |
| 4254 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4255 | old_state == NLP_STE_UNMAPPED_NODE)) { |
| 4256 | if (ndlp->rport) { |
| 4257 | vport->phba->nport_event_cnt++; |
| 4258 | lpfc_unregister_remote_port(ndlp); |
| 4259 | } |
| 4260 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4261 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4262 | vport->phba->nport_event_cnt++; |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4263 | if (vport->phba->nvmet_support == 0) { |
| 4264 | /* Start devloss if target. */ |
| 4265 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4266 | lpfc_nvme_unregister_port(vport, ndlp); |
| 4267 | } else { |
James Smart | 6599e12 | 2017-06-01 21:07:00 -0700 | [diff] [blame] | 4268 | /* NVMET has no upcall. */ |
| 4269 | lpfc_nlp_put(ndlp); |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4270 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4271 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4272 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4274 | /* FCP and NVME Transport interfaces */ |
| 4275 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4276 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4277 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 01a8aed | 2018-09-10 10:30:41 -0700 | [diff] [blame] | 4278 | if (ndlp->nlp_fc4_type || |
James Smart | 92721c3 | 2017-06-01 21:06:59 -0700 | [diff] [blame] | 4279 | ndlp->nlp_DID == Fabric_DID || |
| 4280 | ndlp->nlp_DID == NameServer_DID || |
| 4281 | ndlp->nlp_DID == FDMI_DID) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4282 | vport->phba->nport_event_cnt++; |
| 4283 | /* |
| 4284 | * Tell the fc transport about the port, if we haven't |
| 4285 | * already. If we have, and it's a scsi entity, be |
| 4286 | */ |
| 4287 | lpfc_register_remote_port(vport, ndlp); |
| 4288 | } |
| 4289 | /* Notify the NVME transport of this new rport. */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 4290 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
| 4291 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4292 | if (vport->phba->nvmet_support == 0) { |
| 4293 | /* Register this rport with the transport. |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4294 | * Only NVME Target Rports are registered with |
| 4295 | * the transport. |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4296 | */ |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4297 | if (ndlp->nlp_type & NLP_NVME_TARGET) { |
| 4298 | vport->phba->nport_event_cnt++; |
| 4299 | lpfc_nvme_register_port(vport, ndlp); |
| 4300 | } |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4301 | } else { |
| 4302 | /* Just take an NDLP ref count since the |
| 4303 | * target does not register rports. |
| 4304 | */ |
| 4305 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4306 | } |
| 4307 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4308 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4309 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4310 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4311 | (vport->stat_data_enabled)) { |
| 4312 | /* |
| 4313 | * A new target is discovered, if there is no buffer for |
| 4314 | * statistical data collection allocate buffer. |
| 4315 | */ |
| 4316 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4317 | sizeof(struct lpfc_scsicmd_bkt), |
| 4318 | GFP_KERNEL); |
| 4319 | |
| 4320 | if (!ndlp->lat_data) |
| 4321 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4322 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4323 | "allocate statistical data buffer DID " |
| 4324 | "0x%x\n", ndlp->nlp_DID); |
| 4325 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4326 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4327 | * If the node just added to Mapped list was an FCP target, |
| 4328 | * but the remote port registration failed or assigned a target |
| 4329 | * id outside the presentable range - move the node to the |
| 4330 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4331 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4332 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4333 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4334 | (!ndlp->rport || |
| 4335 | ndlp->rport->scsi_target_id == -1 || |
| 4336 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4338 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | spin_unlock_irq(shost->host_lock); |
| 4340 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4342 | } |
| 4343 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4344 | static char * |
| 4345 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4346 | { |
| 4347 | static char *states[] = { |
| 4348 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4349 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4350 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4351 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4352 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4353 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4354 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4355 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4356 | [NLP_STE_NPR_NODE] = "NPR", |
| 4357 | }; |
| 4358 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4359 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4360 | strlcpy(buffer, states[state], size); |
| 4361 | else |
| 4362 | snprintf(buffer, size, "unknown (%d)", state); |
| 4363 | return buffer; |
| 4364 | } |
| 4365 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4366 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4368 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4369 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4371 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4372 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4373 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4374 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4375 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4376 | ndlp->nlp_DID, |
| 4377 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4378 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4379 | |
| 4380 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4381 | "node statechg did:x%x old:%d ste:%d", |
| 4382 | ndlp->nlp_DID, old_state, state); |
| 4383 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4384 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4385 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4387 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4388 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4389 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4390 | } |
| 4391 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4392 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4393 | spin_lock_irq(shost->host_lock); |
| 4394 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4395 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4396 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4397 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4398 | |
| 4399 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | lpfc_nlp_counters(vport, state, 1); |
| 4401 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4405 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4406 | { |
| 4407 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4408 | |
| 4409 | if (list_empty(&ndlp->nlp_listp)) { |
| 4410 | spin_lock_irq(shost->host_lock); |
| 4411 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4412 | spin_unlock_irq(shost->host_lock); |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4417 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4418 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4420 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4421 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4422 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4423 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4424 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4425 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4426 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4427 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4428 | NLP_STE_UNUSED_NODE); |
| 4429 | } |
| 4430 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4431 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4432 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4433 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4434 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4435 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4436 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4437 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4438 | NLP_STE_UNUSED_NODE); |
| 4439 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4441 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4442 | * @vport: Pointer to Virtual Port object. |
| 4443 | * @ndlp: Pointer to FC node object. |
| 4444 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4445 | * |
| 4446 | * This function is always called when node object need to be initialized. |
| 4447 | * It initializes all the fields of the node object. Although the reference |
| 4448 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4449 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4450 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4451 | * the final release of ndlp is determined by its reference count. And, the |
| 4452 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4453 | **/ |
| 4454 | static inline void |
| 4455 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4456 | uint32_t did) |
| 4457 | { |
| 4458 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4459 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4460 | timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4461 | ndlp->nlp_DID = did; |
| 4462 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4463 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4464 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4465 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4466 | kref_init(&ndlp->kref); |
| 4467 | NLP_INT_NODE_ACT(ndlp); |
| 4468 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4469 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4470 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4471 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4472 | |
| 4473 | struct lpfc_nodelist * |
| 4474 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4475 | int state) |
| 4476 | { |
| 4477 | struct lpfc_hba *phba = vport->phba; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4478 | uint32_t did, flag; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4479 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4480 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4481 | int rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4482 | uint32_t defer_did = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4483 | |
| 4484 | if (!ndlp) |
| 4485 | return NULL; |
| 4486 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4487 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4488 | if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR) |
| 4489 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 4490 | else |
| 4491 | rpi = ndlp->nlp_rpi; |
| 4492 | |
| 4493 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 4494 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4495 | "0359 %s: ndlp:x%px " |
| 4496 | "usgmap:x%x refcnt:%d FAILED RPI " |
| 4497 | " ALLOC\n", |
| 4498 | __func__, |
| 4499 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4500 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4501 | return NULL; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4502 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4505 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4506 | /* The ndlp should not be in memory free mode */ |
| 4507 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4508 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4509 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4510 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4511 | "usgmap:x%x refcnt:%d\n", |
| 4512 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4513 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4514 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4515 | } |
| 4516 | /* The ndlp should not already be in active mode */ |
| 4517 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4518 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4519 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4520 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4521 | "usgmap:x%x refcnt:%d\n", |
| 4522 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4523 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4524 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4525 | } |
| 4526 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4527 | /* First preserve the orginal DID, xri_bitmap and some flags */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4528 | did = ndlp->nlp_DID; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4529 | flag = (ndlp->nlp_flag & NLP_UNREG_INP); |
| 4530 | if (flag & NLP_UNREG_INP) |
| 4531 | defer_did = ndlp->nlp_defer_did; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4532 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4533 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4534 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4535 | /* Zero ndlp except of ndlp linked list pointer */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4536 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4537 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4538 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4539 | /* Next reinitialize and restore saved objects */ |
| 4540 | lpfc_initialize_node(vport, ndlp, did); |
| 4541 | ndlp->nlp_flag |= flag; |
| 4542 | if (flag & NLP_UNREG_INP) |
| 4543 | ndlp->nlp_defer_did = defer_did; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4544 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4545 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4546 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4547 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4548 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4549 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4550 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4551 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4552 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4553 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4554 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4555 | ndlp->nlp_usg_map, ndlp); |
| 4556 | } |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4557 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4558 | |
| 4559 | if (state != NLP_STE_UNUSED_NODE) |
| 4560 | lpfc_nlp_set_state(vport, ndlp, state); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4561 | else |
| 4562 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4563 | "0013 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4564 | "map:%x x%px STATE=UNUSED\n", |
| 4565 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4566 | ndlp->nlp_flag, |
| 4567 | kref_read(&ndlp->kref), |
| 4568 | ndlp->nlp_usg_map, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4569 | |
| 4570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4571 | "node enable: did:x%x", |
| 4572 | ndlp->nlp_DID, 0, 0); |
| 4573 | return ndlp; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4574 | |
| 4575 | free_rpi: |
| 4576 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4577 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 4578 | return NULL; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4583 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4584 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4585 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4586 | * 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] | 4587 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4588 | * until ALL other outstanding threads have completed. We check |
| 4589 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4590 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4591 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4592 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4593 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4594 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4595 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4596 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4597 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4598 | |
| 4599 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4600 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /* |
| 4604 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4605 | */ |
| 4606 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4608 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4609 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4610 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | uint32_t tmo; |
| 4612 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4614 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4615 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4616 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4617 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4618 | * FC spec states we need 3 * ratov for CT requests |
| 4619 | */ |
| 4620 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4623 | |
| 4624 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4625 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4626 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4627 | tmo, vport->port_state, vport->fc_flag); |
| 4628 | } |
| 4629 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4630 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | spin_lock_irq(shost->host_lock); |
| 4632 | vport->fc_flag |= FC_DISC_TMO; |
| 4633 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | |
| 4635 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4636 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4637 | "0247 Start Discovery Timer state x%x " |
| 4638 | "Data: x%x x%lx x%x x%x\n", |
| 4639 | vport->port_state, tmo, |
| 4640 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4641 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | |
| 4643 | return; |
| 4644 | } |
| 4645 | |
| 4646 | /* |
| 4647 | * Cancel rescue timer for Discovery / RSCN handling |
| 4648 | */ |
| 4649 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4650 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4652 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4653 | unsigned long iflags; |
| 4654 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4655 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4656 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4657 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4658 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4660 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4661 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4662 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4663 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4664 | del_timer_sync(&vport->fc_disctmo); |
| 4665 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4666 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4667 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4671 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4672 | "0248 Cancel Discovery Timer state x%x " |
| 4673 | "Data: x%x x%x x%x\n", |
| 4674 | vport->port_state, vport->fc_flag, |
| 4675 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4676 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | /* |
| 4680 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4681 | * Return true if iocb matches the specified nport |
| 4682 | */ |
| 4683 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4685 | struct lpfc_sli_ring *pring, |
| 4686 | struct lpfc_iocbq *iocb, |
| 4687 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4688 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4690 | struct lpfc_vport *vport = ndlp->vport; |
| 4691 | |
| 4692 | if (iocb->vport != vport) |
| 4693 | return 0; |
| 4694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4695 | if (pring->ringno == LPFC_ELS_RING) { |
| 4696 | switch (icmd->ulpCommand) { |
| 4697 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4698 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4699 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4700 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4701 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4702 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4703 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4704 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | case CMD_XMIT_ELS_RSP64_CX: |
| 4706 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4707 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4708 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4710 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | /* Skip match check if waiting to relogin to FCP target */ |
| 4712 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4713 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4714 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | } |
| 4716 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4717 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4719 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4720 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | } |
| 4722 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4723 | static void |
| 4724 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4725 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4726 | struct list_head *dequeue_list) |
| 4727 | { |
| 4728 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4729 | |
| 4730 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4731 | /* Check to see if iocb matches the nport */ |
| 4732 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4733 | /* match, dequeue */ |
| 4734 | list_move_tail(&iocb->list, dequeue_list); |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | static void |
| 4739 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4740 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4741 | { |
| 4742 | struct lpfc_sli *psli = &phba->sli; |
| 4743 | uint32_t i; |
| 4744 | |
| 4745 | spin_lock_irq(&phba->hbalock); |
| 4746 | for (i = 0; i < psli->num_rings; i++) |
| 4747 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4748 | dequeue_list); |
| 4749 | spin_unlock_irq(&phba->hbalock); |
| 4750 | } |
| 4751 | |
| 4752 | static void |
| 4753 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4754 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4755 | { |
| 4756 | struct lpfc_sli_ring *pring; |
| 4757 | struct lpfc_queue *qp = NULL; |
| 4758 | |
| 4759 | spin_lock_irq(&phba->hbalock); |
| 4760 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4761 | pring = qp->pring; |
| 4762 | if (!pring) |
| 4763 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4764 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4765 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4766 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4767 | } |
| 4768 | spin_unlock_irq(&phba->hbalock); |
| 4769 | } |
| 4770 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4771 | /* |
| 4772 | * Free resources / clean up outstanding I/Os |
| 4773 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4774 | */ |
| 4775 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4776 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4778 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4779 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4780 | lpfc_fabric_abort_nport(ndlp); |
| 4781 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | /* |
| 4783 | * Everything that matches on txcmplq will be returned |
| 4784 | * by firmware with a no rpi error. |
| 4785 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4786 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4787 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4788 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4789 | else |
| 4790 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4792 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4793 | /* Cancel all the IOCBs from the completions list */ |
| 4794 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4795 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4796 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4797 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4798 | } |
| 4799 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4800 | /** |
| 4801 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4802 | * @phba: Pointer to HBA context object. |
| 4803 | * @pmb: Pointer to mailbox object. |
| 4804 | * |
| 4805 | * This function will issue an ELS LOGO command after completing |
| 4806 | * the UNREG_RPI. |
| 4807 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4808 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4809 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4810 | { |
| 4811 | struct lpfc_vport *vport = pmb->vport; |
| 4812 | struct lpfc_nodelist *ndlp; |
| 4813 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4814 | ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4815 | if (!ndlp) |
| 4816 | return; |
| 4817 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4818 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4819 | |
| 4820 | /* Check to see if there are any deferred events to process */ |
| 4821 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 4822 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
| 4823 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4824 | "1434 UNREG cmpl deferred logo x%x " |
| 4825 | "on NPort x%x Data: x%x %p\n", |
| 4826 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4827 | ndlp->nlp_defer_did, ndlp); |
| 4828 | |
| 4829 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 4830 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 4831 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4832 | } else { |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4833 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 4834 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 4835 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 4836 | } |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4837 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4838 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4839 | } |
| 4840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | /* |
| 4842 | * Free rpi associated with LPFC_NODELIST entry. |
| 4843 | * This routine is called from lpfc_freenode(), when we are removing |
| 4844 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4845 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4846 | * to the remote NPort. In addition, it is called after we receive |
| 4847 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4848 | * we are waiting to PLOGI back to the remote NPort. |
| 4849 | */ |
| 4850 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4853 | struct lpfc_hba *phba = vport->phba; |
| 4854 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4855 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4856 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4858 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4859 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4860 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 4861 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4862 | "3366 RPI x%x needs to be " |
| 4863 | "unregistered nlp_flag x%x " |
| 4864 | "did x%x\n", |
| 4865 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4866 | ndlp->nlp_DID); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4867 | |
| 4868 | /* If there is already an UNREG in progress for this ndlp, |
| 4869 | * no need to queue up another one. |
| 4870 | */ |
| 4871 | if (ndlp->nlp_flag & NLP_UNREG_INP) { |
| 4872 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4873 | "1436 unreg_rpi SKIP UNREG x%x on " |
| 4874 | "NPort x%x deferred x%x flg x%x " |
| 4875 | "Data: %p\n", |
| 4876 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4877 | ndlp->nlp_defer_did, |
| 4878 | ndlp->nlp_flag, ndlp); |
| 4879 | goto out; |
| 4880 | } |
| 4881 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4883 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4884 | /* SLI4 ports require the physical rpi value. */ |
| 4885 | rpi = ndlp->nlp_rpi; |
| 4886 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4887 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4888 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4889 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4890 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4891 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4892 | mbox->ctx_ndlp = ndlp; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4893 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4894 | } else { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4895 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4896 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4897 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 719162b | 2018-12-10 19:37:01 -0800 | [diff] [blame] | 4898 | &phba->sli4_hba.sli_intf) >= |
James Smart | a6517db | 2016-03-31 14:12:29 -0700 | [diff] [blame] | 4899 | LPFC_SLI_INTF_IF_TYPE_2) && |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4900 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4901 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4902 | mbox->mbox_cmpl = |
| 4903 | lpfc_sli4_unreg_rpi_cmpl_clr; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4904 | /* |
| 4905 | * accept PLOGIs after unreg_rpi_cmpl |
| 4906 | */ |
| 4907 | acc_plogi = 0; |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 4908 | } else if (vport->load_flag & FC_UNLOADING) { |
| 4909 | mbox->ctx_ndlp = NULL; |
| 4910 | mbox->mbox_cmpl = |
| 4911 | lpfc_sli_def_mbox_cmpl; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4912 | } else { |
| 4913 | mbox->ctx_ndlp = ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4914 | mbox->mbox_cmpl = |
| 4915 | lpfc_sli_def_mbox_cmpl; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4916 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4917 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4918 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != |
| 4919 | Fabric_DID_MASK) && |
| 4920 | (!(vport->fc_flag & FC_OFFLINE_MODE))) |
| 4921 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 4922 | |
| 4923 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4924 | "1433 unreg_rpi UNREG x%x on " |
| 4925 | "NPort x%x deferred flg x%x Data:%p\n", |
| 4926 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4927 | ndlp->nlp_flag, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4928 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4929 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4930 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4932 | acc_plogi = 1; |
| 4933 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | lpfc_no_rpi(phba, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4936 | out: |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4937 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4938 | ndlp->nlp_rpi = 0; |
| 4939 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4940 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4941 | if (acc_plogi) |
| 4942 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | return 1; |
| 4944 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4945 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | return 0; |
| 4947 | } |
| 4948 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4949 | /** |
| 4950 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4951 | * @phba: pointer to lpfc hba data structure. |
| 4952 | * |
| 4953 | * This routine is invoked to unregister all the currently registered RPIs |
| 4954 | * to the HBA. |
| 4955 | **/ |
| 4956 | void |
| 4957 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4958 | { |
| 4959 | struct lpfc_vport **vports; |
| 4960 | struct lpfc_nodelist *ndlp; |
| 4961 | struct Scsi_Host *shost; |
| 4962 | int i; |
| 4963 | |
| 4964 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4965 | if (!vports) { |
| 4966 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4967 | "2884 Vport array allocation failed \n"); |
| 4968 | return; |
| 4969 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4970 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4971 | shost = lpfc_shost_from_vport(vports[i]); |
| 4972 | spin_lock_irq(shost->host_lock); |
| 4973 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4974 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4975 | /* The mempool_alloc might sleep */ |
| 4976 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4977 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4978 | spin_lock_irq(shost->host_lock); |
| 4979 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4980 | } |
| 4981 | spin_unlock_irq(shost->host_lock); |
| 4982 | } |
| 4983 | lpfc_destroy_vport_work_array(phba, vports); |
| 4984 | } |
| 4985 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4986 | void |
| 4987 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4988 | { |
| 4989 | struct lpfc_hba *phba = vport->phba; |
| 4990 | LPFC_MBOXQ_t *mbox; |
| 4991 | int rc; |
| 4992 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4993 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4994 | lpfc_sli4_unreg_all_rpis(vport); |
| 4995 | return; |
| 4996 | } |
| 4997 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4998 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4999 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5000 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 5001 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5002 | mbox->vport = vport; |
| 5003 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5004 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5005 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5006 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5007 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5008 | |
| 5009 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 5010 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 5011 | "1836 Could not issue " |
| 5012 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | void |
| 5017 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 5018 | { |
| 5019 | struct lpfc_hba *phba = vport->phba; |
| 5020 | LPFC_MBOXQ_t *mbox; |
| 5021 | int rc; |
| 5022 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 5023 | /* Unreg DID is an SLI3 operation. */ |
| 5024 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 5025 | return; |
| 5026 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5027 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5028 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5029 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 5030 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5031 | mbox->vport = vport; |
| 5032 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5033 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5034 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5035 | if (rc != MBX_TIMEOUT) |
| 5036 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5037 | |
| 5038 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5039 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 5040 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5041 | "unreg_did (default rpis) status %d\n", |
| 5042 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | /* |
| 5047 | * Free resources associated with LPFC_NODELIST entry |
| 5048 | * so it can be freed. |
| 5049 | */ |
| 5050 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5051 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5052 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5053 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5054 | struct lpfc_hba *phba = vport->phba; |
| 5055 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5057 | |
| 5058 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5059 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5060 | "0900 Cleanup node for NPort x%x " |
| 5061 | "Data: x%x x%x x%x\n", |
| 5062 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5063 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5064 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5065 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 5066 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 5067 | "usgmap:x%x refcnt:%d\n", |
| 5068 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5069 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5070 | lpfc_dequeue_node(vport, ndlp); |
| 5071 | } else { |
| 5072 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 5073 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 5074 | "usgmap:x%x refcnt:%d\n", |
| 5075 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5076 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5077 | lpfc_disable_node(vport, ndlp); |
| 5078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5080 | |
| 5081 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 5082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 5084 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5085 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5086 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5087 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5088 | mb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5089 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5090 | } |
| 5091 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 5092 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5093 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5094 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 5095 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 5096 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5097 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5098 | (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp)) |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5099 | continue; |
| 5100 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5101 | mb->ctx_ndlp = NULL; |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5102 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5103 | } |
| 5104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5106 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5107 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5108 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5109 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5110 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5111 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | kfree(mp); |
| 5113 | } |
| 5114 | list_del(&mb->list); |
| 5115 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5116 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 5117 | * the ndlp reference count as we are in the process |
| 5118 | * of lpfc_nlp_release. |
| 5119 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | } |
| 5121 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5122 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5123 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5124 | lpfc_els_abort(phba, ndlp); |
| 5125 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5126 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 5127 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5128 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5129 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5130 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 5132 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5133 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 5134 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5135 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5136 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5137 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5138 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5139 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5140 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | /* |
| 5144 | * Check to see if we can free the nlp back to the freelist. |
| 5145 | * If we are in the middle of using the nlp in the discovery state |
| 5146 | * machine, defer the free till we reach the end of the state machine. |
| 5147 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5148 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5149 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5150 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5151 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5152 | struct lpfc_rport_data *rdata; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5153 | struct fc_rport *rport; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5154 | LPFC_MBOXQ_t *mbox; |
| 5155 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5156 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5157 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 5158 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5159 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
Dick Kennedy | e8bcf0a | 2017-09-29 17:34:32 -0700 | [diff] [blame] | 5160 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
| 5161 | phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5162 | /* For this case we need to cleanup the default rpi |
| 5163 | * allocated by the firmware. |
| 5164 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5165 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5166 | "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 5167 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5168 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5169 | ndlp->nlp_usg_map, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5170 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 5171 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 5172 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5173 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5174 | if (rc) { |
| 5175 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5176 | } |
| 5177 | else { |
| 5178 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 5179 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 5180 | mbox->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5181 | mbox->ctx_ndlp = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5182 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5183 | if (rc == MBX_NOT_FINISHED) { |
| 5184 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5185 | } |
| 5186 | } |
| 5187 | } |
| 5188 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5190 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5191 | /* |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5192 | * ndlp->rport must be set to NULL before it reaches here |
| 5193 | * i.e. break rport/node link before doing lpfc_nlp_put for |
| 5194 | * registered rport and then drop the reference of rport. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5195 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5196 | if (ndlp->rport) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5197 | /* |
| 5198 | * extra lpfc_nlp_put dropped the reference of ndlp |
| 5199 | * for registered rport so need to cleanup rport |
| 5200 | */ |
| 5201 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 5202 | "0940 removed node x%p DID x%x " |
| 5203 | " rport not null %p\n", |
| 5204 | ndlp, ndlp->nlp_DID, ndlp->rport); |
| 5205 | rport = ndlp->rport; |
| 5206 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5207 | rdata->pnode = NULL; |
| 5208 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5209 | put_device(&rport->dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5210 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5214 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5215 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5217 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5218 | |
| 5219 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5220 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | /* First check for Direct match */ |
| 5223 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5224 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5225 | |
| 5226 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5227 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
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 = did; |
| 5233 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5234 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5235 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5236 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5237 | /* This code is supposed to match the ID |
| 5238 | * for a private loop device that is |
| 5239 | * connect to fl_port. But we need to |
| 5240 | * check that the port did not just go |
| 5241 | * from pt2pt to fabric or we could end |
| 5242 | * up matching ndlp->nlp_DID 000001 to |
| 5243 | * fabric DID 0x20101 |
| 5244 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | if ((ndlpdid.un.b.domain == 0) && |
| 5246 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5247 | if (ndlpdid.un.b.id && |
| 5248 | vport->phba->fc_topology == |
| 5249 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5250 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5252 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | matchdid.un.word = ndlp->nlp_DID; |
| 5256 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5257 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5258 | if ((matchdid.un.b.domain == 0) && |
| 5259 | (matchdid.un.b.area == 0)) { |
| 5260 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5261 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5265 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | } |
| 5267 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5268 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5269 | static struct lpfc_nodelist * |
| 5270 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5272 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5273 | uint32_t data1; |
| 5274 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5275 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5276 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5277 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5278 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5279 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5280 | ((uint32_t)ndlp->nlp_usg_map & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5281 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5282 | "0929 FIND node DID " |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5283 | "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] | 5284 | ndlp, ndlp->nlp_DID, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5285 | ndlp->nlp_flag, data1, ndlp->nlp_rpi, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5286 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5287 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | } |
| 5289 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5290 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5291 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5292 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5293 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | return NULL; |
| 5295 | } |
| 5296 | |
| 5297 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5298 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5300 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5301 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5302 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5303 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5304 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5306 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5307 | return ndlp; |
| 5308 | } |
| 5309 | |
| 5310 | struct lpfc_nodelist * |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5311 | lpfc_findnode_mapped(struct lpfc_vport *vport) |
| 5312 | { |
| 5313 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5314 | struct lpfc_nodelist *ndlp; |
| 5315 | uint32_t data1; |
| 5316 | unsigned long iflags; |
| 5317 | |
| 5318 | spin_lock_irqsave(shost->host_lock, iflags); |
| 5319 | |
| 5320 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5321 | if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || |
| 5322 | ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 5323 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5324 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5325 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5326 | ((uint32_t)ndlp->nlp_rpi & 0xff)); |
| 5327 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5328 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5329 | "2025 FIND node DID " |
| 5330 | "Data: x%p x%x x%x x%x %p\n", |
| 5331 | ndlp, ndlp->nlp_DID, |
| 5332 | ndlp->nlp_flag, data1, |
| 5333 | ndlp->active_rrqs_xri_bitmap); |
| 5334 | return ndlp; |
| 5335 | } |
| 5336 | } |
| 5337 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5338 | |
| 5339 | /* FIND node did <did> NOT FOUND */ |
| 5340 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5341 | "2026 FIND mapped did NOT FOUND.\n"); |
| 5342 | return NULL; |
| 5343 | } |
| 5344 | |
| 5345 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5346 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5347 | { |
| 5348 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5349 | struct lpfc_nodelist *ndlp; |
| 5350 | |
| 5351 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5352 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5353 | if (vport->phba->nvmet_support) |
| 5354 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5355 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5356 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5357 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5358 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5359 | if (!ndlp) |
| 5360 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5361 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5362 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5363 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5364 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5365 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5366 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5367 | if (vport->phba->nvmet_support) |
| 5368 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5369 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5370 | if (!ndlp) { |
| 5371 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, |
| 5372 | "0014 Could not enable ndlp\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5373 | return NULL; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5374 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5375 | spin_lock_irq(shost->host_lock); |
| 5376 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5377 | spin_unlock_irq(shost->host_lock); |
| 5378 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5380 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5381 | /* The NVME Target does not want to actively manage an rport. |
| 5382 | * The goal is to allow the target to reset its state and clear |
| 5383 | * pending IO in preparation for the initiator to recover. |
| 5384 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5385 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5386 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5387 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5388 | |
| 5389 | /* Since this node is marked for discovery, |
| 5390 | * delay timeout is not needed. |
| 5391 | */ |
| 5392 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5393 | |
| 5394 | /* NVME Target mode waits until rport is known to be |
| 5395 | * impacted by the RSCN before it transitions. No |
| 5396 | * active management - just go to NPR provided the |
| 5397 | * node had a valid login. |
| 5398 | */ |
| 5399 | if (vport->phba->nvmet_support) |
| 5400 | return ndlp; |
| 5401 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5402 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5403 | * we don't need to try to discover it again. |
| 5404 | */ |
| 5405 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 5406 | return NULL; |
| 5407 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5408 | spin_lock_irq(shost->host_lock); |
| 5409 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5410 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 5411 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5413 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5414 | /* If the initiator received a PLOGI from this NPort or if the |
| 5415 | * initiator is already in the process of discovery on it, |
| 5416 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5417 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5418 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5419 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5420 | (!vport->phba->nvmet_support && |
| 5421 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5422 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5423 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5424 | if (vport->phba->nvmet_support) |
| 5425 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5426 | |
| 5427 | /* Moving to NPR state clears unsolicited flags and |
| 5428 | * allows for rediscovery |
| 5429 | */ |
| 5430 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5431 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5432 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5434 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | } |
| 5436 | return ndlp; |
| 5437 | } |
| 5438 | |
| 5439 | /* Build a list of nodes to discover based on the loopmap */ |
| 5440 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5441 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5442 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5443 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5444 | int j; |
| 5445 | uint32_t alpa, index; |
| 5446 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5447 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5448 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5450 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | |
| 5453 | /* Check for loop map present or not */ |
| 5454 | if (phba->alpa_map[0]) { |
| 5455 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5456 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5459 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5460 | } |
| 5461 | } else { |
| 5462 | /* No alpamap, so try all alpa's */ |
| 5463 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5464 | /* If cfg_scan_down is set, start from highest |
| 5465 | * ALPA (0xef) to lowest (0x1). |
| 5466 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5467 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | index = j; |
| 5469 | else |
| 5470 | index = FC_MAXLOOP - j - 1; |
| 5471 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5474 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | } |
| 5476 | } |
| 5477 | return; |
| 5478 | } |
| 5479 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5480 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5481 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5482 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5483 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5485 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5486 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5487 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5488 | int rc; |
| 5489 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5490 | /* |
| 5491 | * if it's not a physical port or if we already send |
| 5492 | * clear_la then don't send it. |
| 5493 | */ |
| 5494 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5495 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5496 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5497 | return; |
| 5498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5499 | /* Link up discovery */ |
| 5500 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5501 | phba->link_state = LPFC_CLEAR_LA; |
| 5502 | lpfc_clear_la(phba, mbox); |
| 5503 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5504 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5505 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5506 | if (rc == MBX_NOT_FINISHED) { |
| 5507 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5508 | lpfc_disc_flush_list(vport); |
| 5509 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5510 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5511 | phba->link_state = LPFC_HBA_ERROR; |
| 5512 | } |
| 5513 | } |
| 5514 | } |
| 5515 | |
| 5516 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5517 | void |
| 5518 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5519 | { |
| 5520 | LPFC_MBOXQ_t *regvpimbox; |
| 5521 | |
| 5522 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5523 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5524 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5525 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5526 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5527 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5528 | == MBX_NOT_FINISHED) { |
| 5529 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5530 | } |
| 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5535 | void |
| 5536 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5537 | { |
| 5538 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5539 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5540 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5542 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5543 | if (!lpfc_is_link_up(phba)) { |
| 5544 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5545 | "3315 Link is not up %x\n", |
| 5546 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5548 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5549 | |
| 5550 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | clear_la_pending = 1; |
| 5552 | else |
| 5553 | clear_la_pending = 0; |
| 5554 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5555 | if (vport->port_state < LPFC_VPORT_READY) |
| 5556 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5557 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5558 | lpfc_set_disctmo(vport); |
| 5559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5560 | vport->fc_prevDID = vport->fc_myDID; |
| 5561 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5562 | |
| 5563 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5565 | "0202 Start Discovery hba state x%x " |
| 5566 | "Data: x%x x%x x%x\n", |
| 5567 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 5568 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5569 | |
| 5570 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5571 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | |
| 5573 | if (num_sent) |
| 5574 | return; |
| 5575 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5576 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5577 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5578 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5579 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5580 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5581 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5582 | lpfc_issue_reg_vpi(phba, vport); |
| 5583 | return; |
| 5584 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5585 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5586 | /* |
| 5587 | * For SLI2, we need to set port_state to READY and continue |
| 5588 | * discovery. |
| 5589 | */ |
| 5590 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5591 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5592 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5593 | |
| 5594 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5595 | vport->num_disc_nodes = 0; |
| 5596 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5597 | if (vport->fc_npr_cnt) |
| 5598 | lpfc_els_disc_plogi(vport); |
| 5599 | |
| 5600 | if (!vport->num_disc_nodes) { |
| 5601 | spin_lock_irq(shost->host_lock); |
| 5602 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5603 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5604 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | } |
| 5606 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5607 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5608 | } else { |
| 5609 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5610 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5611 | |
| 5612 | if (num_sent) |
| 5613 | return; |
| 5614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5615 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5616 | /* Check to see if more RSCNs came in while we |
| 5617 | * were processing this one. |
| 5618 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5619 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5620 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5621 | spin_lock_irq(shost->host_lock); |
| 5622 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5623 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5624 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5625 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5626 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | } |
| 5628 | } |
| 5629 | return; |
| 5630 | } |
| 5631 | |
| 5632 | /* |
| 5633 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5634 | * ring the match the sppecified nodelist. |
| 5635 | */ |
| 5636 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5637 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5639 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | IOCB_t *icmd; |
| 5641 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5642 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5644 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 5645 | if (unlikely(!pring)) |
| 5646 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | |
| 5648 | /* Error matching iocb on txq or txcmplq |
| 5649 | * First check the txq. |
| 5650 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5651 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5652 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5653 | if (iocb->context1 != ndlp) { |
| 5654 | continue; |
| 5655 | } |
| 5656 | icmd = &iocb->iocb; |
| 5657 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5658 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5659 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5660 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | /* Next check the txcmplq */ |
| 5665 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5666 | if (iocb->context1 != ndlp) { |
| 5667 | continue; |
| 5668 | } |
| 5669 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5670 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5671 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5672 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | } |
| 5674 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5675 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5676 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5677 | /* Cancel all the IOCBs from the completions list */ |
| 5678 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5679 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5680 | } |
| 5681 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5682 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5683 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | { |
| 5685 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5686 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5688 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5689 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5690 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5691 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5692 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5693 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5694 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5695 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5696 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5697 | } |
| 5698 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5699 | } |
| 5700 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5701 | void |
| 5702 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5703 | { |
| 5704 | lpfc_els_flush_rscn(vport); |
| 5705 | lpfc_els_flush_cmd(vport); |
| 5706 | lpfc_disc_flush_list(vport); |
| 5707 | } |
| 5708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5709 | /*****************************************************************************/ |
| 5710 | /* |
| 5711 | * NAME: lpfc_disc_timeout |
| 5712 | * |
| 5713 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5714 | * |
| 5715 | * EXECUTION ENVIRONMENT: interrupt only |
| 5716 | * |
| 5717 | * CALLED FROM: |
| 5718 | * Timer function |
| 5719 | * |
| 5720 | * RETURNS: |
| 5721 | * none |
| 5722 | */ |
| 5723 | /*****************************************************************************/ |
| 5724 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5725 | lpfc_disc_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5726 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5727 | struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5728 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5729 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5730 | unsigned long flags = 0; |
| 5731 | |
| 5732 | if (unlikely(!phba)) |
| 5733 | return; |
| 5734 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5735 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5736 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5737 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5738 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5739 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5740 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5741 | if (!tmo_posted) |
| 5742 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | return; |
| 5744 | } |
| 5745 | |
| 5746 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5747 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5748 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5750 | struct lpfc_hba *phba = vport->phba; |
| 5751 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5752 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5753 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5754 | int rc, clrlaerr = 0; |
| 5755 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5756 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5757 | return; |
| 5758 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5759 | spin_lock_irq(shost->host_lock); |
| 5760 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5761 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5763 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5764 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5765 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5766 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5767 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | |
| 5769 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5770 | /* |
| 5771 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5772 | * waiting for FAN timeout |
| 5773 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5774 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5775 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5776 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5777 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5778 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5779 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5780 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5781 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5782 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5783 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5784 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5785 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5786 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5787 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5788 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5789 | /* Fail outstanding IO now since device |
| 5790 | * is marked for PLOGI. |
| 5791 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5792 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5793 | } |
| 5794 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5795 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5796 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5797 | lpfc_initial_flogi(vport); |
| 5798 | else |
| 5799 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5800 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5801 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5802 | break; |
| 5803 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5804 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5805 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5806 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5807 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5808 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5809 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5810 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5811 | |
| 5812 | /* Assume no Fabric and go on with discovery. |
| 5813 | * Check for outstanding ELS FLOGI to abort. |
| 5814 | */ |
| 5815 | |
| 5816 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5817 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5818 | |
| 5819 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5820 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5821 | break; |
| 5822 | |
| 5823 | case LPFC_FABRIC_CFG_LINK: |
| 5824 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5825 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5826 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5827 | "0223 Timeout while waiting for " |
| 5828 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5829 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5830 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5831 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5832 | lpfc_els_abort(phba, ndlp); |
| 5833 | |
| 5834 | /* ReStart discovery */ |
| 5835 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5836 | |
| 5837 | case LPFC_NS_QRY: |
| 5838 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5839 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5840 | "0224 NameServer Query timeout " |
| 5841 | "Data: x%x x%x\n", |
| 5842 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5843 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5844 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5845 | /* Try it one more time */ |
| 5846 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5847 | vport->gidft_inp = 0; |
| 5848 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5849 | if (rc == 0) |
| 5850 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5851 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5852 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5853 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5854 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5855 | /* |
| 5856 | * Discovery is over. |
| 5857 | * set port_state to PORT_READY if SLI2. |
| 5858 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5859 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5860 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5861 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5862 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5863 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5864 | lpfc_issue_clear_la(phba, vport); |
| 5865 | vport->port_state = LPFC_VPORT_READY; |
| 5866 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5870 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5871 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5872 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5873 | "0206 Device Discovery " |
| 5874 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5875 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5876 | break; |
| 5877 | } |
| 5878 | |
| 5879 | lpfc_linkdown(phba); |
| 5880 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5881 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5882 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5883 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5884 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5885 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5886 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5887 | if (rc == MBX_NOT_FINISHED) |
| 5888 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5889 | |
| 5890 | break; |
| 5891 | |
| 5892 | case LPFC_DISC_AUTH: |
| 5893 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5894 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5895 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5896 | lpfc_disc_flush_list(vport); |
| 5897 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5898 | /* |
| 5899 | * set port_state to PORT_READY if SLI2. |
| 5900 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5901 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5902 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5903 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5904 | lpfc_issue_reg_vpi(phba, vport); |
| 5905 | else { /* NPIV Not enabled */ |
| 5906 | lpfc_issue_clear_la(phba, vport); |
| 5907 | vport->port_state = LPFC_VPORT_READY; |
| 5908 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5909 | } |
| 5910 | break; |
| 5911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5912 | case LPFC_VPORT_READY: |
| 5913 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5914 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5915 | "0231 RSCN timeout Data: x%x " |
| 5916 | "x%x\n", |
| 5917 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5918 | |
| 5919 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5920 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5922 | lpfc_els_flush_rscn(vport); |
| 5923 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5924 | } |
| 5925 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5926 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5927 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5928 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5929 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5930 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5931 | break; |
| 5932 | } |
| 5933 | |
| 5934 | switch (phba->link_state) { |
| 5935 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5936 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 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); |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 5944 | /* fall through */ |
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: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5951 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5952 | "0230 Unexpected timeout, hba link " |
| 5953 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5954 | clrlaerr = 1; |
| 5955 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5956 | |
| 5957 | case LPFC_HBA_READY: |
| 5958 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5962 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5963 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 5964 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 5965 | ~LPFC_STOP_IOCB_EVENT; |
| 5966 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 5967 | ~LPFC_STOP_IOCB_EVENT; |
| 5968 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5969 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5970 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5971 | return; |
| 5972 | } |
| 5973 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5974 | /* |
| 5975 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5976 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5977 | * as the completion routine when the command is |
| 5978 | * handed off to the SLI layer. |
| 5979 | */ |
| 5980 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5981 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5982 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5983 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5984 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 5985 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5986 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5987 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5988 | pmb->ctx_buf = NULL; |
| 5989 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5990 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5991 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5992 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5993 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5994 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5995 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5996 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5997 | "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 5998 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5999 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6000 | ndlp->nlp_usg_map, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6001 | /* |
| 6002 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6003 | * 0xfffffa (FDMI well known port). |
| 6004 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 6005 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6006 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6007 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 6008 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 6009 | else |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6010 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| 6011 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6012 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6013 | /* decrement the node reference count held for this callback |
| 6014 | * function. |
| 6015 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6016 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6017 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6018 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6019 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6020 | |
| 6021 | return; |
| 6022 | } |
| 6023 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6024 | static int |
| 6025 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 6026 | { |
| 6027 | uint16_t *rpi = param; |
| 6028 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 6029 | /* check for active node */ |
| 6030 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 6031 | return 0; |
| 6032 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6033 | return ndlp->nlp_rpi == *rpi; |
| 6034 | } |
| 6035 | |
| 6036 | static int |
| 6037 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 6038 | { |
| 6039 | return memcmp(&ndlp->nlp_portname, param, |
| 6040 | sizeof(ndlp->nlp_portname)) == 0; |
| 6041 | } |
| 6042 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6043 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6044 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6045 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6046 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6047 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6048 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6049 | if (filter(ndlp, param)) { |
| 6050 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 6051 | "3185 FIND node filter %p DID " |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6052 | "ndlp %p did x%x flg x%x st x%x " |
| 6053 | "xri x%x type x%x rpi x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6054 | filter, ndlp, ndlp->nlp_DID, |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6055 | ndlp->nlp_flag, ndlp->nlp_state, |
| 6056 | ndlp->nlp_xri, ndlp->nlp_type, |
| 6057 | ndlp->nlp_rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6058 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6059 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6060 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6061 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 6062 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6063 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6064 | } |
| 6065 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6066 | /* |
| 6067 | * 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] | 6068 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6069 | */ |
| 6070 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6071 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6072 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6073 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6074 | } |
| 6075 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6076 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6077 | * 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] | 6078 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6079 | */ |
| 6080 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6081 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6082 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6083 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6084 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6085 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6086 | spin_lock_irq(shost->host_lock); |
| 6087 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 6088 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6089 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6090 | } |
| 6091 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6092 | /* |
| 6093 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 6094 | * is found, the routine returns the node element list pointer else |
| 6095 | * return NULL. |
| 6096 | */ |
| 6097 | struct lpfc_nodelist * |
| 6098 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 6099 | { |
| 6100 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6101 | struct lpfc_nodelist *ndlp; |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6102 | unsigned long flags; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6103 | |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6104 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6105 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6106 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6107 | return ndlp; |
| 6108 | } |
| 6109 | |
| 6110 | /** |
| 6111 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 6112 | * @phba: pointer to lpfc hba data structure. |
| 6113 | * @vpi: the physical host virtual N_Port identifier. |
| 6114 | * |
| 6115 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6116 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6117 | * of the vport with the matching @vpi. |
| 6118 | * |
| 6119 | * Return code |
| 6120 | * NULL - No vport with the matching @vpi found |
| 6121 | * Otherwise - Address to the vport with the matching @vpi. |
| 6122 | **/ |
| 6123 | struct lpfc_vport * |
| 6124 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6125 | { |
| 6126 | struct lpfc_vport *vport; |
| 6127 | unsigned long flags; |
| 6128 | int i = 0; |
| 6129 | |
| 6130 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 6131 | if (vpi > 0) { |
| 6132 | /* |
| 6133 | * Translate the physical vpi to the logical vpi. The |
| 6134 | * vport stores the logical vpi. |
| 6135 | */ |
| 6136 | for (i = 0; i < phba->max_vpi; i++) { |
| 6137 | if (vpi == phba->vpi_ids[i]) |
| 6138 | break; |
| 6139 | } |
| 6140 | |
| 6141 | if (i >= phba->max_vpi) { |
| 6142 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 6143 | "2936 Could not find Vport mapped " |
| 6144 | "to vpi %d\n", vpi); |
| 6145 | return NULL; |
| 6146 | } |
| 6147 | } |
| 6148 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6149 | spin_lock_irqsave(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6150 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 6151 | if (vport->vpi == i) { |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6152 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6153 | return vport; |
| 6154 | } |
| 6155 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6156 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6157 | return NULL; |
| 6158 | } |
| 6159 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6160 | struct lpfc_nodelist * |
| 6161 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6162 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6163 | struct lpfc_nodelist *ndlp; |
| 6164 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 6165 | |
| 6166 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 6167 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 6168 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 6169 | return NULL; |
| 6170 | } |
| 6171 | |
| 6172 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 6173 | if (!ndlp) { |
| 6174 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6175 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 6176 | return NULL; |
| 6177 | } |
| 6178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6179 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6180 | |
| 6181 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6182 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6183 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6184 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6185 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 6186 | "0007 rpi:%x DID:%x flg:%x refcnt:%d " |
| 6187 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6188 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6189 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6190 | ndlp->nlp_usg_map, ndlp); |
| 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 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6215 | struct lpfc_hba *phba; |
| 6216 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6217 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 6218 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6219 | |
| 6220 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6221 | "node release: did:x%x flg:x%x type:x%x", |
| 6222 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 6223 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6224 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6225 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6226 | "usgmap:x%x refcnt:%d rpi:%x\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6227 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6228 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6229 | |
| 6230 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6231 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6232 | |
| 6233 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6234 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6235 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6236 | NLP_CLR_NODE_ACT(ndlp); |
| 6237 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6238 | |
| 6239 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6240 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 6241 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6242 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6243 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6244 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6245 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6246 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6247 | } |
| 6248 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6249 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6250 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6251 | * is using it. |
| 6252 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6253 | struct lpfc_nodelist * |
| 6254 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6255 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6256 | struct lpfc_hba *phba; |
| 6257 | unsigned long flags; |
| 6258 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6259 | if (ndlp) { |
| 6260 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6261 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6262 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6263 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6264 | /* The check of ndlp usage to prevent incrementing the |
| 6265 | * ndlp reference count that is in the process of being |
| 6266 | * released. |
| 6267 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6268 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6269 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6270 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 6271 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6272 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6273 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 6274 | "usgmap:x%x refcnt:%d\n", |
| 6275 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6276 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6277 | return NULL; |
| 6278 | } else |
| 6279 | kref_get(&ndlp->kref); |
| 6280 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6281 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6282 | return ndlp; |
| 6283 | } |
| 6284 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6285 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6286 | * count goes to 0, this indicates the the associated nodelist should be |
| 6287 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 6288 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 6289 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6290 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6291 | int |
| 6292 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6293 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6294 | struct lpfc_hba *phba; |
| 6295 | unsigned long flags; |
| 6296 | |
| 6297 | if (!ndlp) |
| 6298 | return 1; |
| 6299 | |
| 6300 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6301 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6302 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6303 | kref_read(&ndlp->kref)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6304 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6305 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6306 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 6307 | * possible race condition that kref_put got invoked again |
| 6308 | * after previous one has done ndlp memory free. |
| 6309 | */ |
| 6310 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 6311 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6312 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6313 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 6314 | "usgmap:x%x refcnt:%d\n", |
| 6315 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6316 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6317 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6318 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6319 | /* Check the ndlp inactivate log flag to avoid the possible |
| 6320 | * race condition that kref_put got invoked again after ndlp |
| 6321 | * is already in inactivating state. |
| 6322 | */ |
| 6323 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 6324 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6325 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6326 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 6327 | "usgmap:x%x refcnt:%d\n", |
| 6328 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6329 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6330 | return 1; |
| 6331 | } |
| 6332 | /* For last put, mark the ndlp usage flags to make sure no |
| 6333 | * other kref_get and kref_put on the same ndlp shall get |
| 6334 | * in between the process when the final kref_put has been |
| 6335 | * invoked on this ndlp. |
| 6336 | */ |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6337 | if (kref_read(&ndlp->kref) == 1) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6338 | /* Indicate ndlp is put to inactive state. */ |
| 6339 | NLP_SET_IACT_REQ(ndlp); |
| 6340 | /* Acknowledge ndlp memory free has been seen. */ |
| 6341 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 6342 | NLP_SET_FREE_ACK(ndlp); |
| 6343 | } |
| 6344 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6345 | /* Note, the kref_put returns 1 when decrementing a reference |
| 6346 | * count that was 1, it invokes the release callback function, |
| 6347 | * but it still left the reference count as 1 (not actually |
| 6348 | * performs the last decrementation). Otherwise, it actually |
| 6349 | * decrements the reference count and returns 0. |
| 6350 | */ |
| 6351 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6352 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6353 | |
| 6354 | /* 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] | 6355 | * by any other discovery thread. This routine returns 1 if the |
| 6356 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6357 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6358 | */ |
| 6359 | int |
| 6360 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6361 | { |
| 6362 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6363 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6364 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6365 | kref_read(&ndlp->kref)); |
| 6366 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6367 | if (lpfc_nlp_put(ndlp)) |
| 6368 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6369 | return 0; |
| 6370 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6371 | |
| 6372 | /** |
| 6373 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6374 | * @phba: Pointer to hba context object. |
| 6375 | * |
| 6376 | * This function iterate through all FC nodes associated |
| 6377 | * will all vports to check if there is any node with |
| 6378 | * fc_rports associated with it. If there is an fc_rport |
| 6379 | * associated with the node, then the node is either in |
| 6380 | * discovered state or its devloss_timer is pending. |
| 6381 | */ |
| 6382 | static int |
| 6383 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6384 | { |
| 6385 | struct lpfc_vport **vports; |
| 6386 | int i, ret = 0; |
| 6387 | struct lpfc_nodelist *ndlp; |
| 6388 | struct Scsi_Host *shost; |
| 6389 | |
| 6390 | vports = lpfc_create_vport_work_array(phba); |
| 6391 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6392 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6393 | if (!vports) |
| 6394 | return 1; |
| 6395 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6396 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6397 | shost = lpfc_shost_from_vport(vports[i]); |
| 6398 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6399 | /* |
| 6400 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6401 | * flogi. |
| 6402 | * If dev_loss fires while we are waiting we do not want to |
| 6403 | * unreg the fcf. |
| 6404 | */ |
| 6405 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6406 | spin_unlock_irq(shost->host_lock); |
| 6407 | ret = 1; |
| 6408 | goto out; |
| 6409 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6410 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 6411 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 6412 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6413 | ret = 1; |
| 6414 | spin_unlock_irq(shost->host_lock); |
| 6415 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6416 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6417 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6418 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6419 | "2624 RPI %x DID %x flag %x " |
| 6420 | "still logged in\n", |
| 6421 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6422 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6423 | } |
| 6424 | } |
| 6425 | spin_unlock_irq(shost->host_lock); |
| 6426 | } |
| 6427 | out: |
| 6428 | lpfc_destroy_vport_work_array(phba, vports); |
| 6429 | return ret; |
| 6430 | } |
| 6431 | |
| 6432 | /** |
| 6433 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6434 | * @phba: Pointer to hba context object. |
| 6435 | * @mboxq: Pointer to mailbox object. |
| 6436 | * |
| 6437 | * This function frees memory associated with the mailbox command. |
| 6438 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6439 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6440 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6441 | { |
| 6442 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6443 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6444 | |
| 6445 | if (mboxq->u.mb.mbxStatus) { |
| 6446 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6447 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6448 | "HBA state x%x\n", |
| 6449 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6450 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6451 | spin_lock_irq(shost->host_lock); |
| 6452 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6453 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6454 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6455 | return; |
| 6456 | } |
| 6457 | |
| 6458 | /** |
| 6459 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6460 | * @phba: Pointer to hba context object. |
| 6461 | * @mboxq: Pointer to mailbox object. |
| 6462 | * |
| 6463 | * This function frees memory associated with the mailbox command. |
| 6464 | */ |
| 6465 | static void |
| 6466 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6467 | { |
| 6468 | struct lpfc_vport *vport = mboxq->vport; |
| 6469 | |
| 6470 | if (mboxq->u.mb.mbxStatus) { |
| 6471 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6472 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6473 | "HBA state x%x\n", |
| 6474 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6475 | } |
| 6476 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6477 | return; |
| 6478 | } |
| 6479 | |
| 6480 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6481 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6482 | * @phba: Pointer to hba context object. |
| 6483 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6484 | * This function prepare the HBA for unregistering the currently registered |
| 6485 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6486 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6487 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6488 | int |
| 6489 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6490 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6491 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6492 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6493 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6494 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6495 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6496 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6497 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6498 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6499 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6500 | /* At this point, all discovery is aborted */ |
| 6501 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6502 | |
| 6503 | /* Unregister VPIs */ |
| 6504 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6505 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6506 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6507 | /* Stop FLOGI/FDISC retries */ |
| 6508 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6509 | if (ndlp) |
| 6510 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6511 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6512 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6513 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6514 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6515 | shost = lpfc_shost_from_vport(vports[i]); |
| 6516 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6517 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6518 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6519 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6520 | } |
| 6521 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6522 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6523 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6524 | if (ndlp) |
| 6525 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6526 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6527 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6528 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6529 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6530 | shost = lpfc_shost_from_vport(phba->pport); |
| 6531 | spin_lock_irq(shost->host_lock); |
| 6532 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6533 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6534 | spin_unlock_irq(shost->host_lock); |
| 6535 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6536 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6537 | /* Cleanup any outstanding ELS commands */ |
| 6538 | lpfc_els_flush_all_cmd(phba); |
| 6539 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6540 | /* Unregister the physical port VFI */ |
| 6541 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6542 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | /** |
| 6546 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6547 | * @phba: Pointer to hba context object. |
| 6548 | * |
| 6549 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6550 | * unregister the currently registered FCF record. The driver does not reset |
| 6551 | * the driver FCF usage state flags. |
| 6552 | * |
| 6553 | * Return 0 if successfully issued, none-zero otherwise. |
| 6554 | */ |
| 6555 | int |
| 6556 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6557 | { |
| 6558 | LPFC_MBOXQ_t *mbox; |
| 6559 | int rc; |
| 6560 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6561 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6562 | if (!mbox) { |
| 6563 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6564 | "2551 UNREG_FCFI mbox allocation failed" |
| 6565 | "HBA state x%x\n", phba->pport->port_state); |
| 6566 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6567 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6568 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6569 | mbox->vport = phba->pport; |
| 6570 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6571 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6572 | |
| 6573 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6574 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6575 | "2552 Unregister FCFI command failed rc x%x " |
| 6576 | "HBA state x%x\n", |
| 6577 | rc, phba->pport->port_state); |
| 6578 | return -EINVAL; |
| 6579 | } |
| 6580 | return 0; |
| 6581 | } |
| 6582 | |
| 6583 | /** |
| 6584 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6585 | * @phba: Pointer to hba context object. |
| 6586 | * |
| 6587 | * This function unregisters the currently reigstered FCF. This function |
| 6588 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6589 | */ |
| 6590 | void |
| 6591 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6592 | { |
| 6593 | int rc; |
| 6594 | |
| 6595 | /* Preparation for unregistering fcf */ |
| 6596 | rc = lpfc_unregister_fcf_prep(phba); |
| 6597 | if (rc) { |
| 6598 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6599 | "2748 Failed to prepare for unregistering " |
| 6600 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6601 | return; |
| 6602 | } |
| 6603 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6604 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6605 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6606 | if (rc) |
| 6607 | return; |
| 6608 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6609 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6610 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6611 | |
| 6612 | /* |
| 6613 | * If driver is not unloading, check if there is any other |
| 6614 | * FCF record that can be used for discovery. |
| 6615 | */ |
| 6616 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6617 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6618 | return; |
| 6619 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6620 | /* This is considered as the initial FCF discovery scan */ |
| 6621 | spin_lock_irq(&phba->hbalock); |
| 6622 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6623 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6624 | |
| 6625 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6626 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6627 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6628 | 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] | 6629 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6630 | if (rc) { |
| 6631 | spin_lock_irq(&phba->hbalock); |
| 6632 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6633 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6634 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6635 | "2553 lpfc_unregister_unused_fcf failed " |
| 6636 | "to read FCF record HBA state x%x\n", |
| 6637 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6638 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | /** |
| 6642 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6643 | * @phba: Pointer to hba context object. |
| 6644 | * |
| 6645 | * This function just unregisters the currently reigstered FCF. It does not |
| 6646 | * try to find another FCF for discovery. |
| 6647 | */ |
| 6648 | void |
| 6649 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6650 | { |
| 6651 | int rc; |
| 6652 | |
| 6653 | /* Preparation for unregistering fcf */ |
| 6654 | rc = lpfc_unregister_fcf_prep(phba); |
| 6655 | if (rc) { |
| 6656 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6657 | "2749 Failed to prepare for unregistering " |
| 6658 | "HBA's FCF record: rc=%d\n", rc); |
| 6659 | return; |
| 6660 | } |
| 6661 | |
| 6662 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6663 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6664 | if (rc) |
| 6665 | return; |
| 6666 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6667 | spin_lock_irq(&phba->hbalock); |
| 6668 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6669 | spin_unlock_irq(&phba->hbalock); |
| 6670 | } |
| 6671 | |
| 6672 | /** |
| 6673 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6674 | * @phba: Pointer to hba context object. |
| 6675 | * |
| 6676 | * This function check if there are any connected remote port for the FCF and |
| 6677 | * if all the devices are disconnected, this function unregister FCFI. |
| 6678 | * This function also tries to use another FCF for discovery. |
| 6679 | */ |
| 6680 | void |
| 6681 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6682 | { |
| 6683 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6684 | * If HBA is not running in FIP mode, if HBA does not support |
| 6685 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6686 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6687 | */ |
| 6688 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6689 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6690 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6691 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6692 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6693 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6694 | spin_unlock_irq(&phba->hbalock); |
| 6695 | return; |
| 6696 | } |
| 6697 | spin_unlock_irq(&phba->hbalock); |
| 6698 | |
| 6699 | if (lpfc_fcf_inuse(phba)) |
| 6700 | return; |
| 6701 | |
| 6702 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | /** |
| 6706 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6707 | * @phba: Pointer to hba context object. |
| 6708 | * @buff: Buffer containing the FCF connection table as in the config |
| 6709 | * region. |
| 6710 | * This function create driver data structure for the FCF connection |
| 6711 | * record table read from config region 23. |
| 6712 | */ |
| 6713 | static void |
| 6714 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6715 | uint8_t *buff) |
| 6716 | { |
| 6717 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6718 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6719 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6720 | uint32_t record_count; |
| 6721 | int i; |
| 6722 | |
| 6723 | /* Free the current connect table */ |
| 6724 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6725 | &phba->fcf_conn_rec_list, list) { |
| 6726 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6727 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6728 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6729 | |
| 6730 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6731 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6732 | sizeof(struct lpfc_fcf_conn_rec); |
| 6733 | |
| 6734 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6735 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6736 | |
| 6737 | for (i = 0; i < record_count; i++) { |
| 6738 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6739 | continue; |
| 6740 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6741 | GFP_KERNEL); |
| 6742 | if (!conn_entry) { |
| 6743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6744 | "2566 Failed to allocate connection" |
| 6745 | " table entry\n"); |
| 6746 | return; |
| 6747 | } |
| 6748 | |
| 6749 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6750 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6751 | list_add_tail(&conn_entry->list, |
| 6752 | &phba->fcf_conn_rec_list); |
| 6753 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6754 | |
| 6755 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6756 | i = 0; |
| 6757 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6758 | list) { |
| 6759 | conn_rec = &conn_entry->conn_rec; |
| 6760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6761 | "3345 FCF connection list rec[%02d]: " |
| 6762 | "flags:x%04x, vtag:x%04x, " |
| 6763 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6764 | "%02x:%02x:%02x:%02x, " |
| 6765 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6766 | "%02x:%02x:%02x:%02x\n", i++, |
| 6767 | conn_rec->flags, conn_rec->vlan_tag, |
| 6768 | conn_rec->fabric_name[0], |
| 6769 | conn_rec->fabric_name[1], |
| 6770 | conn_rec->fabric_name[2], |
| 6771 | conn_rec->fabric_name[3], |
| 6772 | conn_rec->fabric_name[4], |
| 6773 | conn_rec->fabric_name[5], |
| 6774 | conn_rec->fabric_name[6], |
| 6775 | conn_rec->fabric_name[7], |
| 6776 | conn_rec->switch_name[0], |
| 6777 | conn_rec->switch_name[1], |
| 6778 | conn_rec->switch_name[2], |
| 6779 | conn_rec->switch_name[3], |
| 6780 | conn_rec->switch_name[4], |
| 6781 | conn_rec->switch_name[5], |
| 6782 | conn_rec->switch_name[6], |
| 6783 | conn_rec->switch_name[7]); |
| 6784 | } |
| 6785 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | /** |
| 6789 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6790 | * @phba: Pointer to hba context object. |
| 6791 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6792 | * |
| 6793 | * This function update driver data structure with config |
| 6794 | * parameters read from config region 23. |
| 6795 | */ |
| 6796 | static void |
| 6797 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6798 | uint8_t *buff) |
| 6799 | { |
| 6800 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6801 | struct lpfc_fcoe_params *fcoe_param; |
| 6802 | |
| 6803 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6804 | buff; |
| 6805 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6806 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6807 | |
| 6808 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6809 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6810 | return; |
| 6811 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6812 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6813 | phba->valid_vlan = 1; |
| 6814 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6815 | 0xFFF; |
| 6816 | } |
| 6817 | |
| 6818 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6819 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6820 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6821 | return; |
| 6822 | } |
| 6823 | |
| 6824 | /** |
| 6825 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6826 | * @buff: Buffer containing config region 23 data. |
| 6827 | * @size: Size of the data buffer. |
| 6828 | * @rec_type: Record type to be searched. |
| 6829 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6830 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6831 | * of the record specified by record_type. If record found, this |
| 6832 | * function return pointer to the record else return NULL. |
| 6833 | */ |
| 6834 | static uint8_t * |
| 6835 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6836 | { |
| 6837 | uint32_t offset = 0, rec_length; |
| 6838 | |
| 6839 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6840 | (size < sizeof(uint32_t))) |
| 6841 | return NULL; |
| 6842 | |
| 6843 | rec_length = buff[offset + 1]; |
| 6844 | |
| 6845 | /* |
| 6846 | * One TLV record has one word header and number of data words |
| 6847 | * specified in the rec_length field of the record header. |
| 6848 | */ |
| 6849 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6850 | <= size) { |
| 6851 | if (buff[offset] == rec_type) |
| 6852 | return &buff[offset]; |
| 6853 | |
| 6854 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6855 | return NULL; |
| 6856 | |
| 6857 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6858 | rec_length = buff[offset + 1]; |
| 6859 | } |
| 6860 | return NULL; |
| 6861 | } |
| 6862 | |
| 6863 | /** |
| 6864 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6865 | * @phba: Pointer to lpfc_hba data structure. |
| 6866 | * @buff: Buffer containing config region 23 data. |
| 6867 | * @size: Size of the data buffer. |
| 6868 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6869 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6870 | * populate driver data structure with the parameters. |
| 6871 | */ |
| 6872 | void |
| 6873 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6874 | uint8_t *buff, |
| 6875 | uint32_t size) |
| 6876 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6877 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6878 | uint8_t *rec_ptr; |
| 6879 | |
| 6880 | /* |
| 6881 | * If data size is less than 2 words signature and version cannot be |
| 6882 | * verified. |
| 6883 | */ |
| 6884 | if (size < 2*sizeof(uint32_t)) |
| 6885 | return; |
| 6886 | |
| 6887 | /* Check the region signature first */ |
| 6888 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6890 | "2567 Config region 23 has bad signature\n"); |
| 6891 | return; |
| 6892 | } |
| 6893 | |
| 6894 | offset += 4; |
| 6895 | |
| 6896 | /* Check the data structure version */ |
| 6897 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6898 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6899 | "2568 Config region 23 has bad version\n"); |
| 6900 | return; |
| 6901 | } |
| 6902 | offset += 4; |
| 6903 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6904 | /* Read FCoE param record */ |
| 6905 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6906 | size - offset, FCOE_PARAM_TYPE); |
| 6907 | if (rec_ptr) |
| 6908 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6909 | |
| 6910 | /* Read FCF connection table */ |
| 6911 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6912 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6913 | if (rec_ptr) |
| 6914 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6915 | |
| 6916 | } |