| 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> |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 31 | #include <linux/utsname.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 33 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
| 36 | #include <scsi/scsi_transport_fc.h> |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 37 | #include <scsi/fc/fc_fs.h> |
| 38 | |
| 39 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 43 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc_disc.h" |
| 45 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 46 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 48 | #include "lpfc_scsi.h" |
| 49 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc_logmsg.h" |
| 51 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 53 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | |
| 55 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 56 | static uint8_t lpfcAlpaArray[] = { |
| 57 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 58 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 59 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 60 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 61 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 62 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 63 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 64 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 65 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 66 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 67 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 68 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 69 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 70 | }; |
| 71 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 72 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 73 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 74 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 75 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 76 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 77 | void |
| 78 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 79 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 80 | struct lpfc_rport_data *rdata; |
| 81 | struct lpfc_nodelist * ndlp; |
| 82 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 84 | rdata = rport->dd_data; |
| 85 | ndlp = rdata->pnode; |
| 86 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 87 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 88 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 89 | printk(KERN_ERR "Cannot find remote node" |
| 90 | " to terminate I/O Data x%x\n", |
| 91 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 95 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 96 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 97 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 98 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 99 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 100 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 101 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 102 | lpfc_sli_abort_iocb(ndlp->vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 103 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 104 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 105 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * This function will be called when dev_loss_tmo fire. |
| 110 | */ |
| 111 | void |
| 112 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 113 | { |
| 114 | struct lpfc_rport_data *rdata; |
| 115 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 116 | struct lpfc_vport *vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 117 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 118 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 119 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 120 | int put_node; |
| 121 | int put_rport; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 122 | unsigned long iflags; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 123 | |
| 124 | rdata = rport->dd_data; |
| 125 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 126 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 127 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 128 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 129 | vport = ndlp->vport; |
| 130 | phba = vport->phba; |
| 131 | |
| 132 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 133 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 134 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 135 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 136 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 137 | "3181 dev_loss_callbk x%06x, rport x%px flg x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 138 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 139 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 140 | /* Don't defer this if we are in the process of deleting the vport |
| 141 | * or unloading the driver. The unload will cleanup the node |
| 142 | * appropriately we just need to cleanup the ndlp rport info here. |
| 143 | */ |
| 144 | if (vport->load_flag & FC_UNLOADING) { |
| 145 | put_node = rdata->pnode != NULL; |
| 146 | put_rport = ndlp->rport != NULL; |
| 147 | rdata->pnode = NULL; |
| 148 | ndlp->rport = NULL; |
| 149 | if (put_node) |
| 150 | lpfc_nlp_put(ndlp); |
| 151 | if (put_rport) |
| 152 | put_device(&rport->dev); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 157 | return; |
| 158 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 159 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
| 160 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 161 | "6789 rport name %llx != node port name %llx", |
| 162 | rport->port_name, |
| 163 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 164 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 165 | evtp = &ndlp->dev_loss_evt; |
| 166 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 167 | if (!list_empty(&evtp->evt_listp)) { |
| 168 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 169 | "6790 rport name %llx dev_loss_evt pending", |
| 170 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 171 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 172 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 173 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 174 | shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 175 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 176 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 177 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 178 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 179 | /* We need to hold the node by incrementing the reference |
| 180 | * count until this queued work is done |
| 181 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 182 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 183 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 184 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 185 | if (evtp->evt_arg1) { |
| 186 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 187 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 188 | lpfc_worker_wake_up(phba); |
| 189 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 190 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 191 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 195 | /** |
| 196 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 197 | * @ndlp: Pointer to remote node object. |
| 198 | * |
| 199 | * This function is called from the worker thread when devloss timeout timer |
| 200 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 201 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 202 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 203 | * when devloss timeout happened to this @ndlp. |
| 204 | **/ |
| 205 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 206 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 207 | { |
| 208 | struct lpfc_rport_data *rdata; |
| 209 | struct fc_rport *rport; |
| 210 | struct lpfc_vport *vport; |
| 211 | struct lpfc_hba *phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 212 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 213 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 214 | int put_node; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 215 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 216 | int fcf_inuse = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 217 | unsigned long iflags; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 218 | |
| 219 | rport = ndlp->rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 220 | vport = ndlp->vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 221 | shost = lpfc_shost_from_vport(vport); |
| 222 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 223 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 224 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 225 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 226 | |
| 227 | if (!rport) |
| 228 | return fcf_inuse; |
| 229 | |
| 230 | name = (uint8_t *) &ndlp->nlp_portname; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 231 | phba = vport->phba; |
| 232 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 233 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 234 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 235 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 236 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 237 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 238 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 239 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 240 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 241 | "3182 dev_loss_tmo_handler x%06x, rport x%px flg x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 242 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 243 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 244 | /* |
| 245 | * lpfc_nlp_remove if reached with dangling rport drops the |
| 246 | * reference. To make sure that does not happen clear rport |
| 247 | * pointer in ndlp before lpfc_nlp_put. |
| 248 | */ |
| 249 | rdata = rport->dd_data; |
| 250 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 251 | /* Don't defer this if we are in the process of deleting the vport |
| 252 | * or unloading the driver. The unload will cleanup the node |
| 253 | * appropriately we just need to cleanup the ndlp rport info here. |
| 254 | */ |
| 255 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 256 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 257 | /* flush the target */ |
| 258 | lpfc_sli_abort_iocb(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 259 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
| 260 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 261 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 262 | put_node = rdata->pnode != NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 263 | rdata->pnode = NULL; |
| 264 | ndlp->rport = NULL; |
| 265 | if (put_node) |
| 266 | lpfc_nlp_put(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 267 | put_device(&rport->dev); |
| 268 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 269 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 270 | } |
| 271 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 272 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 273 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 274 | "0284 Devloss timeout Ignored on " |
| 275 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 276 | "NPort x%x\n", |
| 277 | *name, *(name+1), *(name+2), *(name+3), |
| 278 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 279 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 280 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 281 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 282 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 283 | put_node = rdata->pnode != NULL; |
| 284 | rdata->pnode = NULL; |
| 285 | ndlp->rport = NULL; |
| 286 | if (put_node) |
| 287 | lpfc_nlp_put(ndlp); |
| 288 | put_device(&rport->dev); |
| 289 | |
| 290 | if (ndlp->nlp_type & NLP_FABRIC) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 291 | return fcf_inuse; |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 292 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 293 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 294 | warn_on = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 295 | lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 296 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 297 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 298 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 299 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 300 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 301 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 302 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 303 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 304 | *name, *(name+1), *(name+2), *(name+3), |
| 305 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 306 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 307 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 308 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 309 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 310 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 311 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 312 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 313 | *name, *(name+1), *(name+2), *(name+3), |
| 314 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 315 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 316 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 317 | } |
| 318 | |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 319 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 320 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 321 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 322 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 323 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 324 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 325 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 326 | return fcf_inuse; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 331 | * @phba: Pointer to hba context object. |
| 332 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 333 | * @nlp_did: remote node identifer with devloss timeout. |
| 334 | * |
| 335 | * This function is called from the worker thread after invoking devloss |
| 336 | * timeout handler and releasing the reference count for the ndlp with |
| 337 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 338 | * timeout of the last remote node which had been in use of FCF, when this |
| 339 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 340 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 341 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 342 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 343 | * engine is in FCF discovery process, the devloss timeout state shall |
| 344 | * be set for either the FCF table scan process or roundrobin failover |
| 345 | * process to unregister the in-use FCF. |
| 346 | **/ |
| 347 | static void |
| 348 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 349 | uint32_t nlp_did) |
| 350 | { |
| 351 | /* If devloss timeout happened to a remote node when FCF had no |
| 352 | * longer been in-use, do nothing. |
| 353 | */ |
| 354 | if (!fcf_inuse) |
| 355 | return; |
| 356 | |
| 357 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 358 | spin_lock_irq(&phba->hbalock); |
| 359 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 360 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 361 | spin_unlock_irq(&phba->hbalock); |
| 362 | return; |
| 363 | } |
| 364 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 365 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 366 | "2847 Last remote node (x%x) using " |
| 367 | "FCF devloss tmo\n", nlp_did); |
| 368 | } |
| 369 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 370 | spin_unlock_irq(&phba->hbalock); |
| 371 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 372 | "2868 Devloss tmo to FCF rediscovery " |
| 373 | "in progress\n"); |
| 374 | return; |
| 375 | } |
| 376 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 377 | spin_unlock_irq(&phba->hbalock); |
| 378 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 379 | "2869 Devloss tmo to idle FIP engine, " |
| 380 | "unreg in-use FCF and rescan.\n"); |
| 381 | /* Unregister in-use FCF and rescan */ |
| 382 | lpfc_unregister_fcf_rescan(phba); |
| 383 | return; |
| 384 | } |
| 385 | spin_unlock_irq(&phba->hbalock); |
| 386 | if (phba->hba_flag & FCF_TS_INPROG) |
| 387 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 388 | "2870 FCF table scan in progress\n"); |
| 389 | if (phba->hba_flag & FCF_RR_INPROG) |
| 390 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 391 | "2871 FLOGI roundrobin FCF failover " |
| 392 | "in progress\n"); |
| 393 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 394 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 395 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 396 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 398 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 399 | * @phba: Pointer to hba context object. |
| 400 | * |
| 401 | * This function is called from the functions which need to post |
| 402 | * events from interrupt context. This function allocates data |
| 403 | * structure required for posting event. It also keeps track of |
| 404 | * number of events pending and prevent event storm when there are |
| 405 | * too many events. |
| 406 | **/ |
| 407 | struct lpfc_fast_path_event * |
| 408 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 409 | struct lpfc_fast_path_event *ret; |
| 410 | |
| 411 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 412 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 413 | return NULL; |
| 414 | |
| 415 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 416 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 417 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 418 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 419 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 420 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 421 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 426 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 427 | * @phba: Pointer to hba context object. |
| 428 | * @evt: Event object which need to be freed. |
| 429 | * |
| 430 | * This function frees the data structure required for posting |
| 431 | * events. |
| 432 | **/ |
| 433 | void |
| 434 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 435 | struct lpfc_fast_path_event *evt) { |
| 436 | |
| 437 | atomic_dec(&phba->fast_event_count); |
| 438 | kfree(evt); |
| 439 | } |
| 440 | |
| 441 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 442 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 443 | * @phba: Pointer to hba context object. |
| 444 | * @evtp: Event data structure. |
| 445 | * |
| 446 | * This function is called from worker thread, when the interrupt |
| 447 | * context need to post an event. This function posts the event |
| 448 | * to fc transport netlink interface. |
| 449 | **/ |
| 450 | static void |
| 451 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 452 | struct lpfc_work_evt *evtp) |
| 453 | { |
| 454 | unsigned long evt_category, evt_sub_category; |
| 455 | struct lpfc_fast_path_event *fast_evt_data; |
| 456 | char *evt_data; |
| 457 | uint32_t evt_data_size; |
| 458 | struct Scsi_Host *shost; |
| 459 | |
| 460 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 461 | work_evt); |
| 462 | |
| 463 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 464 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 465 | fabric_evt.subcategory; |
| 466 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 467 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 468 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 469 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 470 | evt_data_size = sizeof(fast_evt_data->un. |
| 471 | read_check_error); |
| 472 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 473 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 474 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 475 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 476 | } else { |
| 477 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 478 | return; |
| 479 | } |
| 480 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 481 | switch (evt_sub_category) { |
| 482 | case LPFC_EVENT_QFULL: |
| 483 | case LPFC_EVENT_DEVBSY: |
| 484 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 485 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 486 | break; |
| 487 | case LPFC_EVENT_CHECK_COND: |
| 488 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 489 | evt_data_size = sizeof(fast_evt_data->un. |
| 490 | check_cond_evt); |
| 491 | break; |
| 492 | case LPFC_EVENT_VARQUEDEPTH: |
| 493 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 494 | evt_data_size = sizeof(fast_evt_data->un. |
| 495 | queue_depth_evt); |
| 496 | break; |
| 497 | default: |
| 498 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 499 | return; |
| 500 | } |
| 501 | } else { |
| 502 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 503 | return; |
| 504 | } |
| 505 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 506 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 507 | fc_host_post_vendor_event(shost, |
| 508 | fc_get_event_number(), |
| 509 | evt_data_size, |
| 510 | evt_data, |
| 511 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 512 | |
| 513 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 514 | return; |
| 515 | } |
| 516 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 518 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | { |
| 520 | struct lpfc_work_evt *evtp = NULL; |
| 521 | struct lpfc_nodelist *ndlp; |
| 522 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 523 | int fcf_inuse; |
| 524 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 526 | spin_lock_irq(&phba->hbalock); |
| 527 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 529 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 530 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 532 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 533 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 534 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 536 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 537 | /* decrement the node reference count held |
| 538 | * for this queued work |
| 539 | */ |
| 540 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 542 | case LPFC_EVT_DEV_LOSS: |
| 543 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 544 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 545 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 546 | /* decrement the node reference count held for |
| 547 | * this queued work |
| 548 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 549 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 550 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 551 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 552 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 553 | fcf_inuse, |
| 554 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 555 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 557 | if (phba->link_state < LPFC_LINK_DOWN) |
| 558 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 559 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 560 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 561 | complete((struct completion *)(evtp->evt_arg2)); |
| 562 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 563 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 564 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 565 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 566 | *(int *)(evtp->evt_arg1) = 0; |
| 567 | complete((struct completion *)(evtp->evt_arg2)); |
| 568 | break; |
| 569 | case LPFC_EVT_OFFLINE: |
| 570 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 571 | lpfc_sli_brdrestart(phba); |
| 572 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 573 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 574 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 575 | complete((struct completion *)(evtp->evt_arg2)); |
| 576 | break; |
| 577 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 578 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 579 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 580 | lpfc_sli_brdreset(phba); |
| 581 | lpfc_hba_down_post(phba); |
| 582 | *(int *)(evtp->evt_arg1) = |
| 583 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 584 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 585 | complete((struct completion *)(evtp->evt_arg2)); |
| 586 | break; |
| 587 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 588 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 589 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | = (phba->pport->stopped) |
| 591 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 592 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | complete((struct completion *)(evtp->evt_arg2)); |
| 594 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 595 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 596 | lpfc_send_fastpath_evt(phba, evtp); |
| 597 | free_evt = 0; |
| 598 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 599 | case LPFC_EVT_RESET_HBA: |
| 600 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 601 | lpfc_reset_hba(phba); |
| 602 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | } |
| 604 | if (free_evt) |
| 605 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 608 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | |
| 610 | } |
| 611 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 612 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 613 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | { |
| 615 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 616 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 617 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 618 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 619 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 621 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | ha_copy = phba->work_ha; |
| 623 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 624 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 626 | /* First, try to post the next mailbox command to SLI4 device */ |
| 627 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 628 | lpfc_sli4_post_async_mbox(phba); |
| 629 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 630 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 631 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | lpfc_handle_eratt(phba); |
| 633 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 634 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | lpfc_sli_handle_mb_event(phba); |
| 636 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 637 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 638 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 639 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 640 | /* Process SLI4 events */ |
| 641 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 642 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 643 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 644 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 645 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 646 | if (phba->hba_flag & ASYNC_EVENT) |
| 647 | lpfc_sli4_async_event_proc(phba); |
| 648 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 649 | spin_lock_irq(&phba->hbalock); |
| 650 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 651 | spin_unlock_irq(&phba->hbalock); |
| 652 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 653 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 654 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 655 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 656 | } |
| 657 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 658 | vports = lpfc_create_vport_work_array(phba); |
| 659 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 660 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 661 | /* |
| 662 | * We could have no vports in array if unloading, so if |
| 663 | * this happens then just use the pport |
| 664 | */ |
| 665 | if (vports[i] == NULL && i == 0) |
| 666 | vport = phba->pport; |
| 667 | else |
| 668 | vport = vports[i]; |
| 669 | if (vport == NULL) |
| 670 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 671 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 672 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 673 | vport->work_port_events &= ~work_port_events; |
| 674 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 675 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 676 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 677 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 678 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 679 | if (work_port_events & WORKER_HB_TMO) |
| 680 | lpfc_hb_timeout_handler(phba); |
| 681 | if (work_port_events & WORKER_MBOX_TMO) |
| 682 | lpfc_mbox_timeout_handler(phba); |
| 683 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 684 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 685 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 686 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 687 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 688 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 689 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 690 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 691 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 692 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 693 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 694 | status >>= (4*LPFC_ELS_RING); |
James Smart | 0c9c6a7 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 695 | if (pring && (status & HA_RXMASK || |
| 696 | pring->flag & LPFC_DEFERRED_RING_EVENT || |
| 697 | phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 698 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 699 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 161df4f0 | 2018-01-30 15:58:54 -0800 | [diff] [blame] | 700 | /* Preserve legacy behavior. */ |
| 701 | if (!(phba->hba_flag & HBA_SP_QUEUE_EVT)) |
| 702 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 703 | } else { |
James Smart | 15498dc | 2019-09-21 20:58:59 -0700 | [diff] [blame] | 704 | /* Driver could have abort request completed in queue |
| 705 | * when link goes down. Allow for this transition. |
| 706 | */ |
| 707 | if (phba->link_state >= LPFC_LINK_DOWN || |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 708 | phba->link_flag & LS_MDS_LOOPBACK) { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 709 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 710 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 711 | (status & |
| 712 | HA_RXMASK)); |
| 713 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 714 | } |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 715 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 716 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 717 | /* |
| 718 | * Turn on Ring interrupts |
| 719 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 720 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 721 | spin_lock_irq(&phba->hbalock); |
| 722 | control = readl(phba->HCregaddr); |
| 723 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 724 | lpfc_debugfs_slow_ring_trc(phba, |
| 725 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 726 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 727 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 728 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 729 | writel(control, phba->HCregaddr); |
| 730 | readl(phba->HCregaddr); /* flush */ |
| 731 | } else { |
| 732 | lpfc_debugfs_slow_ring_trc(phba, |
| 733 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 734 | control, ha_copy, 0); |
| 735 | } |
| 736 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | } |
| 738 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 739 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | } |
| 741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | int |
| 743 | lpfc_do_work(void *p) |
| 744 | { |
| 745 | struct lpfc_hba *phba = p; |
| 746 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 748 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 749 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 750 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 752 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 753 | /* wait and check worker queue activities */ |
| 754 | rc = wait_event_interruptible(phba->work_waitq, |
| 755 | (test_and_clear_bit(LPFC_DATA_READY, |
| 756 | &phba->data_flags) |
| 757 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 758 | /* Signal wakeup shall terminate the worker thread */ |
| 759 | if (rc) { |
| 760 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 761 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 763 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 765 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 767 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 768 | phba->worker_thread = NULL; |
| 769 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 770 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * 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] | 776 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | * embedding it in the IOCB. |
| 778 | */ |
| 779 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | uint32_t evt) |
| 782 | { |
| 783 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 784 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 788 | * be queued to worker thread for processing |
| 789 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 790 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | if (!evtp) |
| 792 | return 0; |
| 793 | |
| 794 | evtp->evt_arg1 = arg1; |
| 795 | evtp->evt_arg2 = arg2; |
| 796 | evtp->evt = evt; |
| 797 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 798 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 799 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 800 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 802 | lpfc_worker_wake_up(phba); |
| 803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | return 1; |
| 805 | } |
| 806 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 807 | void |
| 808 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 809 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 810 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 811 | struct lpfc_hba *phba = vport->phba; |
| 812 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | |
| 814 | 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] | 815 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 816 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 817 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 818 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 819 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 820 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 821 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 822 | lpfc_unreg_rpi(vport, ndlp); |
| 823 | |
| 824 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 825 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 826 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 827 | continue; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 828 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 829 | remove |
| 830 | ? NLP_EVT_DEVICE_RM |
| 831 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | } |
| 833 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 834 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 835 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 837 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 839 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 843 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 844 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 846 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 847 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 848 | /* Cleanup any outstanding received buffers */ |
| 849 | lpfc_cleanup_rcv_buffers(vport); |
| 850 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 851 | /* Cleanup any outstanding RSCN activity */ |
| 852 | lpfc_els_flush_rscn(vport); |
| 853 | |
| 854 | /* Cleanup any outstanding ELS commands */ |
| 855 | lpfc_els_flush_cmd(vport); |
| 856 | |
| 857 | lpfc_cleanup_rpis(vport, 0); |
| 858 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 859 | /* Turn off discovery timer if its running */ |
| 860 | lpfc_can_disctmo(vport); |
| 861 | } |
| 862 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 863 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 864 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 865 | { |
| 866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 867 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 868 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 869 | fc_host_post_event(shost, fc_get_event_number(), |
| 870 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 871 | |
| 872 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 873 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 874 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 875 | |
| 876 | lpfc_port_link_failure(vport); |
| 877 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 878 | /* Stop delayed Nport discovery */ |
| 879 | spin_lock_irq(shost->host_lock); |
| 880 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 881 | spin_unlock_irq(shost->host_lock); |
| 882 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 883 | } |
| 884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 886 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 888 | struct lpfc_vport *vport = phba->pport; |
| 889 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 890 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 891 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 892 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 894 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 895 | return 0; |
James Smart | 19193ff | 2019-03-12 16:30:25 -0700 | [diff] [blame] | 896 | |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 897 | /* Block all SCSI stack I/Os */ |
| 898 | lpfc_scsi_dev_block(phba); |
| 899 | |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 900 | phba->defer_flogi_acc_flag = false; |
| 901 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 902 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 903 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 904 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 905 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 906 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 907 | if (phba->sli4_hba.conf_trunk) { |
| 908 | phba->trunk_link.link0.state = 0; |
| 909 | phba->trunk_link.link1.state = 0; |
| 910 | phba->trunk_link.link2.state = 0; |
| 911 | phba->trunk_link.link3.state = 0; |
James Smart | 845d032 | 2019-08-14 16:57:01 -0700 | [diff] [blame] | 912 | phba->sli4_hba.link_state.logical_speed = |
| 913 | LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 2977a09 | 2018-12-13 15:17:52 -0800 | [diff] [blame] | 914 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 915 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 916 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 917 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 918 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 919 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 920 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 921 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 922 | /* Issue a LINK DOWN event to all nodes */ |
| 923 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 924 | |
| 925 | vports[i]->fc_myDID = 0; |
| 926 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 927 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 928 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 929 | if (phba->nvmet_support) |
| 930 | lpfc_nvmet_update_targetport(phba); |
| 931 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 932 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 933 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 934 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 935 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 936 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 937 | |
| 938 | /* Clean up any SLI3 firmware default rpi's */ |
| 939 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 940 | goto skip_unreg_did; |
| 941 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 942 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 943 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 944 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 945 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 947 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 953 | skip_unreg_did: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 954 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 955 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 956 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 957 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 959 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 960 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 961 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 962 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 963 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 964 | } |
| 965 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 966 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 968 | phba->pport->rcv_flogi_cnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 969 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 971 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | } |
| 973 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 974 | static void |
| 975 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 977 | struct lpfc_nodelist *ndlp; |
| 978 | |
| 979 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | a3da825 | 2018-03-05 12:04:06 -0800 | [diff] [blame] | 980 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 981 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 982 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 984 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 985 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 986 | /* On Linkup its safe to clean up the ndlp |
| 987 | * from Fabric connections. |
| 988 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 989 | if (ndlp->nlp_DID != Fabric_DID) |
| 990 | lpfc_unreg_rpi(vport, ndlp); |
| 991 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 992 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 993 | /* Fail outstanding IO now since device is |
| 994 | * marked for PLOGI. |
| 995 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | lpfc_unreg_rpi(vport, ndlp); |
| 997 | } |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | static void |
| 1002 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 1003 | { |
| 1004 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1005 | struct lpfc_hba *phba = vport->phba; |
| 1006 | |
| 1007 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 1008 | return; |
| 1009 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1010 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1011 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 1012 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 1013 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1014 | /* If NPIV is not enabled, only bring the physical port up */ |
| 1015 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1016 | (vport != phba->pport)) |
| 1017 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 1019 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1020 | fc_host_post_event(shost, fc_get_event_number(), |
| 1021 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1022 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1023 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1024 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1025 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1026 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1027 | vport->fc_ns_retry = 0; |
| 1028 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1030 | if (vport->fc_flag & FC_LBIT) |
| 1031 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static int |
| 1036 | lpfc_linkup(struct lpfc_hba *phba) |
| 1037 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1038 | struct lpfc_vport **vports; |
| 1039 | int i; |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1040 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1041 | |
| 1042 | phba->link_state = LPFC_LINK_UP; |
| 1043 | |
| 1044 | /* Unblock fabric iocbs if they are blocked */ |
| 1045 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1046 | del_timer_sync(&phba->fabric_block_timer); |
| 1047 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1048 | vports = lpfc_create_vport_work_array(phba); |
| 1049 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1050 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1051 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1052 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | |
James Smart | d496b9a | 2018-10-23 13:41:08 -0700 | [diff] [blame] | 1054 | /* Clear the pport flogi counter in case the link down was |
| 1055 | * absorbed without an ACQE. No lock here - in worker thread |
| 1056 | * and discovery is synchronized. |
| 1057 | */ |
| 1058 | spin_lock_irq(shost->host_lock); |
| 1059 | phba->pport->rcv_flogi_cnt = 0; |
| 1060 | spin_unlock_irq(shost->host_lock); |
James Smart | 0a9e968 | 2018-11-29 16:09:36 -0800 | [diff] [blame] | 1061 | |
| 1062 | /* reinitialize initial FLOGI flag */ |
| 1063 | phba->hba_flag &= ~(HBA_FLOGI_ISSUED); |
| 1064 | phba->defer_flogi_acc_flag = false; |
| 1065 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * This routine handles processing a CLEAR_LA mailbox |
| 1071 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1072 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1075 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1076 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1078 | struct lpfc_vport *vport = pmb->vport; |
| 1079 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1080 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1081 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | uint32_t control; |
| 1083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1085 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1086 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1087 | |
| 1088 | /* Check for error */ |
| 1089 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1090 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1091 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1092 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1093 | "state x%x\n", |
| 1094 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1095 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | goto out; |
| 1097 | } |
| 1098 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1099 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1100 | phba->link_state = LPFC_HBA_READY; |
| 1101 | |
| 1102 | spin_lock_irq(&phba->hbalock); |
| 1103 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1104 | control = readl(phba->HCregaddr); |
| 1105 | control |= HC_LAINT_ENA; |
| 1106 | writel(control, phba->HCregaddr); |
| 1107 | readl(phba->HCregaddr); /* flush */ |
| 1108 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1109 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1110 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | out: |
| 1113 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1114 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1115 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1116 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1118 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1119 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1120 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1122 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1123 | |
| 1124 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | |
| 1126 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1128 | control = readl(phba->HCregaddr); |
| 1129 | control |= HC_LAINT_ENA; |
| 1130 | writel(control, phba->HCregaddr); |
| 1131 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1132 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | |
| 1134 | return; |
| 1135 | } |
| 1136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1137 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1138 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1139 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1140 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1141 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1142 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1143 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1144 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1145 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1146 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1147 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1148 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1149 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1150 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1151 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1152 | return; |
| 1153 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1154 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1155 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1156 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1157 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1158 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1159 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1160 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1161 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1162 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1163 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1165 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1166 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1167 | */ |
James Smart | 6bfb1620 | 2019-11-04 16:56:59 -0800 | [diff] [blame] | 1168 | if (vport->port_state != LPFC_FLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1169 | lpfc_initial_flogi(vport); |
James Smart | 6bfb1620 | 2019-11-04 16:56:59 -0800 | [diff] [blame] | 1170 | else if (vport->fc_flag & FC_PT2PT) |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1171 | lpfc_disc_start(vport); |
James Smart | 6bfb1620 | 2019-11-04 16:56:59 -0800 | [diff] [blame] | 1172 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1173 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | |
| 1175 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1176 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1177 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1178 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1179 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1180 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1181 | |
| 1182 | lpfc_linkdown(phba); |
| 1183 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1184 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1185 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1186 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1187 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1188 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | return; |
| 1190 | } |
| 1191 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1192 | /** |
| 1193 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1194 | * @phba pointer to the struct lpfc_hba for this port. |
| 1195 | * This fucnction resets the round robin bit mask and clears the |
| 1196 | * fcf priority list. The list deletions are done while holding the |
| 1197 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1198 | * from the lpfc_fcf_pri record. |
| 1199 | **/ |
| 1200 | void |
| 1201 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1202 | { |
| 1203 | struct lpfc_fcf_pri *fcf_pri; |
| 1204 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1205 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1206 | spin_lock_irq(&phba->hbalock); |
| 1207 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1208 | &phba->fcf.fcf_pri_list, list) { |
| 1209 | list_del_init(&fcf_pri->list); |
| 1210 | fcf_pri->fcf_rec.flag = 0; |
| 1211 | } |
| 1212 | spin_unlock_irq(&phba->hbalock); |
| 1213 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1215 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1216 | { |
| 1217 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1218 | |
| 1219 | if (mboxq->u.mb.mbxStatus) { |
| 1220 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1221 | "2017 REG_FCFI mbxStatus error x%x " |
| 1222 | "HBA state x%x\n", |
| 1223 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1224 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1228 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1229 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1230 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1231 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1232 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1233 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1234 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1235 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1236 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1237 | goto fail_out; |
| 1238 | |
| 1239 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1240 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1241 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1242 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1243 | if (vport->port_state != LPFC_FLOGI) { |
| 1244 | phba->hba_flag |= FCF_RR_INPROG; |
| 1245 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1246 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1247 | goto out; |
| 1248 | } |
| 1249 | spin_unlock_irq(&phba->hbalock); |
| 1250 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1251 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1252 | fail_out: |
| 1253 | spin_lock_irq(&phba->hbalock); |
| 1254 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1255 | spin_unlock_irq(&phba->hbalock); |
| 1256 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1257 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | /** |
| 1261 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1262 | * @fab_name: pointer to fabric name. |
| 1263 | * @new_fcf_record: pointer to fcf record. |
| 1264 | * |
| 1265 | * This routine compare the fcf record's fabric name with provided |
| 1266 | * fabric name. If the fabric name are identical this function |
| 1267 | * returns 1 else return 0. |
| 1268 | **/ |
| 1269 | static uint32_t |
| 1270 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1271 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1272 | 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] | 1273 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1274 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1275 | return 0; |
| 1276 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1277 | return 0; |
| 1278 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1279 | return 0; |
| 1280 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1281 | return 0; |
| 1282 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1283 | return 0; |
| 1284 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1285 | return 0; |
| 1286 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1287 | return 0; |
| 1288 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1292 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1293 | * @fab_name: pointer to fabric name. |
| 1294 | * @new_fcf_record: pointer to fcf record. |
| 1295 | * |
| 1296 | * This routine compare the fcf record's switch name with provided |
| 1297 | * switch name. If the switch name are identical this function |
| 1298 | * returns 1 else return 0. |
| 1299 | **/ |
| 1300 | static uint32_t |
| 1301 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1302 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1303 | 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] | 1304 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1305 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1306 | return 0; |
| 1307 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1308 | return 0; |
| 1309 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1310 | return 0; |
| 1311 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1312 | return 0; |
| 1313 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1314 | return 0; |
| 1315 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1316 | return 0; |
| 1317 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1318 | return 0; |
| 1319 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1323 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1324 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1325 | * @new_fcf_record: pointer to fcf record. |
| 1326 | * |
| 1327 | * This routine compare the fcf record's mac address with HBA's |
| 1328 | * FCF mac address. If the mac addresses are identical this function |
| 1329 | * returns 1 else return 0. |
| 1330 | **/ |
| 1331 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1332 | 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] | 1333 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1334 | 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] | 1335 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1336 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1337 | return 0; |
| 1338 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1339 | return 0; |
| 1340 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1341 | return 0; |
| 1342 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1343 | return 0; |
| 1344 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1345 | return 0; |
| 1346 | return 1; |
| 1347 | } |
| 1348 | |
| 1349 | static bool |
| 1350 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1351 | { |
| 1352 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1356 | * lpfc_update_fcf_record - Update driver fcf record |
| 1357 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1358 | * @phba: pointer to lpfc hba data structure. |
| 1359 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1360 | * @new_fcf_record: pointer to hba fcf record. |
| 1361 | * |
| 1362 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1363 | * record. This routine is called with the host lock held. |
| 1364 | **/ |
| 1365 | static void |
| 1366 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1367 | struct fcf_record *new_fcf_record |
| 1368 | ) |
| 1369 | { |
| 1370 | struct lpfc_fcf_pri *fcf_pri; |
| 1371 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1372 | lockdep_assert_held(&phba->hbalock); |
| 1373 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1374 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1375 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1376 | /* FCF record priority */ |
| 1377 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1378 | |
| 1379 | } |
| 1380 | |
| 1381 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1382 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1383 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1384 | * @new_fcf_record: pointer to fcf record. |
| 1385 | * |
| 1386 | * This routine copies the FCF information from the FCF |
| 1387 | * record to lpfc_hba data structure. |
| 1388 | **/ |
| 1389 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1390 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1391 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1392 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1393 | /* Fabric name */ |
| 1394 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1395 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1396 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1397 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1398 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1399 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1400 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1401 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1402 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1403 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1404 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1405 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1406 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1407 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1408 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1409 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1410 | /* Mac address */ |
| 1411 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1412 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1413 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1414 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1415 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1416 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1417 | /* FCF record index */ |
| 1418 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1419 | /* FCF record priority */ |
| 1420 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1421 | /* Switch name */ |
| 1422 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1423 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1424 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1425 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1426 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1427 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1428 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1429 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1430 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1431 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1432 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1433 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1434 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1435 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1436 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1437 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1441 | * lpfc_update_fcf_record - Update driver fcf record |
| 1442 | * @phba: pointer to lpfc hba data structure. |
| 1443 | * @fcf_rec: pointer to driver fcf record. |
| 1444 | * @new_fcf_record: pointer to hba fcf record. |
| 1445 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1446 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1447 | * @flag: flag bits to be set to the driver fcf record. |
| 1448 | * |
| 1449 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1450 | * together with the address mode, vlan_id, and other informations. This |
| 1451 | * routine is called with the host lock held. |
| 1452 | **/ |
| 1453 | static void |
| 1454 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1455 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1456 | uint16_t vlan_id, uint32_t flag) |
| 1457 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1458 | lockdep_assert_held(&phba->hbalock); |
| 1459 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1460 | /* Copy the fields from the HBA's FCF record */ |
| 1461 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1462 | /* Update other fields of driver FCF record */ |
| 1463 | fcf_rec->addr_mode = addr_mode; |
| 1464 | fcf_rec->vlan_id = vlan_id; |
| 1465 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1466 | __lpfc_update_fcf_record_pri(phba, |
| 1467 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1468 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1472 | * lpfc_register_fcf - Register the FCF with hba. |
| 1473 | * @phba: pointer to lpfc hba data structure. |
| 1474 | * |
| 1475 | * This routine issues a register fcfi mailbox command to register |
| 1476 | * the fcf with HBA. |
| 1477 | **/ |
| 1478 | static void |
| 1479 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1480 | { |
| 1481 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1482 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1483 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1484 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1485 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1486 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1487 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1488 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1489 | return; |
| 1490 | } |
| 1491 | |
| 1492 | /* The FCF is already registered, start discovery */ |
| 1493 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1494 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1495 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1496 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1497 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1498 | phba->hba_flag |= FCF_RR_INPROG; |
| 1499 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1500 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1501 | return; |
| 1502 | } |
| 1503 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1504 | return; |
| 1505 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1506 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1507 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1508 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1509 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1510 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1511 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1512 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1513 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1514 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1515 | |
| 1516 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1517 | fcf_mbxq->vport = phba->pport; |
| 1518 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1519 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1520 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1521 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1522 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1523 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1524 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1525 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1526 | |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1532 | * @phba: pointer to lpfc hba data structure. |
| 1533 | * @new_fcf_record: pointer to fcf record. |
| 1534 | * @boot_flag: Indicates if this record used by boot bios. |
| 1535 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1536 | * @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] | 1537 | * |
| 1538 | * This routine compare the fcf record with connect list obtained from the |
| 1539 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1540 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1541 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1542 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1543 | * used for this FCF when the function returns. |
| 1544 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1545 | * 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] | 1546 | * 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] | 1547 | **/ |
| 1548 | static int |
| 1549 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1550 | struct fcf_record *new_fcf_record, |
| 1551 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1552 | uint16_t *vlan_id) |
| 1553 | { |
| 1554 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1555 | int i, j, fcf_vlan_id = 0; |
| 1556 | |
| 1557 | /* Find the lowest VLAN id in the FCF record */ |
| 1558 | for (i = 0; i < 512; i++) { |
| 1559 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1560 | fcf_vlan_id = i * 8; |
| 1561 | j = 0; |
| 1562 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1563 | j++; |
| 1564 | fcf_vlan_id++; |
| 1565 | } |
| 1566 | break; |
| 1567 | } |
| 1568 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1569 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1570 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1571 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1572 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1573 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1574 | return 0; |
| 1575 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1576 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1577 | *boot_flag = 0; |
| 1578 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1579 | new_fcf_record); |
| 1580 | if (phba->valid_vlan) |
| 1581 | *vlan_id = phba->vlan_id; |
| 1582 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1583 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1584 | return 1; |
| 1585 | } |
| 1586 | |
| 1587 | /* |
| 1588 | * If there are no FCF connection table entry, driver connect to all |
| 1589 | * FCFs. |
| 1590 | */ |
| 1591 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1592 | *boot_flag = 0; |
| 1593 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1594 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1595 | |
| 1596 | /* |
| 1597 | * When there are no FCF connect entries, use driver's default |
| 1598 | * addressing mode - FPMA. |
| 1599 | */ |
| 1600 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1601 | *addr_mode = LPFC_FCF_FPMA; |
| 1602 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1603 | /* If FCF record report a vlan id use that vlan id */ |
| 1604 | if (fcf_vlan_id) |
| 1605 | *vlan_id = fcf_vlan_id; |
| 1606 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1607 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1608 | return 1; |
| 1609 | } |
| 1610 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1611 | list_for_each_entry(conn_entry, |
| 1612 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1613 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1614 | continue; |
| 1615 | |
| 1616 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1617 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1618 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1619 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1620 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1621 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1622 | new_fcf_record)) |
| 1623 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1624 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1625 | /* |
| 1626 | * If the vlan bit map does not have the bit set for the |
| 1627 | * vlan id to be used, then it is not a match. |
| 1628 | */ |
| 1629 | if (!(new_fcf_record->vlan_bitmap |
| 1630 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1631 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1632 | continue; |
| 1633 | } |
| 1634 | |
| 1635 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1636 | * If connection record does not support any addressing mode, |
| 1637 | * skip the FCF record. |
| 1638 | */ |
| 1639 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1640 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1641 | continue; |
| 1642 | |
| 1643 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1644 | * Check if the connection record specifies a required |
| 1645 | * addressing mode. |
| 1646 | */ |
| 1647 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1648 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1649 | |
| 1650 | /* |
| 1651 | * If SPMA required but FCF not support this continue. |
| 1652 | */ |
| 1653 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1654 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1655 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1656 | continue; |
| 1657 | |
| 1658 | /* |
| 1659 | * If FPMA required but FCF not support this continue. |
| 1660 | */ |
| 1661 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1662 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1663 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1664 | continue; |
| 1665 | } |
| 1666 | |
| 1667 | /* |
| 1668 | * This fcf record matches filtering criteria. |
| 1669 | */ |
| 1670 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1671 | *boot_flag = 1; |
| 1672 | else |
| 1673 | *boot_flag = 0; |
| 1674 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1675 | /* |
| 1676 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1677 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1678 | * by FCF, allow fabric to pick the addressing mode. |
| 1679 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1680 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1681 | new_fcf_record); |
| 1682 | /* |
| 1683 | * If the user specified a required address mode, assign that |
| 1684 | * address mode |
| 1685 | */ |
| 1686 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1687 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1688 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1689 | FCFCNCT_AM_SPMA) ? |
| 1690 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1691 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1692 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1693 | * addr mode only if FCF support the addr_mode. |
| 1694 | */ |
| 1695 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1696 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1697 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1698 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1699 | *addr_mode = LPFC_FCF_SPMA; |
| 1700 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1701 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1702 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1703 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1704 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1705 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1706 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1707 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1708 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1709 | /* |
| 1710 | * If no vlan id is specified in connect list, use the vlan id |
| 1711 | * in the FCF record |
| 1712 | */ |
| 1713 | else if (fcf_vlan_id) |
| 1714 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1715 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1716 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1717 | |
| 1718 | return 1; |
| 1719 | } |
| 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1725 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1726 | * @phba: pointer to lpfc hba data structure. |
| 1727 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1728 | * |
| 1729 | * This function check if there is any fcoe event pending while driver |
| 1730 | * scan FCF entries. If there is any pending event, it will restart the |
| 1731 | * FCF saning and return 1 else return 0. |
| 1732 | */ |
| 1733 | int |
| 1734 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1735 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1736 | /* |
| 1737 | * If the Link is up and no FCoE events while in the |
| 1738 | * FCF discovery, no need to restart FCF discovery. |
| 1739 | */ |
| 1740 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1741 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1742 | return 0; |
| 1743 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1744 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1745 | "2768 Pending link or FCF event during current " |
| 1746 | "handling of the previous event: link_state:x%x, " |
| 1747 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1748 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1749 | phba->fcoe_eventtag); |
| 1750 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1751 | spin_lock_irq(&phba->hbalock); |
| 1752 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1753 | spin_unlock_irq(&phba->hbalock); |
| 1754 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1755 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1756 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1757 | "2780 Restart FCF table scan due to " |
| 1758 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1759 | "evt_tag_current:x%x\n", |
| 1760 | phba->fcoe_eventtag_at_fcf_scan, |
| 1761 | phba->fcoe_eventtag); |
| 1762 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1763 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1764 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1765 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1766 | * flag |
| 1767 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1768 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1769 | "2833 Stop FCF discovery process due to link " |
| 1770 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1771 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1772 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1773 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1774 | spin_unlock_irq(&phba->hbalock); |
| 1775 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1776 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1777 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1778 | if (unreg_fcf) { |
| 1779 | spin_lock_irq(&phba->hbalock); |
| 1780 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1781 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1782 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1783 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1784 | return 1; |
| 1785 | } |
| 1786 | |
| 1787 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1788 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1789 | * @phba: pointer to lpfc hba data structure. |
| 1790 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1791 | * |
| 1792 | * This function makes an running random selection decision on FCF record to |
| 1793 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1794 | * probability. To perform integer manunipulation of random numbers with |
| 1795 | * 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] | 1796 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1797 | * |
| 1798 | * Returns true when outcome is for the newly read FCF record should be |
| 1799 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1800 | * chosen FCF record. |
| 1801 | **/ |
| 1802 | static bool |
| 1803 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1804 | { |
| 1805 | uint32_t rand_num; |
| 1806 | |
| 1807 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1808 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1809 | |
| 1810 | /* Decision with probability 1/fcf_cnt */ |
| 1811 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1812 | return true; |
| 1813 | else |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
| 1817 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1818 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1819 | * @phba: pointer to lpfc hba data structure. |
| 1820 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1821 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1822 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1823 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1824 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1825 | * SGE parsing, and endianness swapping. |
| 1826 | * |
| 1827 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1828 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1829 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1830 | static struct fcf_record * |
| 1831 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1832 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1833 | { |
| 1834 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1835 | struct lpfc_mbx_sge sge; |
| 1836 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1837 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1838 | union lpfc_sli4_cfg_shdr *shdr; |
| 1839 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1840 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1841 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1842 | * routine only uses a single SGE. |
| 1843 | */ |
| 1844 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1845 | if (unlikely(!mboxq->sge_array)) { |
| 1846 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1847 | "2524 Failed to get the non-embedded SGE " |
| 1848 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1849 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1850 | } |
| 1851 | virt_addr = mboxq->sge_array->addr[0]; |
| 1852 | |
| 1853 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1854 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1855 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1856 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1857 | 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] | 1858 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1859 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1860 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1861 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1862 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1863 | "2726 READ_FCF_RECORD Indicates empty " |
| 1864 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1865 | else |
| 1866 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1867 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1868 | "with status x%x add_status x%x, " |
| 1869 | "mbx\n", shdr_status, shdr_add_status); |
| 1870 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1871 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1872 | |
| 1873 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1874 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1875 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1876 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1877 | *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] | 1878 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1879 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1880 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1881 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1882 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1883 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1884 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1885 | return new_fcf_record; |
| 1886 | } |
| 1887 | |
| 1888 | /** |
| 1889 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1890 | * @phba: pointer to lpfc hba data structure. |
| 1891 | * @fcf_record: pointer to the fcf record. |
| 1892 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1893 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1894 | * |
| 1895 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1896 | * enabled. |
| 1897 | **/ |
| 1898 | static void |
| 1899 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1900 | struct fcf_record *fcf_record, |
| 1901 | uint16_t vlan_id, |
| 1902 | uint16_t next_fcf_index) |
| 1903 | { |
| 1904 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1905 | "2764 READ_FCF_RECORD:\n" |
| 1906 | "\tFCF_Index : x%x\n" |
| 1907 | "\tFCF_Avail : x%x\n" |
| 1908 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1909 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1910 | "\tFIP_Priority : x%x\n" |
| 1911 | "\tMAC_Provider : x%x\n" |
| 1912 | "\tLowest VLANID : x%x\n" |
| 1913 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1914 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1915 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1916 | "\tNext_FCF_Index: x%x\n", |
| 1917 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1918 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1919 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1920 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1921 | fcf_record->fip_priority, |
| 1922 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1923 | vlan_id, |
| 1924 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1925 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1926 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1927 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1928 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1929 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1930 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1931 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1932 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1933 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1934 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1935 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1936 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1937 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1938 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1939 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1940 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1941 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1942 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1943 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1944 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1945 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1946 | next_fcf_index); |
| 1947 | } |
| 1948 | |
| 1949 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1950 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1951 | * @phba: pointer to lpfc hba data structure. |
| 1952 | * @fcf_rec: pointer to an existing FCF record. |
| 1953 | * @new_fcf_record: pointer to a new FCF record. |
| 1954 | * @new_vlan_id: vlan id from the new FCF record. |
| 1955 | * |
| 1956 | * This function performs matching test of a new FCF record against an existing |
| 1957 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1958 | * will not be used as part of the FCF record matching criteria. |
| 1959 | * |
| 1960 | * Returns true if all the fields matching, otherwise returns false. |
| 1961 | */ |
| 1962 | static bool |
| 1963 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1964 | struct lpfc_fcf_rec *fcf_rec, |
| 1965 | struct fcf_record *new_fcf_record, |
| 1966 | uint16_t new_vlan_id) |
| 1967 | { |
| 1968 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1969 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1970 | return false; |
| 1971 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1972 | return false; |
| 1973 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1974 | return false; |
| 1975 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1976 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1977 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1978 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1979 | return true; |
| 1980 | } |
| 1981 | |
| 1982 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1983 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1984 | * @vport: Pointer to vport object. |
| 1985 | * @fcf_index: index to next fcf. |
| 1986 | * |
| 1987 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1988 | * When this function is invoked, there will be a current fcf registered |
| 1989 | * for flogi. |
| 1990 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1991 | * 1 for stop flogi on currently registered fcf; |
| 1992 | */ |
| 1993 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1994 | { |
| 1995 | struct lpfc_hba *phba = vport->phba; |
| 1996 | int rc; |
| 1997 | |
| 1998 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1999 | spin_lock_irq(&phba->hbalock); |
| 2000 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2001 | spin_unlock_irq(&phba->hbalock); |
| 2002 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2003 | "2872 Devloss tmo with no eligible " |
| 2004 | "FCF, unregister in-use FCF (x%x) " |
| 2005 | "and rescan FCF table\n", |
| 2006 | phba->fcf.current_rec.fcf_indx); |
| 2007 | lpfc_unregister_fcf_rescan(phba); |
| 2008 | goto stop_flogi_current_fcf; |
| 2009 | } |
| 2010 | /* Mark the end to FLOGI roundrobin failover */ |
| 2011 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 2012 | /* Allow action to new fcf asynchronous event */ |
| 2013 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 2014 | spin_unlock_irq(&phba->hbalock); |
| 2015 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2016 | "2865 No FCF available, stop roundrobin FCF " |
| 2017 | "failover and change port state:x%x/x%x\n", |
| 2018 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 2019 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 2020 | |
| 2021 | if (!phba->fcf.fcf_redisc_attempted) { |
| 2022 | lpfc_unregister_fcf(phba); |
| 2023 | |
| 2024 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 2025 | if (!rc) { |
| 2026 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2027 | "3195 Rediscover FCF table\n"); |
| 2028 | phba->fcf.fcf_redisc_attempted = 1; |
| 2029 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 2030 | } else { |
| 2031 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2032 | "3196 Rediscover FCF table " |
| 2033 | "failed. Status:x%x\n", rc); |
| 2034 | } |
| 2035 | } else { |
| 2036 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2037 | "3197 Already rediscover FCF table " |
| 2038 | "attempted. No more retry\n"); |
| 2039 | } |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2040 | goto stop_flogi_current_fcf; |
| 2041 | } else { |
| 2042 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 2043 | "2794 Try FLOGI roundrobin FCF failover to " |
| 2044 | "(x%x)\n", fcf_index); |
| 2045 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 2046 | if (rc) |
| 2047 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 2048 | "2761 FLOGI roundrobin FCF failover " |
| 2049 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 2050 | rc, phba->fcf.current_rec.fcf_indx); |
| 2051 | else |
| 2052 | goto stop_flogi_current_fcf; |
| 2053 | } |
| 2054 | return 0; |
| 2055 | |
| 2056 | stop_flogi_current_fcf: |
| 2057 | lpfc_can_disctmo(vport); |
| 2058 | return 1; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2062 | * lpfc_sli4_fcf_pri_list_del |
| 2063 | * @phba: pointer to lpfc hba data structure. |
| 2064 | * @fcf_index the index of the fcf record to delete |
| 2065 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2066 | * If it is one the list then it is removed from the list, and the flag |
| 2067 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2068 | * record from the list. |
| 2069 | **/ |
| 2070 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2071 | uint16_t fcf_index) |
| 2072 | { |
| 2073 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2074 | |
| 2075 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2076 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2077 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2078 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2079 | new_fcf_pri->fcf_rec.flag); |
| 2080 | spin_lock_irq(&phba->hbalock); |
| 2081 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2082 | if (phba->fcf.current_rec.priority == |
| 2083 | new_fcf_pri->fcf_rec.priority) |
| 2084 | phba->fcf.eligible_fcf_cnt--; |
| 2085 | list_del_init(&new_fcf_pri->list); |
| 2086 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2087 | } |
| 2088 | spin_unlock_irq(&phba->hbalock); |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * lpfc_sli4_set_fcf_flogi_fail |
| 2093 | * @phba: pointer to lpfc hba data structure. |
| 2094 | * @fcf_index the index of the fcf record to update |
| 2095 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2096 | * flag so the the round robin slection for the particular priority level |
| 2097 | * will try a different fcf record that does not have this bit set. |
| 2098 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2099 | * adding it to the priority list. |
| 2100 | **/ |
| 2101 | void |
| 2102 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2103 | { |
| 2104 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2105 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2106 | spin_lock_irq(&phba->hbalock); |
| 2107 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2108 | spin_unlock_irq(&phba->hbalock); |
| 2109 | } |
| 2110 | |
| 2111 | /** |
| 2112 | * lpfc_sli4_fcf_pri_list_add |
| 2113 | * @phba: pointer to lpfc hba data structure. |
| 2114 | * @fcf_index the index of the fcf record to add |
| 2115 | * This routine checks the priority of the fcf_index to be added. |
| 2116 | * If it is a lower priority than the current head of the fcf_pri list |
| 2117 | * then it is added to the list in the right order. |
| 2118 | * If it is the same priority as the current head of the list then it |
| 2119 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2120 | * If the fcf_index to be added is of a higher priority than the current |
| 2121 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2122 | * rr_bmask and it is added to the head of the list. |
| 2123 | * returns: |
| 2124 | * 0=success 1=failure |
| 2125 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2126 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2127 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2128 | struct fcf_record *new_fcf_record) |
| 2129 | { |
| 2130 | uint16_t current_fcf_pri; |
| 2131 | uint16_t last_index; |
| 2132 | struct lpfc_fcf_pri *fcf_pri; |
| 2133 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2134 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2135 | int ret; |
| 2136 | |
| 2137 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2138 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2139 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2140 | fcf_index, new_fcf_record->fip_priority, |
| 2141 | new_fcf_pri->fcf_rec.flag); |
| 2142 | spin_lock_irq(&phba->hbalock); |
| 2143 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2144 | list_del_init(&new_fcf_pri->list); |
| 2145 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2146 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2147 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2148 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2149 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2150 | new_fcf_pri->fcf_rec.fcf_index); |
| 2151 | goto out; |
| 2152 | } |
| 2153 | |
| 2154 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2155 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2156 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2157 | ret = 0; /* Empty rr list */ |
| 2158 | goto out; |
| 2159 | } |
| 2160 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2161 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2162 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2163 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2164 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2165 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2166 | /* fcfs_at_this_priority_level = 1; */ |
| 2167 | phba->fcf.eligible_fcf_cnt = 1; |
| 2168 | } else |
| 2169 | /* fcfs_at_this_priority_level++; */ |
| 2170 | phba->fcf.eligible_fcf_cnt++; |
| 2171 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2172 | new_fcf_pri->fcf_rec.fcf_index); |
| 2173 | goto out; |
| 2174 | } |
| 2175 | |
| 2176 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2177 | &phba->fcf.fcf_pri_list, list) { |
| 2178 | if (new_fcf_pri->fcf_rec.priority <= |
| 2179 | fcf_pri->fcf_rec.priority) { |
| 2180 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2181 | list_add(&new_fcf_pri->list, |
| 2182 | &phba->fcf.fcf_pri_list); |
| 2183 | else |
| 2184 | list_add(&new_fcf_pri->list, |
| 2185 | &((struct lpfc_fcf_pri *) |
| 2186 | fcf_pri->list.prev)->list); |
| 2187 | ret = 0; |
| 2188 | goto out; |
| 2189 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2190 | || new_fcf_pri->fcf_rec.priority < |
| 2191 | next_fcf_pri->fcf_rec.priority) { |
| 2192 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2193 | ret = 0; |
| 2194 | goto out; |
| 2195 | } |
| 2196 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2197 | continue; |
| 2198 | |
| 2199 | } |
| 2200 | ret = 1; |
| 2201 | out: |
| 2202 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2203 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2204 | spin_unlock_irq(&phba->hbalock); |
| 2205 | return ret; |
| 2206 | } |
| 2207 | |
| 2208 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2209 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2210 | * @phba: pointer to lpfc hba data structure. |
| 2211 | * @mboxq: pointer to mailbox object. |
| 2212 | * |
| 2213 | * This function iterates through all the fcf records available in |
| 2214 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2215 | * the FCF for discovery it registers the FCF record and kicks start |
| 2216 | * discovery. |
| 2217 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2218 | * use an FCF record which matches fabric name and mac address of the |
| 2219 | * currently used FCF record. |
| 2220 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2221 | * used by BOOT_BIOS. |
| 2222 | */ |
| 2223 | void |
| 2224 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2225 | { |
| 2226 | struct fcf_record *new_fcf_record; |
| 2227 | uint32_t boot_flag, addr_mode; |
| 2228 | uint16_t fcf_index, next_fcf_index; |
| 2229 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2230 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2231 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2232 | int rc; |
| 2233 | |
| 2234 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2235 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2236 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2237 | return; |
| 2238 | } |
| 2239 | |
| 2240 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2241 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2242 | &next_fcf_index); |
| 2243 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2244 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2245 | "2765 Mailbox command READ_FCF_RECORD " |
| 2246 | "failed to retrieve a FCF record.\n"); |
| 2247 | /* Let next new FCF event trigger fast failover */ |
| 2248 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2249 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2250 | spin_unlock_irq(&phba->hbalock); |
| 2251 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2252 | return; |
| 2253 | } |
| 2254 | |
| 2255 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2256 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2257 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2258 | |
| 2259 | /* Log the FCF record information if turned on */ |
| 2260 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2261 | next_fcf_index); |
| 2262 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2263 | /* |
| 2264 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2265 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2266 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2267 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2268 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2269 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2270 | bf_get(lpfc_fcf_record_fcf_index, |
| 2271 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2272 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2273 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2274 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2275 | bf_get(lpfc_fcf_record_fcf_index, |
| 2276 | new_fcf_record), |
| 2277 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2278 | new_fcf_record), |
| 2279 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2280 | new_fcf_record), |
| 2281 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2282 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2283 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2284 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2285 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2286 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2287 | phba->fcf.current_rec.fcf_indx) { |
| 2288 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2289 | "2862 FCF (x%x) matches property " |
| 2290 | "of in-use FCF (x%x)\n", |
| 2291 | bf_get(lpfc_fcf_record_fcf_index, |
| 2292 | new_fcf_record), |
| 2293 | phba->fcf.current_rec.fcf_indx); |
| 2294 | goto read_next_fcf; |
| 2295 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2296 | /* |
| 2297 | * In case the current in-use FCF record becomes |
| 2298 | * invalid/unavailable during FCF discovery that |
| 2299 | * was not triggered by fast FCF failover process, |
| 2300 | * treat it as fast FCF failover. |
| 2301 | */ |
| 2302 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2303 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2304 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2305 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2306 | "(x%x), enter FCF failover " |
| 2307 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2308 | phba->fcf.current_rec.fcf_indx); |
| 2309 | spin_lock_irq(&phba->hbalock); |
| 2310 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2311 | spin_unlock_irq(&phba->hbalock); |
| 2312 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2313 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2314 | LPFC_FCOE_FCF_GET_FIRST); |
| 2315 | return; |
| 2316 | } |
| 2317 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2318 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2319 | } else { |
| 2320 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2321 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2322 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2323 | if (rc) |
| 2324 | goto read_next_fcf; |
| 2325 | } |
| 2326 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2327 | /* |
| 2328 | * 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] | 2329 | * FCF record for the discovery. The condition that a rescan |
| 2330 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2331 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2332 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2333 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2334 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2335 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2336 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2337 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2338 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2339 | phba->fcf.current_rec.fcf_indx) { |
| 2340 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2341 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2342 | /* Stop FCF redisc wait timer */ |
| 2343 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2344 | phba); |
| 2345 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2346 | /* Fast failover, mark completed */ |
| 2347 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2348 | spin_unlock_irq(&phba->hbalock); |
| 2349 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2350 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2351 | "FCF (x%x), port_state:x%x, " |
| 2352 | "fc_flag:x%x\n", |
| 2353 | phba->fcf.current_rec.fcf_indx, |
| 2354 | phba->pport->port_state, |
| 2355 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2356 | goto out; |
| 2357 | } else |
| 2358 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2359 | "2863 New FCF (x%x) matches " |
| 2360 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2361 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2362 | new_fcf_record), |
| 2363 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2364 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2365 | /* |
| 2366 | * Read next FCF record from HBA searching for the matching |
| 2367 | * with in-use record only if not during the fast failover |
| 2368 | * period. In case of fast failover period, it shall try to |
| 2369 | * determine whether the FCF record just read should be the |
| 2370 | * next candidate. |
| 2371 | */ |
| 2372 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2373 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2374 | goto read_next_fcf; |
| 2375 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2376 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2377 | /* |
| 2378 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2379 | * period; otherwise, update on current FCF record. |
| 2380 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2381 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2382 | fcf_rec = &phba->fcf.failover_rec; |
| 2383 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2384 | fcf_rec = &phba->fcf.current_rec; |
| 2385 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2386 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2387 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2388 | * If the driver FCF record does not have boot flag |
| 2389 | * set and new hba fcf record has boot flag set, use |
| 2390 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2391 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2392 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2393 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2394 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2395 | "2837 Update current FCF record " |
| 2396 | "(x%x) with new FCF record (x%x)\n", |
| 2397 | fcf_rec->fcf_indx, |
| 2398 | bf_get(lpfc_fcf_record_fcf_index, |
| 2399 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2400 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2401 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2402 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2403 | goto read_next_fcf; |
| 2404 | } |
| 2405 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2406 | * If the driver FCF record has boot flag set and the |
| 2407 | * new hba FCF record does not have boot flag, read |
| 2408 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2409 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2410 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2411 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2412 | goto read_next_fcf; |
| 2413 | } |
| 2414 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2415 | * If the new hba FCF record has lower priority value |
| 2416 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2417 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2418 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2419 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2420 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2421 | "2838 Update current FCF record " |
| 2422 | "(x%x) with new FCF record (x%x)\n", |
| 2423 | fcf_rec->fcf_indx, |
| 2424 | bf_get(lpfc_fcf_record_fcf_index, |
| 2425 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2426 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2427 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2428 | /* Reset running random FCF selection count */ |
| 2429 | phba->fcf.eligible_fcf_cnt = 1; |
| 2430 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2431 | /* Update running random FCF selection count */ |
| 2432 | phba->fcf.eligible_fcf_cnt++; |
| 2433 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2434 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2435 | if (select_new_fcf) { |
| 2436 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2437 | "2839 Update current FCF record " |
| 2438 | "(x%x) with new FCF record (x%x)\n", |
| 2439 | fcf_rec->fcf_indx, |
| 2440 | bf_get(lpfc_fcf_record_fcf_index, |
| 2441 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2442 | /* Choose the new FCF by random selection */ |
| 2443 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2444 | new_fcf_record, |
| 2445 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2446 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2447 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2448 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2449 | goto read_next_fcf; |
| 2450 | } |
| 2451 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2452 | * This is the first suitable FCF record, choose this record for |
| 2453 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2454 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2455 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2456 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2457 | "2840 Update initial FCF candidate " |
| 2458 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2459 | bf_get(lpfc_fcf_record_fcf_index, |
| 2460 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2461 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2462 | addr_mode, vlan_id, (boot_flag ? |
| 2463 | BOOT_ENABLE : 0)); |
| 2464 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2465 | /* Setup initial running random FCF selection count */ |
| 2466 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2467 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2468 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2469 | goto read_next_fcf; |
| 2470 | |
| 2471 | read_next_fcf: |
| 2472 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2473 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2474 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2475 | /* |
| 2476 | * Case of FCF fast failover scan |
| 2477 | */ |
| 2478 | |
| 2479 | /* |
| 2480 | * It has not found any suitable FCF record, cancel |
| 2481 | * FCF scan inprogress, and do nothing |
| 2482 | */ |
| 2483 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2484 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2485 | "2782 No suitable FCF found: " |
| 2486 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2487 | phba->fcoe_eventtag_at_fcf_scan, |
| 2488 | bf_get(lpfc_fcf_record_fcf_index, |
| 2489 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2490 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2491 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2492 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2493 | spin_unlock_irq(&phba->hbalock); |
| 2494 | /* Unregister in-use FCF and rescan */ |
| 2495 | lpfc_printf_log(phba, KERN_INFO, |
| 2496 | LOG_FIP, |
| 2497 | "2864 On devloss tmo " |
| 2498 | "unreg in-use FCF and " |
| 2499 | "rescan FCF table\n"); |
| 2500 | lpfc_unregister_fcf_rescan(phba); |
| 2501 | return; |
| 2502 | } |
| 2503 | /* |
| 2504 | * Let next new FCF event trigger fast failover |
| 2505 | */ |
| 2506 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2507 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2508 | return; |
| 2509 | } |
| 2510 | /* |
| 2511 | * It has found a suitable FCF record that is not |
| 2512 | * the same as in-use FCF record, unregister the |
| 2513 | * in-use FCF record, replace the in-use FCF record |
| 2514 | * with the new FCF record, mark FCF fast failover |
| 2515 | * completed, and then start register the new FCF |
| 2516 | * record. |
| 2517 | */ |
| 2518 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2519 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2520 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2521 | |
| 2522 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2523 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2524 | "2842 Replace in-use FCF (x%x) " |
| 2525 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2526 | phba->fcf.current_rec.fcf_indx, |
| 2527 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2528 | memcpy(&phba->fcf.current_rec, |
| 2529 | &phba->fcf.failover_rec, |
| 2530 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2531 | /* |
| 2532 | * Mark the fast FCF failover rediscovery completed |
| 2533 | * and the start of the first round of the roundrobin |
| 2534 | * FCF failover. |
| 2535 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2536 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2537 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2538 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2539 | /* Register to the new FCF record */ |
| 2540 | lpfc_register_fcf(phba); |
| 2541 | } else { |
| 2542 | /* |
| 2543 | * In case of transaction period to fast FCF failover, |
| 2544 | * do nothing when search to the end of the FCF table. |
| 2545 | */ |
| 2546 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2547 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2548 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2549 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2550 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2551 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2552 | /* |
| 2553 | * In case the current in-use FCF record no |
| 2554 | * longer existed during FCF discovery that |
| 2555 | * was not triggered by fast FCF failover |
| 2556 | * process, treat it as fast FCF failover. |
| 2557 | */ |
| 2558 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2559 | "2841 In-use FCF record (x%x) " |
| 2560 | "not reported, entering fast " |
| 2561 | "FCF failover mode scanning.\n", |
| 2562 | phba->fcf.current_rec.fcf_indx); |
| 2563 | spin_lock_irq(&phba->hbalock); |
| 2564 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2565 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2566 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2567 | LPFC_FCOE_FCF_GET_FIRST); |
| 2568 | return; |
| 2569 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2570 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2571 | lpfc_register_fcf(phba); |
| 2572 | } |
| 2573 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2574 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2575 | return; |
| 2576 | |
| 2577 | out: |
| 2578 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2579 | lpfc_register_fcf(phba); |
| 2580 | |
| 2581 | return; |
| 2582 | } |
| 2583 | |
| 2584 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2585 | * 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] | 2586 | * @phba: pointer to lpfc hba data structure. |
| 2587 | * @mboxq: pointer to mailbox object. |
| 2588 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2589 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2590 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2591 | * performing the failover. If the FCF read back is not valid/available, it |
| 2592 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2593 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2594 | * newly read FCF record to the failover FCF record, unregister currently |
| 2595 | * registered FCF record, copy the failover FCF record to the current |
| 2596 | * FCF record, and then register the current FCF record before proceeding |
| 2597 | * to trying FLOGI on the new failover FCF. |
| 2598 | */ |
| 2599 | void |
| 2600 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2601 | { |
| 2602 | struct fcf_record *new_fcf_record; |
| 2603 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2604 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2605 | uint16_t current_fcf_index; |
| 2606 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2607 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2608 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2609 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2610 | if (phba->link_state < LPFC_LINK_UP) { |
| 2611 | spin_lock_irq(&phba->hbalock); |
| 2612 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2613 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2614 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2615 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2619 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2620 | &next_fcf_index); |
| 2621 | if (!new_fcf_record) { |
| 2622 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2623 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2624 | "failed to retrieve a FCF record. " |
| 2625 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2626 | phba->fcf.fcf_flag); |
| 2627 | lpfc_unregister_fcf_rescan(phba); |
| 2628 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2632 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2633 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2634 | |
| 2635 | /* Log the FCF record information if turned on */ |
| 2636 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2637 | next_fcf_index); |
| 2638 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2639 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2640 | if (!rc) { |
| 2641 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2642 | "2848 Remove ineligible FCF (x%x) from " |
| 2643 | "from roundrobin bmask\n", fcf_index); |
| 2644 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2645 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2646 | /* Perform next round of roundrobin FCF failover */ |
| 2647 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2648 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2649 | if (rc) |
| 2650 | goto out; |
| 2651 | goto error_out; |
| 2652 | } |
| 2653 | |
| 2654 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2655 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2656 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2657 | "FCF (x%x) back to FCF (x%x)\n", |
| 2658 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2659 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2660 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2661 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2662 | goto out; |
| 2663 | } |
| 2664 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2665 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2666 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2667 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2668 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2669 | spin_lock_irq(&phba->hbalock); |
| 2670 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2671 | new_fcf_record, addr_mode, vlan_id, |
| 2672 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2673 | spin_unlock_irq(&phba->hbalock); |
| 2674 | |
| 2675 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2676 | |
| 2677 | /* Unregister the current in-use FCF record */ |
| 2678 | lpfc_unregister_fcf(phba); |
| 2679 | |
| 2680 | /* Replace in-use record with the new record */ |
| 2681 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2682 | sizeof(struct lpfc_fcf_rec)); |
| 2683 | |
| 2684 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2685 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2686 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2687 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2688 | error_out: |
| 2689 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2690 | out: |
| 2691 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2696 | * @phba: pointer to lpfc hba data structure. |
| 2697 | * @mboxq: pointer to mailbox object. |
| 2698 | * |
| 2699 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2700 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2701 | * failover when a new FCF event happened. If the FCF read back is |
| 2702 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2703 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2704 | */ |
| 2705 | void |
| 2706 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2707 | { |
| 2708 | struct fcf_record *new_fcf_record; |
| 2709 | uint32_t boot_flag, addr_mode; |
| 2710 | uint16_t fcf_index, next_fcf_index; |
| 2711 | uint16_t vlan_id; |
| 2712 | int rc; |
| 2713 | |
| 2714 | /* If link state is not up, no need to proceed */ |
| 2715 | if (phba->link_state < LPFC_LINK_UP) |
| 2716 | goto out; |
| 2717 | |
| 2718 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2719 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2720 | goto out; |
| 2721 | |
| 2722 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2723 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2724 | &next_fcf_index); |
| 2725 | if (!new_fcf_record) { |
| 2726 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2727 | "2767 Mailbox command READ_FCF_RECORD " |
| 2728 | "failed to retrieve a FCF record.\n"); |
| 2729 | goto out; |
| 2730 | } |
| 2731 | |
| 2732 | /* Check the connection list for eligibility */ |
| 2733 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2734 | &addr_mode, &vlan_id); |
| 2735 | |
| 2736 | /* Log the FCF record information if turned on */ |
| 2737 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2738 | next_fcf_index); |
| 2739 | |
| 2740 | if (!rc) |
| 2741 | goto out; |
| 2742 | |
| 2743 | /* Update the eligible FCF record index bmask */ |
| 2744 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2745 | |
| 2746 | 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] | 2747 | |
| 2748 | out: |
| 2749 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2750 | } |
| 2751 | |
| 2752 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2753 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2754 | * @phba: pointer to lpfc hba data structure. |
| 2755 | * @mboxq: pointer to mailbox data structure. |
| 2756 | * |
| 2757 | * This function handles completion of init vfi mailbox command. |
| 2758 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2759 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2760 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2761 | { |
| 2762 | struct lpfc_vport *vport = mboxq->vport; |
| 2763 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2764 | /* |
| 2765 | * VFI not supported on interface type 0, just do the flogi |
| 2766 | * Also continue if the VFI is in use - just use the same one. |
| 2767 | */ |
| 2768 | if (mboxq->u.mb.mbxStatus && |
| 2769 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2770 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2771 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2772 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2773 | LOG_MBOX, |
| 2774 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2775 | mboxq->u.mb.mbxStatus); |
| 2776 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2777 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2778 | return; |
| 2779 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2780 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2781 | lpfc_initial_flogi(vport); |
| 2782 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2783 | return; |
| 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2788 | * @vport: pointer to lpfc_vport data structure. |
| 2789 | * |
| 2790 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2791 | * VPI for the physical port. |
| 2792 | */ |
| 2793 | void |
| 2794 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2795 | { |
| 2796 | LPFC_MBOXQ_t *mboxq; |
| 2797 | int rc; |
| 2798 | struct lpfc_hba *phba = vport->phba; |
| 2799 | |
| 2800 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2801 | if (!mboxq) { |
| 2802 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2803 | LOG_MBOX, "2892 Failed to allocate " |
| 2804 | "init_vfi mailbox\n"); |
| 2805 | return; |
| 2806 | } |
| 2807 | lpfc_init_vfi(mboxq, vport); |
| 2808 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2809 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2810 | if (rc == MBX_NOT_FINISHED) { |
| 2811 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2812 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2813 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2818 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2819 | * @phba: pointer to lpfc hba data structure. |
| 2820 | * @mboxq: pointer to mailbox data structure. |
| 2821 | * |
| 2822 | * This function handles completion of init vpi mailbox command. |
| 2823 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2824 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2825 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2826 | { |
| 2827 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2828 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2829 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2830 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2831 | if (mboxq->u.mb.mbxStatus) { |
| 2832 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2833 | LOG_MBOX, |
| 2834 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2835 | mboxq->u.mb.mbxStatus); |
| 2836 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2837 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2838 | return; |
| 2839 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2840 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2841 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2842 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2843 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2844 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2845 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2846 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2847 | if (!ndlp) |
| 2848 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2849 | LOG_DISCOVERY, |
| 2850 | "2731 Cannot find fabric " |
| 2851 | "controller node\n"); |
| 2852 | else |
| 2853 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2854 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2855 | return; |
| 2856 | } |
| 2857 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2858 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2859 | lpfc_initial_fdisc(vport); |
| 2860 | else { |
| 2861 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2862 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2863 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2864 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2865 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2866 | return; |
| 2867 | } |
| 2868 | |
| 2869 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2870 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2871 | * @vport: pointer to lpfc_vport data structure. |
| 2872 | * |
| 2873 | * This function issue a init_vpi mailbox command to initialize |
| 2874 | * VPI for the vport. |
| 2875 | */ |
| 2876 | void |
| 2877 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2878 | { |
| 2879 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2880 | int rc, vpi; |
| 2881 | |
| 2882 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2883 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2884 | if (!vpi) { |
| 2885 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2886 | LOG_MBOX, |
| 2887 | "3303 Failed to obtain vport vpi\n"); |
| 2888 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2889 | return; |
| 2890 | } |
| 2891 | vport->vpi = vpi; |
| 2892 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2893 | |
| 2894 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2895 | if (!mboxq) { |
| 2896 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2897 | LOG_MBOX, "2607 Failed to allocate " |
| 2898 | "init_vpi mailbox\n"); |
| 2899 | return; |
| 2900 | } |
| 2901 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2902 | mboxq->vport = vport; |
| 2903 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2904 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2905 | if (rc == MBX_NOT_FINISHED) { |
| 2906 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2907 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2908 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2913 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2914 | * @phba: pointer to lpfc hba data structure. |
| 2915 | * |
| 2916 | * This function loops through the list of vports on the @phba and issues an |
| 2917 | * FDISC if possible. |
| 2918 | */ |
| 2919 | void |
| 2920 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2921 | { |
| 2922 | struct lpfc_vport **vports; |
| 2923 | int i; |
| 2924 | |
| 2925 | vports = lpfc_create_vport_work_array(phba); |
| 2926 | if (vports != NULL) { |
| 2927 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2928 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2929 | continue; |
| 2930 | /* There are no vpi for this vport */ |
| 2931 | if (vports[i]->vpi > phba->max_vpi) { |
| 2932 | lpfc_vport_set_state(vports[i], |
| 2933 | FC_VPORT_FAILED); |
| 2934 | continue; |
| 2935 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2936 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2937 | lpfc_vport_set_state(vports[i], |
| 2938 | FC_VPORT_LINKDOWN); |
| 2939 | continue; |
| 2940 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2941 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2942 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2943 | continue; |
| 2944 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2945 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2946 | lpfc_initial_fdisc(vports[i]); |
| 2947 | else { |
| 2948 | lpfc_vport_set_state(vports[i], |
| 2949 | FC_VPORT_NO_FABRIC_SUPP); |
| 2950 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2951 | LOG_ELS, |
| 2952 | "0259 No NPIV " |
| 2953 | "Fabric support\n"); |
| 2954 | } |
| 2955 | } |
| 2956 | } |
| 2957 | lpfc_destroy_vport_work_array(phba, vports); |
| 2958 | } |
| 2959 | |
| 2960 | void |
| 2961 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2962 | { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2963 | struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2964 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2965 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2966 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2967 | /* |
| 2968 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2969 | * error (except VFI in use) and continue with the discovery. |
| 2970 | */ |
| 2971 | if (mboxq->u.mb.mbxStatus && |
| 2972 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2973 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2974 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2975 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2976 | "2018 REG_VFI mbxStatus error x%x " |
| 2977 | "HBA state x%x\n", |
| 2978 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2979 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2980 | /* FLOGI failed, use loop map to make discovery list */ |
| 2981 | lpfc_disc_list_loopmap(vport); |
| 2982 | /* Start discovery */ |
| 2983 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2984 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2985 | } |
| 2986 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2987 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2988 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2989 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2990 | /* If the VFI is already registered, there is nothing else to do |
| 2991 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2992 | * we should drop through to set the port state to ready. |
| 2993 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2994 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2995 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2996 | vport->fc_flag & FC_PT2PT)) |
| 2997 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2998 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2999 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3000 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3001 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3002 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3003 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 3004 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3005 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3006 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3007 | /* In case SLI4 FC loopback test, we are ready */ |
| 3008 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 3009 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 3010 | phba->link_state = LPFC_HBA_READY; |
| 3011 | goto out_free_mem; |
| 3012 | } |
| 3013 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3014 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3015 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 3016 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 3017 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 3018 | vport->phba->alpa_map[0], |
| 3019 | phba->link_state, phba->fc_topology); |
| 3020 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3021 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 3022 | /* |
| 3023 | * For private loop or for NPort pt2pt, |
| 3024 | * just start discovery and we are done. |
| 3025 | */ |
| 3026 | if ((vport->fc_flag & FC_PT2PT) || |
| 3027 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 3028 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 3029 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3030 | /* Use loop map to make discovery list */ |
| 3031 | lpfc_disc_list_loopmap(vport); |
| 3032 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3033 | if (vport->fc_flag & FC_PT2PT) |
| 3034 | vport->port_state = LPFC_VPORT_READY; |
| 3035 | else |
| 3036 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3037 | } else { |
| 3038 | lpfc_start_fdiscs(phba); |
| 3039 | lpfc_do_scr_ns_plogi(phba, vport); |
| 3040 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3043 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3044 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3045 | if (dmabuf) { |
| 3046 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 3047 | kfree(dmabuf); |
| 3048 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3049 | return; |
| 3050 | } |
| 3051 | |
| 3052 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3053 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3055 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3056 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3057 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3058 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3059 | struct serv_parm *sp = &vport->fc_sparam; |
| 3060 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | |
| 3062 | /* Check for error */ |
| 3063 | if (mb->mbxStatus) { |
| 3064 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3065 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3066 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3067 | "hba state x%x>\n", |
| 3068 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | goto out; |
| 3071 | } |
| 3072 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3073 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3074 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3075 | |
| 3076 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3077 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3078 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3079 | |
| 3080 | phba->fc_edtov = ed_tov; |
| 3081 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3082 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3083 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3084 | phba->fc_ratov = FF_DEF_RATOV; |
| 3085 | } |
| 3086 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3087 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3088 | 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] | 3089 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3090 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3091 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3092 | } |
| 3093 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3095 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | return; |
| 3098 | |
| 3099 | out: |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3100 | pmb->ctx_buf = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3102 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3103 | lpfc_issue_clear_la(phba, vport); |
| 3104 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | return; |
| 3106 | } |
| 3107 | |
| 3108 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3109 | 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] | 3110 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3111 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3112 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3113 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3114 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3115 | struct lpfc_dmabuf *mp; |
| 3116 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3117 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3118 | uint32_t fc_flags = 0; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3119 | unsigned long iflags; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3120 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3121 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3122 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3123 | |
| 3124 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3125 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3126 | case LPFC_LINK_SPEED_1GHZ: |
| 3127 | case LPFC_LINK_SPEED_2GHZ: |
| 3128 | case LPFC_LINK_SPEED_4GHZ: |
| 3129 | case LPFC_LINK_SPEED_8GHZ: |
| 3130 | case LPFC_LINK_SPEED_10GHZ: |
| 3131 | case LPFC_LINK_SPEED_16GHZ: |
| 3132 | case LPFC_LINK_SPEED_32GHZ: |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 3133 | case LPFC_LINK_SPEED_64GHZ: |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 3134 | case LPFC_LINK_SPEED_128GHZ: |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3135 | break; |
| 3136 | default: |
| 3137 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3138 | break; |
| 3139 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | } |
| 3141 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3142 | if (phba->fc_topology && |
| 3143 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3144 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3145 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3146 | phba->fc_topology, |
| 3147 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3148 | phba->fc_topology_changed = 1; |
| 3149 | } |
| 3150 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3151 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3152 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3153 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3154 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3155 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3156 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3158 | /* if npiv is enabled and this adapter supports npiv log |
| 3159 | * a message that npiv is not supported in this topology |
| 3160 | */ |
| 3161 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3162 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3163 | "1309 Link Up Event npiv not supported in loop " |
| 3164 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3165 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3166 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3167 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3169 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3170 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | |
| 3172 | if (i == 0) { |
| 3173 | phba->alpa_map[0] = 0; |
| 3174 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3175 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | int numalpa, j, k; |
| 3177 | union { |
| 3178 | uint8_t pamap[16]; |
| 3179 | struct { |
| 3180 | uint32_t wd1; |
| 3181 | uint32_t wd2; |
| 3182 | uint32_t wd3; |
| 3183 | uint32_t wd4; |
| 3184 | } pa; |
| 3185 | } un; |
| 3186 | numalpa = phba->alpa_map[0]; |
| 3187 | j = 0; |
| 3188 | while (j < numalpa) { |
| 3189 | memset(un.pamap, 0, 16); |
| 3190 | for (k = 1; j < numalpa; k++) { |
| 3191 | un.pamap[k - 1] = |
| 3192 | phba->alpa_map[j + 1]; |
| 3193 | j++; |
| 3194 | if (k == 16) |
| 3195 | break; |
| 3196 | } |
| 3197 | /* Link Up Event ALPA map */ |
| 3198 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3199 | KERN_WARNING, |
| 3200 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3201 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3202 | "ALPA map Data: x%x " |
| 3203 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3204 | un.pa.wd1, un.pa.wd2, |
| 3205 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3206 | } |
| 3207 | } |
| 3208 | } |
| 3209 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3210 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3211 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3212 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3213 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3214 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3215 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3216 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3218 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3219 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3220 | if (fc_flags) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3221 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3222 | vport->fc_flag |= fc_flags; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3223 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3224 | } |
| 3225 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3227 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3228 | if (!sparam_mbox) |
| 3229 | goto out; |
| 3230 | |
| 3231 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3232 | if (rc) { |
| 3233 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3234 | goto out; |
| 3235 | } |
| 3236 | sparam_mbox->vport = vport; |
| 3237 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3238 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3239 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3240 | mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3241 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3242 | kfree(mp); |
| 3243 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3244 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3245 | } |
| 3246 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3247 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3248 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3249 | if (!cfglink_mbox) |
| 3250 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3251 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3253 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3254 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3255 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3256 | if (rc == MBX_NOT_FINISHED) { |
| 3257 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3258 | goto out; |
| 3259 | } |
| 3260 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3261 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3262 | /* |
| 3263 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3264 | * is phase 1 implementation that support FCF index 0 and driver |
| 3265 | * defaults. |
| 3266 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3267 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3268 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3269 | GFP_KERNEL); |
| 3270 | if (unlikely(!fcf_record)) { |
| 3271 | lpfc_printf_log(phba, KERN_ERR, |
| 3272 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3273 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3274 | "fcf record\n"); |
| 3275 | rc = -ENODEV; |
| 3276 | goto out; |
| 3277 | } |
| 3278 | |
| 3279 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3280 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3281 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3282 | if (unlikely(rc)) { |
| 3283 | lpfc_printf_log(phba, KERN_ERR, |
| 3284 | LOG_MBOX | LOG_SLI, |
| 3285 | "2013 Could not manually add FCF " |
| 3286 | "record 0, status %d\n", rc); |
| 3287 | rc = -ENODEV; |
| 3288 | kfree(fcf_record); |
| 3289 | goto out; |
| 3290 | } |
| 3291 | kfree(fcf_record); |
| 3292 | } |
| 3293 | /* |
| 3294 | * The driver is expected to do FIP/FCF. Call the port |
| 3295 | * and get the FCF Table. |
| 3296 | */ |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3297 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3298 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3299 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3300 | return; |
| 3301 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3302 | /* This is the initial FCF discovery scan */ |
| 3303 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3304 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3305 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3306 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3307 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3308 | LPFC_FCOE_FCF_GET_FIRST); |
| 3309 | if (rc) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3310 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3311 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3312 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3313 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3314 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3315 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3316 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3318 | |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 3319 | /* Prepare for LINK up registrations */ |
| 3320 | memset(phba->os_host_name, 0, sizeof(phba->os_host_name)); |
| 3321 | scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s", |
| 3322 | init_utsname()->nodename); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3323 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3324 | out: |
| 3325 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3326 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 3327 | "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3328 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3329 | lpfc_issue_clear_la(phba, vport); |
| 3330 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3334 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | uint32_t control; |
| 3337 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3338 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3340 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3341 | control = readl(phba->HCregaddr); |
| 3342 | control |= HC_LAINT_ENA; |
| 3343 | writel(control, phba->HCregaddr); |
| 3344 | readl(phba->HCregaddr); /* flush */ |
| 3345 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3346 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | } |
| 3348 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3349 | static void |
| 3350 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3351 | { |
| 3352 | lpfc_linkdown(phba); |
| 3353 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3354 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3355 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3356 | } |
| 3357 | |
| 3358 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3360 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3362 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3363 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | */ |
| 3365 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3366 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3368 | struct lpfc_vport *vport = pmb->vport; |
| 3369 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3370 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3371 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3372 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3373 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3374 | uint8_t attn_type; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3375 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3377 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3378 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 3379 | if (pring) |
| 3380 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3381 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | /* Check for error */ |
| 3383 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3384 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3385 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3386 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3389 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | } |
| 3391 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3392 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3393 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | |
| 3395 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3396 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3397 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3398 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3400 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3402 | spin_unlock_irqrestore(shost->host_lock, iflags); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3403 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3404 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3406 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | if (phba->fc_eventTag != 0) |
| 3408 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3409 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | |
| 3411 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3412 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3413 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3414 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3415 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3416 | else |
| 3417 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 3418 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3419 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3421 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3422 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3423 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3426 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3427 | "1306 Link Up Event in loop back mode " |
| 3428 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3429 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3430 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3431 | la), |
| 3432 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3433 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3434 | } else { |
| 3435 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3436 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3437 | "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] | 3438 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3439 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3440 | la), |
| 3441 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3442 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3443 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3444 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3445 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3446 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3447 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3448 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3449 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3451 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3452 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3453 | "1308 Link Down Event in loop back mode " |
| 3454 | "x%x received " |
| 3455 | "Data: x%x x%x x%x\n", |
| 3456 | la->eventTag, phba->fc_eventTag, |
| 3457 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3458 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3459 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | b9da814 | 2019-11-04 16:57:04 -0800 | [diff] [blame] | 3460 | "1313 Link Down Unexpected FA WWPN Event x%x " |
| 3461 | "received Data: x%x x%x x%x x%x x%x\n", |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3462 | la->eventTag, phba->fc_eventTag, |
| 3463 | phba->pport->port_state, vport->fc_flag, |
| 3464 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3465 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3466 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3467 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3468 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3469 | "Data: x%x x%x x%x x%x x%x\n", |
| 3470 | la->eventTag, phba->fc_eventTag, |
| 3471 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3472 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3473 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3474 | lpfc_mbx_issue_link_down(phba); |
| 3475 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3476 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3477 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3478 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3479 | phba->fc_stat.LinkDown++; |
| 3480 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3481 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3483 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3484 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3485 | lpfc_mbx_issue_link_down(phba); |
| 3486 | } else |
| 3487 | lpfc_enable_la(phba); |
| 3488 | |
| 3489 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3490 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3491 | "Data: x%x x%x x%x\n", |
| 3492 | la->eventTag, phba->fc_eventTag, |
| 3493 | phba->pport->port_state, vport->fc_flag); |
| 3494 | /* |
| 3495 | * The cmnd that triggered this will be waiting for this |
| 3496 | * signal. |
| 3497 | */ |
| 3498 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3499 | if (phba->wait_4_mlo_maint_flg) { |
| 3500 | phba->wait_4_mlo_maint_flg = 0; |
| 3501 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3502 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3503 | } |
| 3504 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3505 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3506 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3507 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3508 | lpfc_issue_clear_la(phba, vport); |
| 3509 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3510 | "1311 fa %d\n", |
| 3511 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | } |
| 3513 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3514 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3516 | kfree(mp); |
| 3517 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3518 | return; |
| 3519 | } |
| 3520 | |
| 3521 | /* |
| 3522 | * This routine handles processing a REG_LOGIN mailbox |
| 3523 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3524 | * as the completion routine when the command is |
| 3525 | * handed off to the SLI layer. |
| 3526 | */ |
| 3527 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3528 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3530 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3531 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 3532 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3533 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3535 | pmb->ctx_buf = NULL; |
| 3536 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3538 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 3539 | "0002 rpi:%x DID:%x flg:%x %d map:%x x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3540 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3541 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3542 | ndlp->nlp_usg_map, ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3543 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3544 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3545 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3546 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3547 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3548 | /* We rcvd a rscn after issuing this |
| 3549 | * mbox reg login, we may have cycled |
| 3550 | * back through the state and be |
| 3551 | * back at reg login state so this |
| 3552 | * mbox needs to be ignored becase |
| 3553 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3554 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3555 | */ |
| 3556 | spin_lock_irq(shost->host_lock); |
| 3557 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3558 | spin_unlock_irq(shost->host_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3559 | |
| 3560 | /* |
| 3561 | * We cannot leave the RPI registered because |
| 3562 | * if we go thru discovery again for this ndlp |
| 3563 | * a subsequent REG_RPI will fail. |
| 3564 | */ |
| 3565 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3566 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | /* Call state machine */ |
| 3570 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3571 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3573 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3574 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3575 | /* decrement the node reference count held for this callback |
| 3576 | * function. |
| 3577 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3578 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | |
| 3580 | return; |
| 3581 | } |
| 3582 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | static void |
| 3584 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3585 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3586 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3587 | struct lpfc_vport *vport = pmb->vport; |
| 3588 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3589 | |
| 3590 | switch (mb->mbxStatus) { |
| 3591 | case 0x0011: |
| 3592 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3593 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3594 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3595 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3596 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3597 | /* If VPI is busy, reset the HBA */ |
| 3598 | case 0x9700: |
| 3599 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3600 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3601 | vport->vpi, mb->mbxStatus); |
| 3602 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3603 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3604 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3605 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3606 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3607 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3608 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3609 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3610 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3611 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3612 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3613 | /* |
| 3614 | * This shost reference might have been taken at the beginning of |
| 3615 | * lpfc_vport_delete() |
| 3616 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3617 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3618 | scsi_host_put(shost); |
| 3619 | } |
| 3620 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3621 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3622 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3623 | { |
| 3624 | struct lpfc_hba *phba = vport->phba; |
| 3625 | LPFC_MBOXQ_t *mbox; |
| 3626 | int rc; |
| 3627 | |
| 3628 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3629 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3630 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3631 | |
| 3632 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3633 | mbox->vport = vport; |
| 3634 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3635 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3636 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3637 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3638 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3639 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3640 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3641 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3642 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3643 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | static void |
| 3647 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3648 | { |
| 3649 | struct lpfc_vport *vport = pmb->vport; |
| 3650 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3651 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3652 | |
| 3653 | switch (mb->mbxStatus) { |
| 3654 | case 0x0011: |
| 3655 | case 0x9601: |
| 3656 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3657 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3658 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3659 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3660 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3661 | spin_lock_irq(shost->host_lock); |
| 3662 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3663 | spin_unlock_irq(shost->host_lock); |
| 3664 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3665 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3666 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3667 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3668 | if (phba->nvmet_support) |
| 3669 | lpfc_nvmet_update_targetport(phba); |
| 3670 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3671 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3672 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3673 | goto out; |
| 3674 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3675 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3676 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3677 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3678 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3679 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3680 | vport->num_disc_nodes = 0; |
| 3681 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3682 | if (vport->fc_npr_cnt) |
| 3683 | lpfc_els_disc_plogi(vport); |
| 3684 | |
| 3685 | if (!vport->num_disc_nodes) { |
| 3686 | spin_lock_irq(shost->host_lock); |
| 3687 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3688 | spin_unlock_irq(shost->host_lock); |
| 3689 | lpfc_can_disctmo(vport); |
| 3690 | } |
| 3691 | vport->port_state = LPFC_VPORT_READY; |
| 3692 | |
| 3693 | out: |
| 3694 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3695 | return; |
| 3696 | } |
| 3697 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3698 | /** |
| 3699 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3700 | * @phba: pointer to lpfc hba data structure. |
| 3701 | * |
| 3702 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3703 | * the list of static vports to be created. The function create vports |
| 3704 | * based on the information returned from the HBA. |
| 3705 | **/ |
| 3706 | void |
| 3707 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3708 | { |
| 3709 | LPFC_MBOXQ_t *pmb = NULL; |
| 3710 | MAILBOX_t *mb; |
| 3711 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3712 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3713 | struct fc_vport_identifiers vport_id; |
| 3714 | struct fc_vport *new_fc_vport; |
| 3715 | struct Scsi_Host *shost; |
| 3716 | struct lpfc_vport *vport; |
| 3717 | uint16_t offset = 0; |
| 3718 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3719 | struct lpfc_dmabuf *mp; |
| 3720 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3721 | |
| 3722 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3723 | if (!pmb) { |
| 3724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3725 | "0542 lpfc_create_static_vport failed to" |
| 3726 | " allocate mailbox memory\n"); |
| 3727 | return; |
| 3728 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3729 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3730 | mb = &pmb->u.mb; |
| 3731 | |
| 3732 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3733 | if (!vport_info) { |
| 3734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3735 | "0543 lpfc_create_static_vport failed to" |
| 3736 | " allocate vport_info\n"); |
| 3737 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3738 | return; |
| 3739 | } |
| 3740 | |
| 3741 | vport_buff = (uint8_t *) vport_info; |
| 3742 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3743 | /* free dma buffer from previous round */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3744 | if (pmb->ctx_buf) { |
| 3745 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3746 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3747 | kfree(mp); |
| 3748 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3749 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3750 | goto out; |
| 3751 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3752 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3753 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3754 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3755 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3756 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3757 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3758 | "0544 lpfc_create_static_vport failed to" |
| 3759 | " issue dump mailbox command ret 0x%x " |
| 3760 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3761 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3762 | goto out; |
| 3763 | } |
| 3764 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3765 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3766 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3767 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3768 | if (byte_count > sizeof(struct static_vport_info) - |
| 3769 | offset) |
| 3770 | byte_count = sizeof(struct static_vport_info) |
| 3771 | - offset; |
| 3772 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3773 | offset += byte_count; |
| 3774 | } else { |
| 3775 | if (mb->un.varDmp.word_cnt > |
| 3776 | sizeof(struct static_vport_info) - offset) |
| 3777 | mb->un.varDmp.word_cnt = |
| 3778 | sizeof(struct static_vport_info) |
| 3779 | - offset; |
| 3780 | byte_count = mb->un.varDmp.word_cnt; |
| 3781 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3782 | vport_buff + offset, |
| 3783 | byte_count); |
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 | offset += byte_count; |
| 3786 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3787 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3788 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3789 | offset < sizeof(struct static_vport_info)); |
| 3790 | |
| 3791 | |
| 3792 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3793 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3794 | != VPORT_INFO_REV)) { |
| 3795 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3796 | "0545 lpfc_create_static_vport bad" |
| 3797 | " information header 0x%x 0x%x\n", |
| 3798 | le32_to_cpu(vport_info->signature), |
| 3799 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3800 | |
| 3801 | goto out; |
| 3802 | } |
| 3803 | |
| 3804 | shost = lpfc_shost_from_vport(phba->pport); |
| 3805 | |
| 3806 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3807 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3808 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3809 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3810 | if (!vport_id.port_name || !vport_id.node_name) |
| 3811 | continue; |
| 3812 | |
| 3813 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3814 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3815 | vport_id.disable = false; |
| 3816 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3817 | |
| 3818 | if (!new_fc_vport) { |
| 3819 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3820 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3821 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3822 | continue; |
| 3823 | } |
| 3824 | |
| 3825 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3826 | vport->vport_flag |= STATIC_VPORT; |
| 3827 | } |
| 3828 | |
| 3829 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3830 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3831 | if (mbx_wait_rc != MBX_TIMEOUT) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3832 | if (pmb->ctx_buf) { |
| 3833 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3834 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3835 | kfree(mp); |
| 3836 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3837 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3838 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3839 | |
| 3840 | return; |
| 3841 | } |
| 3842 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3843 | /* |
| 3844 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3845 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3846 | * as the completion routine when the command is |
| 3847 | * handed off to the SLI layer. |
| 3848 | */ |
| 3849 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3850 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3853 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3854 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3855 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3856 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 3858 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 3859 | pmb->ctx_ndlp = NULL; |
| 3860 | pmb->ctx_buf = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3861 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3863 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3864 | "0258 Register Fabric login error: 0x%x\n", |
| 3865 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3867 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3868 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3870 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3871 | /* FLOGI failed, use loop map to make discovery list */ |
| 3872 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3874 | /* Start discovery */ |
| 3875 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3876 | /* Decrement the reference count to ndlp after the |
| 3877 | * reference to the ndlp are done. |
| 3878 | */ |
| 3879 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3880 | return; |
| 3881 | } |
| 3882 | |
| 3883 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3884 | /* Decrement the reference count to ndlp after the reference |
| 3885 | * to the ndlp are done. |
| 3886 | */ |
| 3887 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | return; |
| 3889 | } |
| 3890 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3891 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3892 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3893 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3895 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3897 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3898 | /* when physical port receive logo donot start |
| 3899 | * vport discovery */ |
| 3900 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3901 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3902 | else { |
| 3903 | shost = lpfc_shost_from_vport(vport); |
| 3904 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3905 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3906 | spin_unlock_irq(shost->host_lock); |
| 3907 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3908 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3912 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3913 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3914 | |
| 3915 | /* Drop the reference count from the mbox at the end after |
| 3916 | * all the current reference to the ndlp have been done. |
| 3917 | */ |
| 3918 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | return; |
| 3920 | } |
| 3921 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3922 | /* |
| 3923 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3924 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3925 | */ |
| 3926 | int |
| 3927 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3928 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3929 | /* Good status, issue CT Request to NameServer */ |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3930 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3931 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3932 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3933 | /* Cannot issue NameServer FCP Query, so finish up |
| 3934 | * discovery |
| 3935 | */ |
| 3936 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3937 | "0604 %s FC TYPE %x %s\n", |
| 3938 | "Failed to issue GID_FT to ", |
| 3939 | FC_TYPE_FCP, |
| 3940 | "Finishing discovery."); |
| 3941 | return 0; |
| 3942 | } |
| 3943 | vport->gidft_inp++; |
| 3944 | } |
| 3945 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 3946 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3947 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3948 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 3949 | /* Cannot issue NameServer NVME Query, so finish up |
| 3950 | * discovery |
| 3951 | */ |
| 3952 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3953 | "0605 %s FC_TYPE %x %s %d\n", |
| 3954 | "Failed to issue GID_FT to ", |
| 3955 | FC_TYPE_NVME, |
| 3956 | "Finishing discovery: gidftinp ", |
| 3957 | vport->gidft_inp); |
| 3958 | if (vport->gidft_inp == 0) |
| 3959 | return 0; |
| 3960 | } else |
| 3961 | vport->gidft_inp++; |
| 3962 | } |
| 3963 | return vport->gidft_inp; |
| 3964 | } |
| 3965 | |
James Smart | 7ea92eb | 2018-10-23 13:41:10 -0700 | [diff] [blame] | 3966 | /** |
| 3967 | * lpfc_issue_gidpt - issue a GID_PT for all N_Ports |
| 3968 | * @vport: The virtual port for which this call is being executed. |
| 3969 | * |
| 3970 | * This routine will issue a GID_PT to get a list of all N_Ports |
| 3971 | * |
| 3972 | * Return value : |
| 3973 | * 0 - Failure to issue a GID_PT |
| 3974 | * 1 - GID_PT issued |
| 3975 | **/ |
| 3976 | int |
| 3977 | lpfc_issue_gidpt(struct lpfc_vport *vport) |
| 3978 | { |
| 3979 | /* Good status, issue CT Request to NameServer */ |
| 3980 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) { |
| 3981 | /* Cannot issue NameServer FCP Query, so finish up |
| 3982 | * discovery |
| 3983 | */ |
| 3984 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3985 | "0606 %s Port TYPE %x %s\n", |
| 3986 | "Failed to issue GID_PT to ", |
| 3987 | GID_PT_N_PORT, |
| 3988 | "Finishing discovery."); |
| 3989 | return 0; |
| 3990 | } |
| 3991 | vport->gidft_inp++; |
| 3992 | return 1; |
| 3993 | } |
| 3994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | /* |
| 3996 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3997 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3998 | * as the completion routine when the command is |
| 3999 | * handed off to the SLI layer. |
| 4000 | */ |
| 4001 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4002 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4004 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4005 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 4006 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4009 | pmb->ctx_buf = NULL; |
| 4010 | pmb->ctx_ndlp = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4011 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4012 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4014 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4015 | "0260 Register NameServer error: 0x%x\n", |
| 4016 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4017 | |
| 4018 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4019 | /* decrement the node reference count held for this |
| 4020 | * callback function. |
| 4021 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4022 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4024 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4025 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4026 | |
| 4027 | /* If no other thread is using the ndlp, free it */ |
| 4028 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4030 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4031 | /* |
| 4032 | * RegLogin failed, use loop map to make discovery |
| 4033 | * list |
| 4034 | */ |
| 4035 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4037 | /* Start discovery */ |
| 4038 | lpfc_disc_start(vport); |
| 4039 | return; |
| 4040 | } |
| 4041 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | return; |
| 4043 | } |
| 4044 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4045 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4046 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4047 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4049 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4050 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4051 | "0003 rpi:%x DID:%x flg:%x %d map%x x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4052 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4053 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4054 | ndlp->nlp_usg_map, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4055 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4056 | if (vport->port_state < LPFC_VPORT_READY) { |
| 4057 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4058 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 4059 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 4060 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 4061 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4062 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4063 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4064 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4065 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 4066 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4067 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4068 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4069 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 4070 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4071 | |
| 4072 | /* Issue SCR just before NameServer GID_FT Query */ |
| 4073 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | } |
| 4075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4076 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4077 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4078 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4080 | /* |
| 4081 | * At this point in time we may need to wait for multiple |
| 4082 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 4083 | * |
| 4084 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4085 | * callback function. |
| 4086 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4087 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4089 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | |
| 4092 | return; |
| 4093 | } |
| 4094 | |
| 4095 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4096 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4098 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4099 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | struct lpfc_rport_data *rdata; |
| 4101 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4104 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4105 | return; |
| 4106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4108 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4109 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | rport_ids.port_id = ndlp->nlp_DID; |
| 4111 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4113 | /* |
| 4114 | * We leave our node pointer in rport->dd_data when we unregister a |
| 4115 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 4116 | * rport->dd_data points. So, if we're reusing a previously |
| 4117 | * registered port, drop the reference that we took the last time we |
| 4118 | * registered the port. |
| 4119 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4120 | rport = ndlp->rport; |
| 4121 | if (rport) { |
| 4122 | rdata = rport->dd_data; |
| 4123 | /* break the link before dropping the ref */ |
| 4124 | ndlp->rport = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4125 | if (rdata) { |
| 4126 | if (rdata->pnode == ndlp) |
| 4127 | lpfc_nlp_put(ndlp); |
| 4128 | rdata->pnode = NULL; |
| 4129 | } |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4130 | /* drop reference for earlier registeration */ |
| 4131 | put_device(&rport->dev); |
| 4132 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4133 | |
| 4134 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 4135 | "rport add: did:x%x flg:x%x type x%x", |
| 4136 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4137 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4138 | /* Don't add the remote port if unloading. */ |
| 4139 | if (vport->load_flag & FC_UNLOADING) |
| 4140 | return; |
| 4141 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4143 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4145 | "Warning: fc_remote_port_add failed\n"); |
| 4146 | return; |
| 4147 | } |
| 4148 | |
| 4149 | /* initialize static port data */ |
| 4150 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4151 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4153 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4154 | |
| 4155 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4156 | rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4157 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
Hannes Reinecke | a6a6d05 | 2019-04-10 16:16:19 +0200 | [diff] [blame] | 4158 | rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; |
| 4159 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) |
| 4160 | rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; |
| 4161 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4162 | rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; |
| 4163 | if (ndlp->nlp_type & NLP_NVME_DISCOVERY) |
| 4164 | rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4165 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4166 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4167 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4168 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4169 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4170 | "3183 rport register x%06x, rport x%px role x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4171 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 4172 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4173 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4174 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4175 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4176 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4177 | return; |
| 4178 | } |
| 4179 | |
| 4180 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4181 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4182 | { |
| 4183 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4184 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4185 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4186 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4187 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4188 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4189 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4190 | "rport delete: did:x%x flg:x%x type x%x", |
| 4191 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4192 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4193 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4194 | "3184 rport unregister x%06x, rport x%px\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4195 | ndlp->nlp_DID, rport); |
| 4196 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4197 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | |
| 4199 | return; |
| 4200 | } |
| 4201 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4202 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4203 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4204 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4206 | unsigned long iflags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4207 | |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4208 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4209 | switch (state) { |
| 4210 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4212 | break; |
| 4213 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4214 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4215 | break; |
| 4216 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4217 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4218 | break; |
| 4219 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4220 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4221 | break; |
| 4222 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4223 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4224 | break; |
| 4225 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4226 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4227 | break; |
| 4228 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4229 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4230 | break; |
| 4231 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4232 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4233 | vport->fc_npr_cnt = 0; |
| 4234 | else |
| 4235 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4236 | break; |
| 4237 | } |
James Smart | 894bb17 | 2019-08-14 16:56:52 -0700 | [diff] [blame] | 4238 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4239 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4240 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4241 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4243 | int old_state, int new_state) |
| 4244 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4246 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4247 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4248 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4249 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4250 | } |
| 4251 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4252 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4253 | if (new_state == NLP_STE_NPR_NODE) |
| 4254 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4256 | /* FCP and NVME Transport interface */ |
| 4257 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4258 | old_state == NLP_STE_UNMAPPED_NODE)) { |
| 4259 | if (ndlp->rport) { |
| 4260 | vport->phba->nport_event_cnt++; |
| 4261 | lpfc_unregister_remote_port(ndlp); |
| 4262 | } |
| 4263 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4264 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4265 | vport->phba->nport_event_cnt++; |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4266 | if (vport->phba->nvmet_support == 0) { |
| 4267 | /* Start devloss if target. */ |
| 4268 | if (ndlp->nlp_type & NLP_NVME_TARGET) |
| 4269 | lpfc_nvme_unregister_port(vport, ndlp); |
| 4270 | } else { |
James Smart | 6599e12 | 2017-06-01 21:07:00 -0700 | [diff] [blame] | 4271 | /* NVMET has no upcall. */ |
| 4272 | lpfc_nlp_put(ndlp); |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4273 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4274 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4275 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4277 | /* FCP and NVME Transport interfaces */ |
| 4278 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4279 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4280 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 01a8aed | 2018-09-10 10:30:41 -0700 | [diff] [blame] | 4281 | if (ndlp->nlp_fc4_type || |
James Smart | 92721c3 | 2017-06-01 21:06:59 -0700 | [diff] [blame] | 4282 | ndlp->nlp_DID == Fabric_DID || |
| 4283 | ndlp->nlp_DID == NameServer_DID || |
| 4284 | ndlp->nlp_DID == FDMI_DID) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4285 | vport->phba->nport_event_cnt++; |
| 4286 | /* |
| 4287 | * Tell the fc transport about the port, if we haven't |
| 4288 | * already. If we have, and it's a scsi entity, be |
| 4289 | */ |
| 4290 | lpfc_register_remote_port(vport, ndlp); |
| 4291 | } |
| 4292 | /* Notify the NVME transport of this new rport. */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 4293 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
| 4294 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4295 | if (vport->phba->nvmet_support == 0) { |
| 4296 | /* Register this rport with the transport. |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4297 | * Only NVME Target Rports are registered with |
| 4298 | * the transport. |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4299 | */ |
James Smart | 3b5bde69 | 2017-11-20 16:00:39 -0800 | [diff] [blame] | 4300 | if (ndlp->nlp_type & NLP_NVME_TARGET) { |
| 4301 | vport->phba->nport_event_cnt++; |
| 4302 | lpfc_nvme_register_port(vport, ndlp); |
| 4303 | } |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4304 | } else { |
| 4305 | /* Just take an NDLP ref count since the |
| 4306 | * target does not register rports. |
| 4307 | */ |
| 4308 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4309 | } |
| 4310 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4311 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4312 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4313 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4314 | (vport->stat_data_enabled)) { |
| 4315 | /* |
| 4316 | * A new target is discovered, if there is no buffer for |
| 4317 | * statistical data collection allocate buffer. |
| 4318 | */ |
| 4319 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4320 | sizeof(struct lpfc_scsicmd_bkt), |
| 4321 | GFP_KERNEL); |
| 4322 | |
| 4323 | if (!ndlp->lat_data) |
| 4324 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4325 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4326 | "allocate statistical data buffer DID " |
| 4327 | "0x%x\n", ndlp->nlp_DID); |
| 4328 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4329 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4330 | * If the node just added to Mapped list was an FCP target, |
| 4331 | * but the remote port registration failed or assigned a target |
| 4332 | * id outside the presentable range - move the node to the |
| 4333 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4334 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4335 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4336 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4337 | (!ndlp->rport || |
| 4338 | ndlp->rport->scsi_target_id == -1 || |
| 4339 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4341 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4342 | spin_unlock_irq(shost->host_lock); |
| 4343 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4345 | } |
| 4346 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4347 | static char * |
| 4348 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4349 | { |
| 4350 | static char *states[] = { |
| 4351 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4352 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4353 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4354 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4355 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4356 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4357 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4358 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4359 | [NLP_STE_NPR_NODE] = "NPR", |
| 4360 | }; |
| 4361 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4362 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4363 | strlcpy(buffer, states[state], size); |
| 4364 | else |
| 4365 | snprintf(buffer, size, "unknown (%d)", state); |
| 4366 | return buffer; |
| 4367 | } |
| 4368 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4369 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4371 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4372 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4373 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4374 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4375 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4376 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4377 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4378 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4379 | ndlp->nlp_DID, |
| 4380 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4381 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4382 | |
| 4383 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4384 | "node statechg did:x%x old:%d ste:%d", |
| 4385 | ndlp->nlp_DID, old_state, state); |
| 4386 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4387 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4388 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4389 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4390 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4391 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4392 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4393 | } |
| 4394 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4395 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4396 | spin_lock_irq(shost->host_lock); |
| 4397 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4398 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4399 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4401 | |
| 4402 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4403 | lpfc_nlp_counters(vport, state, 1); |
| 4404 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4408 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4409 | { |
| 4410 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4411 | |
| 4412 | if (list_empty(&ndlp->nlp_listp)) { |
| 4413 | spin_lock_irq(shost->host_lock); |
| 4414 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4415 | spin_unlock_irq(shost->host_lock); |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4420 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4421 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4422 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4423 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4424 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4425 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4426 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4427 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4428 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4429 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4430 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4431 | NLP_STE_UNUSED_NODE); |
| 4432 | } |
| 4433 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4434 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4435 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4436 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4437 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4438 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4439 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4440 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4441 | NLP_STE_UNUSED_NODE); |
| 4442 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4443 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4444 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4445 | * @vport: Pointer to Virtual Port object. |
| 4446 | * @ndlp: Pointer to FC node object. |
| 4447 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4448 | * |
| 4449 | * This function is always called when node object need to be initialized. |
| 4450 | * It initializes all the fields of the node object. Although the reference |
| 4451 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4452 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4453 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4454 | * the final release of ndlp is determined by its reference count. And, the |
| 4455 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4456 | **/ |
| 4457 | static inline void |
| 4458 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4459 | uint32_t did) |
| 4460 | { |
| 4461 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4462 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4463 | timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4464 | ndlp->nlp_DID = did; |
| 4465 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4466 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4467 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4468 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4469 | kref_init(&ndlp->kref); |
| 4470 | NLP_INT_NODE_ACT(ndlp); |
| 4471 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4472 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4473 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4474 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4475 | |
| 4476 | struct lpfc_nodelist * |
| 4477 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4478 | int state) |
| 4479 | { |
| 4480 | struct lpfc_hba *phba = vport->phba; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4481 | uint32_t did, flag; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4482 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4483 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4484 | int rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4485 | uint32_t defer_did = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4486 | |
| 4487 | if (!ndlp) |
| 4488 | return NULL; |
| 4489 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4490 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4491 | if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR) |
| 4492 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 4493 | else |
| 4494 | rpi = ndlp->nlp_rpi; |
| 4495 | |
| 4496 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 4497 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4498 | "0359 %s: ndlp:x%px " |
| 4499 | "usgmap:x%x refcnt:%d FAILED RPI " |
| 4500 | " ALLOC\n", |
| 4501 | __func__, |
| 4502 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4503 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4504 | return NULL; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4505 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4508 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4509 | /* The ndlp should not be in memory free mode */ |
| 4510 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4511 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4512 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4513 | "0277 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4514 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4515 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4516 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4517 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4518 | } |
| 4519 | /* The ndlp should not already be in active mode */ |
| 4520 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4521 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4522 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4523 | "0278 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4524 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4525 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4526 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4527 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4528 | } |
| 4529 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4530 | /* First preserve the orginal DID, xri_bitmap and some flags */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4531 | did = ndlp->nlp_DID; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4532 | flag = (ndlp->nlp_flag & NLP_UNREG_INP); |
| 4533 | if (flag & NLP_UNREG_INP) |
| 4534 | defer_did = ndlp->nlp_defer_did; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4535 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4536 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4537 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4538 | /* Zero ndlp except of ndlp linked list pointer */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4539 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4540 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4541 | |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4542 | /* Next reinitialize and restore saved objects */ |
| 4543 | lpfc_initialize_node(vport, ndlp, did); |
| 4544 | ndlp->nlp_flag |= flag; |
| 4545 | if (flag & NLP_UNREG_INP) |
| 4546 | ndlp->nlp_defer_did = defer_did; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4547 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4548 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4549 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4550 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4551 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4552 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4554 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4555 | "map:%x x%px\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4556 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4557 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4558 | ndlp->nlp_usg_map, ndlp); |
| 4559 | } |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4560 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4561 | |
| 4562 | if (state != NLP_STE_UNUSED_NODE) |
| 4563 | lpfc_nlp_set_state(vport, ndlp, state); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 4564 | else |
| 4565 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4566 | "0013 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4567 | "map:%x x%px STATE=UNUSED\n", |
| 4568 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4569 | ndlp->nlp_flag, |
| 4570 | kref_read(&ndlp->kref), |
| 4571 | ndlp->nlp_usg_map, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4572 | |
| 4573 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4574 | "node enable: did:x%x", |
| 4575 | ndlp->nlp_DID, 0, 0); |
| 4576 | return ndlp; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4577 | |
| 4578 | free_rpi: |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4579 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4580 | lpfc_sli4_free_rpi(vport->phba, rpi); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4581 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 4582 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4583 | return NULL; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4588 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4589 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4590 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4591 | * be used if we wish to issue the "last" lpfc_nlp_put() to remove |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4592 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4593 | * until ALL other outstanding threads have completed. We check |
| 4594 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4595 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4596 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4597 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4598 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4599 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4600 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4601 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4602 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4603 | |
| 4604 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4605 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | /* |
| 4609 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4610 | */ |
| 4611 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4612 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4615 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | uint32_t tmo; |
| 4617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4619 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4620 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4621 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4622 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4623 | * FC spec states we need 3 * ratov for CT requests |
| 4624 | */ |
| 4625 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4627 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4628 | |
| 4629 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4630 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4631 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4632 | tmo, vport->port_state, vport->fc_flag); |
| 4633 | } |
| 4634 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4635 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4636 | spin_lock_irq(shost->host_lock); |
| 4637 | vport->fc_flag |= FC_DISC_TMO; |
| 4638 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4639 | |
| 4640 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4642 | "0247 Start Discovery Timer state x%x " |
| 4643 | "Data: x%x x%lx x%x x%x\n", |
| 4644 | vport->port_state, tmo, |
| 4645 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4646 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | |
| 4648 | return; |
| 4649 | } |
| 4650 | |
| 4651 | /* |
| 4652 | * Cancel rescue timer for Discovery / RSCN handling |
| 4653 | */ |
| 4654 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4655 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4657 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4658 | unsigned long iflags; |
| 4659 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4660 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4661 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4662 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4665 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4666 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4667 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4668 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4669 | del_timer_sync(&vport->fc_disctmo); |
| 4670 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4671 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4672 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4676 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4677 | "0248 Cancel Discovery Timer state x%x " |
| 4678 | "Data: x%x x%x x%x\n", |
| 4679 | vport->port_state, vport->fc_flag, |
| 4680 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4681 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | /* |
| 4685 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4686 | * Return true if iocb matches the specified nport |
| 4687 | */ |
| 4688 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4690 | struct lpfc_sli_ring *pring, |
| 4691 | struct lpfc_iocbq *iocb, |
| 4692 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4695 | struct lpfc_vport *vport = ndlp->vport; |
| 4696 | |
| 4697 | if (iocb->vport != vport) |
| 4698 | return 0; |
| 4699 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4700 | if (pring->ringno == LPFC_ELS_RING) { |
| 4701 | switch (icmd->ulpCommand) { |
| 4702 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4703 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4704 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4705 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4707 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4708 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4709 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4710 | case CMD_XMIT_ELS_RSP64_CX: |
| 4711 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4712 | return 1; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4713 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4715 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4716 | /* Skip match check if waiting to relogin to FCP target */ |
| 4717 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4718 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4719 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | } |
| 4721 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4722 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4723 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4725 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | } |
| 4727 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4728 | static void |
| 4729 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4730 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4731 | struct list_head *dequeue_list) |
| 4732 | { |
| 4733 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4734 | |
| 4735 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4736 | /* Check to see if iocb matches the nport */ |
| 4737 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4738 | /* match, dequeue */ |
| 4739 | list_move_tail(&iocb->list, dequeue_list); |
| 4740 | } |
| 4741 | } |
| 4742 | |
| 4743 | static void |
| 4744 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4745 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4746 | { |
| 4747 | struct lpfc_sli *psli = &phba->sli; |
| 4748 | uint32_t i; |
| 4749 | |
| 4750 | spin_lock_irq(&phba->hbalock); |
| 4751 | for (i = 0; i < psli->num_rings; i++) |
| 4752 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4753 | dequeue_list); |
| 4754 | spin_unlock_irq(&phba->hbalock); |
| 4755 | } |
| 4756 | |
| 4757 | static void |
| 4758 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4759 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4760 | { |
| 4761 | struct lpfc_sli_ring *pring; |
| 4762 | struct lpfc_queue *qp = NULL; |
| 4763 | |
| 4764 | spin_lock_irq(&phba->hbalock); |
| 4765 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4766 | pring = qp->pring; |
| 4767 | if (!pring) |
| 4768 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4769 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4770 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4771 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4772 | } |
| 4773 | spin_unlock_irq(&phba->hbalock); |
| 4774 | } |
| 4775 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | /* |
| 4777 | * Free resources / clean up outstanding I/Os |
| 4778 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4779 | */ |
| 4780 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4781 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4783 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4785 | lpfc_fabric_abort_nport(ndlp); |
| 4786 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | /* |
| 4788 | * Everything that matches on txcmplq will be returned |
| 4789 | * by firmware with a no rpi error. |
| 4790 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4791 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4792 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4793 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4794 | else |
| 4795 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4797 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4798 | /* Cancel all the IOCBs from the completions list */ |
| 4799 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4800 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4801 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4802 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4803 | } |
| 4804 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4805 | /** |
| 4806 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4807 | * @phba: Pointer to HBA context object. |
| 4808 | * @pmb: Pointer to mailbox object. |
| 4809 | * |
| 4810 | * This function will issue an ELS LOGO command after completing |
| 4811 | * the UNREG_RPI. |
| 4812 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4813 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4814 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4815 | { |
| 4816 | struct lpfc_vport *vport = pmb->vport; |
| 4817 | struct lpfc_nodelist *ndlp; |
| 4818 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 4819 | ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4820 | if (!ndlp) |
| 4821 | return; |
| 4822 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4823 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4824 | |
| 4825 | /* Check to see if there are any deferred events to process */ |
| 4826 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 4827 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
| 4828 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4829 | "1434 UNREG cmpl deferred logo x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4830 | "on NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4831 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4832 | ndlp->nlp_defer_did, ndlp); |
| 4833 | |
| 4834 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 4835 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 4836 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4837 | } else { |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4838 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 4839 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 4840 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4841 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 4842 | } |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 4843 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4844 | } |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4845 | } |
| 4846 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | /* |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4848 | * Sets the mailbox completion handler to be used for the |
| 4849 | * unreg_rpi command. The handler varies based on the state of |
| 4850 | * the port and what will be happening to the rpi next. |
| 4851 | */ |
| 4852 | static void |
| 4853 | lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 4854 | struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox) |
| 4855 | { |
| 4856 | unsigned long iflags; |
| 4857 | |
| 4858 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4859 | mbox->ctx_ndlp = ndlp; |
| 4860 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4861 | |
| 4862 | } else if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4863 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4864 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >= |
| 4865 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 4866 | (kref_read(&ndlp->kref) > 0)) { |
| 4867 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
| 4868 | mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr; |
| 4869 | } else { |
| 4870 | if (vport->load_flag & FC_UNLOADING) { |
| 4871 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4872 | spin_lock_irqsave(&vport->phba->ndlp_lock, |
| 4873 | iflags); |
| 4874 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
| 4875 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, |
| 4876 | iflags); |
| 4877 | } |
| 4878 | lpfc_nlp_get(ndlp); |
| 4879 | } |
| 4880 | mbox->ctx_ndlp = ndlp; |
| 4881 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | * Free rpi associated with LPFC_NODELIST entry. |
| 4887 | * This routine is called from lpfc_freenode(), when we are removing |
| 4888 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4889 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4890 | * to the remote NPort. In addition, it is called after we receive |
| 4891 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4892 | * we are waiting to PLOGI back to the remote NPort. |
| 4893 | */ |
| 4894 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4895 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4896 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4897 | struct lpfc_hba *phba = vport->phba; |
| 4898 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4899 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4900 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4902 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4903 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4904 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4905 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4906 | LOG_NODE | LOG_DISCOVERY, |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4907 | "3366 RPI x%x needs to be " |
| 4908 | "unregistered nlp_flag x%x " |
| 4909 | "did x%x\n", |
| 4910 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4911 | ndlp->nlp_DID); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4912 | |
| 4913 | /* If there is already an UNREG in progress for this ndlp, |
| 4914 | * no need to queue up another one. |
| 4915 | */ |
| 4916 | if (ndlp->nlp_flag & NLP_UNREG_INP) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4917 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4918 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4919 | "1436 unreg_rpi SKIP UNREG x%x on " |
| 4920 | "NPort x%x deferred x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4921 | "Data: x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4922 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4923 | ndlp->nlp_defer_did, |
| 4924 | ndlp->nlp_flag, ndlp); |
| 4925 | goto out; |
| 4926 | } |
| 4927 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4928 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4929 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4930 | /* SLI4 ports require the physical rpi value. */ |
| 4931 | rpi = ndlp->nlp_rpi; |
| 4932 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4933 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4934 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4935 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4936 | mbox->vport = vport; |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 4937 | lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox); |
| 4938 | if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr) |
| 4939 | /* |
| 4940 | * accept PLOGIs after unreg_rpi_cmpl |
| 4941 | */ |
| 4942 | acc_plogi = 0; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4943 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != |
| 4944 | Fabric_DID_MASK) && |
| 4945 | (!(vport->fc_flag & FC_OFFLINE_MODE))) |
| 4946 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 4947 | |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 4948 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4949 | LOG_NODE | LOG_DISCOVERY, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4950 | "1433 unreg_rpi UNREG x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4951 | "NPort x%x deferred flg x%x " |
| 4952 | "Data:x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4953 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4954 | ndlp->nlp_flag, ndlp); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4955 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4956 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4957 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4958 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4959 | acc_plogi = 1; |
| 4960 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | lpfc_no_rpi(phba, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 4963 | out: |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4964 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4965 | ndlp->nlp_rpi = 0; |
| 4966 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4967 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4968 | if (acc_plogi) |
| 4969 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | return 1; |
| 4971 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4972 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | return 0; |
| 4974 | } |
| 4975 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4976 | /** |
| 4977 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4978 | * @phba: pointer to lpfc hba data structure. |
| 4979 | * |
| 4980 | * This routine is invoked to unregister all the currently registered RPIs |
| 4981 | * to the HBA. |
| 4982 | **/ |
| 4983 | void |
| 4984 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4985 | { |
| 4986 | struct lpfc_vport **vports; |
| 4987 | struct lpfc_nodelist *ndlp; |
| 4988 | struct Scsi_Host *shost; |
| 4989 | int i; |
| 4990 | |
| 4991 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4992 | if (!vports) { |
| 4993 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4994 | "2884 Vport array allocation failed \n"); |
| 4995 | return; |
| 4996 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4997 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4998 | shost = lpfc_shost_from_vport(vports[i]); |
| 4999 | spin_lock_irq(shost->host_lock); |
| 5000 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5001 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5002 | /* The mempool_alloc might sleep */ |
| 5003 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5004 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5005 | spin_lock_irq(shost->host_lock); |
| 5006 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5007 | } |
| 5008 | spin_unlock_irq(shost->host_lock); |
| 5009 | } |
| 5010 | lpfc_destroy_vport_work_array(phba, vports); |
| 5011 | } |
| 5012 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5013 | void |
| 5014 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 5015 | { |
| 5016 | struct lpfc_hba *phba = vport->phba; |
| 5017 | LPFC_MBOXQ_t *mbox; |
| 5018 | int rc; |
| 5019 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5020 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 5021 | lpfc_sli4_unreg_all_rpis(vport); |
| 5022 | return; |
| 5023 | } |
| 5024 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5025 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5026 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5027 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 5028 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5029 | mbox->vport = vport; |
| 5030 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5031 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5032 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5033 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5034 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5035 | |
| 5036 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 5037 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 5038 | "1836 Could not issue " |
| 5039 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | void |
| 5044 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 5045 | { |
| 5046 | struct lpfc_hba *phba = vport->phba; |
| 5047 | LPFC_MBOXQ_t *mbox; |
| 5048 | int rc; |
| 5049 | |
James Smart | c95a3b4 | 2019-03-12 16:30:07 -0700 | [diff] [blame] | 5050 | /* Unreg DID is an SLI3 operation. */ |
| 5051 | if (phba->sli_rev > LPFC_SLI_REV3) |
| 5052 | return; |
| 5053 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5054 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5055 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5056 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 5057 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5058 | mbox->vport = vport; |
| 5059 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5060 | mbox->ctx_ndlp = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5061 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5062 | if (rc != MBX_TIMEOUT) |
| 5063 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5064 | |
| 5065 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5066 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 5067 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5068 | "unreg_did (default rpis) status %d\n", |
| 5069 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | /* |
| 5074 | * Free resources associated with LPFC_NODELIST entry |
| 5075 | * so it can be freed. |
| 5076 | */ |
| 5077 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5078 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5080 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5081 | struct lpfc_hba *phba = vport->phba; |
| 5082 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | struct lpfc_dmabuf *mp; |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5084 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5085 | |
| 5086 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5087 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5088 | "0900 Cleanup node for NPort x%x " |
| 5089 | "Data: x%x x%x x%x\n", |
| 5090 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5091 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5092 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5093 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5094 | "0280 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5095 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5096 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5097 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5098 | lpfc_dequeue_node(vport, ndlp); |
| 5099 | } else { |
| 5100 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5101 | "0281 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5102 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5103 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5104 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5105 | lpfc_disable_node(vport, ndlp); |
| 5106 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5107 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5108 | |
| 5109 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 5110 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 5112 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5113 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5114 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5115 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5116 | mb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5118 | } |
| 5119 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 5120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5121 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5122 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 5123 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 5124 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5125 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5126 | (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp)) |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5127 | continue; |
| 5128 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5129 | mb->ctx_ndlp = NULL; |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 5130 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5131 | } |
| 5132 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5133 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5134 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5135 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5136 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
| 5137 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5138 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5139 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5140 | kfree(mp); |
| 5141 | } |
| 5142 | list_del(&mb->list); |
| 5143 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5144 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 5145 | * the ndlp reference count as we are in the process |
| 5146 | * of lpfc_nlp_release. |
| 5147 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | } |
| 5149 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5150 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5151 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5152 | lpfc_els_abort(phba, ndlp); |
| 5153 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5154 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 5155 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5156 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5157 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5158 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5159 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 5160 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5161 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 5162 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 5163 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 4f1a2fe | 2019-08-14 16:56:32 -0700 | [diff] [blame] | 5164 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5165 | ndlp->nlp_flag |= NLP_RELEASE_RPI; |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 5166 | if (!lpfc_unreg_rpi(vport, ndlp)) { |
| 5167 | /* Clean up unregistered and non freed rpis */ |
| 5168 | if ((ndlp->nlp_flag & NLP_RELEASE_RPI) && |
| 5169 | !(ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)) { |
| 5170 | lpfc_sli4_free_rpi(vport->phba, |
| 5171 | ndlp->nlp_rpi); |
| 5172 | spin_lock_irqsave(&vport->phba->ndlp_lock, |
| 5173 | iflags); |
| 5174 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 5175 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 5176 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, |
| 5177 | iflags); |
| 5178 | } |
| 5179 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5180 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | /* |
| 5184 | * Check to see if we can free the nlp back to the freelist. |
| 5185 | * If we are in the middle of using the nlp in the discovery state |
| 5186 | * machine, defer the free till we reach the end of the state machine. |
| 5187 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5188 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5191 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5192 | struct lpfc_rport_data *rdata; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5193 | struct fc_rport *rport; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5194 | LPFC_MBOXQ_t *mbox; |
| 5195 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5196 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5197 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 5198 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5199 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
Dick Kennedy | e8bcf0a | 2017-09-29 17:34:32 -0700 | [diff] [blame] | 5200 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
| 5201 | phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5202 | /* For this case we need to cleanup the default rpi |
| 5203 | * allocated by the firmware. |
| 5204 | */ |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5205 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5206 | LOG_NODE | LOG_DISCOVERY, |
| 5207 | "0005 Cleanup Default rpi:x%x DID:x%x flg:x%x " |
| 5208 | "ref %d map:x%x ndlp x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5209 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5210 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5211 | ndlp->nlp_usg_map, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5212 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 5213 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 5214 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5215 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5216 | if (rc) { |
| 5217 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5218 | } |
| 5219 | else { |
| 5220 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 5221 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 5222 | mbox->vport = vport; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5223 | mbox->ctx_ndlp = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5224 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5225 | if (rc == MBX_NOT_FINISHED) { |
| 5226 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5232 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | /* |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5234 | * ndlp->rport must be set to NULL before it reaches here |
| 5235 | * i.e. break rport/node link before doing lpfc_nlp_put for |
| 5236 | * registered rport and then drop the reference of rport. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5237 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5238 | if (ndlp->rport) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5239 | /* |
| 5240 | * extra lpfc_nlp_put dropped the reference of ndlp |
| 5241 | * for registered rport so need to cleanup rport |
| 5242 | */ |
| 5243 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5244 | "0940 removed node x%px DID x%x " |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 5245 | "rpi %d rport not null x%px\n", |
| 5246 | ndlp, ndlp->nlp_DID, ndlp->nlp_rpi, |
| 5247 | ndlp->rport); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5248 | rport = ndlp->rport; |
| 5249 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5250 | rdata->pnode = NULL; |
| 5251 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5252 | put_device(&rport->dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5253 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5257 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5258 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5259 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5260 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | |
| 5262 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5263 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5265 | /* First check for Direct match */ |
| 5266 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5267 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | |
| 5269 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5270 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5272 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | matchdid.un.word = did; |
| 5276 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5277 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5278 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5279 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5280 | /* This code is supposed to match the ID |
| 5281 | * for a private loop device that is |
| 5282 | * connect to fl_port. But we need to |
| 5283 | * check that the port did not just go |
| 5284 | * from pt2pt to fabric or we could end |
| 5285 | * up matching ndlp->nlp_DID 000001 to |
| 5286 | * fabric DID 0x20101 |
| 5287 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | if ((ndlpdid.un.b.domain == 0) && |
| 5289 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5290 | if (ndlpdid.un.b.id && |
| 5291 | vport->phba->fc_topology == |
| 5292 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5293 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5295 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | matchdid.un.word = ndlp->nlp_DID; |
| 5299 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5300 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5301 | if ((matchdid.un.b.domain == 0) && |
| 5302 | (matchdid.un.b.area == 0)) { |
| 5303 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5304 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5305 | } |
| 5306 | } |
| 5307 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5308 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5309 | } |
| 5310 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5311 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5312 | static struct lpfc_nodelist * |
| 5313 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5314 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5315 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5316 | uint32_t data1; |
| 5317 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5318 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5319 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5320 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5321 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5322 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5323 | ((uint32_t)ndlp->nlp_usg_map & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5324 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5325 | "0929 FIND node DID " |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5326 | "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] | 5327 | ndlp, ndlp->nlp_DID, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5328 | ndlp->nlp_flag, data1, ndlp->nlp_rpi, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5329 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5330 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5331 | } |
| 5332 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5334 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5335 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5336 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5337 | return NULL; |
| 5338 | } |
| 5339 | |
| 5340 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5341 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5343 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5344 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5345 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5347 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5348 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5349 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5350 | return ndlp; |
| 5351 | } |
| 5352 | |
| 5353 | struct lpfc_nodelist * |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5354 | lpfc_findnode_mapped(struct lpfc_vport *vport) |
| 5355 | { |
| 5356 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5357 | struct lpfc_nodelist *ndlp; |
| 5358 | uint32_t data1; |
| 5359 | unsigned long iflags; |
| 5360 | |
| 5361 | spin_lock_irqsave(shost->host_lock, iflags); |
| 5362 | |
| 5363 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5364 | if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || |
| 5365 | ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 5366 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
| 5367 | ((uint32_t)ndlp->nlp_xri << 16) | |
| 5368 | ((uint32_t)ndlp->nlp_type << 8) | |
| 5369 | ((uint32_t)ndlp->nlp_rpi & 0xff)); |
| 5370 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5371 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5372 | "2025 FIND node DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5373 | "Data: x%px x%x x%x x%x x%px\n", |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 5374 | ndlp, ndlp->nlp_DID, |
| 5375 | ndlp->nlp_flag, data1, |
| 5376 | ndlp->active_rrqs_xri_bitmap); |
| 5377 | return ndlp; |
| 5378 | } |
| 5379 | } |
| 5380 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 5381 | |
| 5382 | /* FIND node did <did> NOT FOUND */ |
| 5383 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5384 | "2026 FIND mapped did NOT FOUND.\n"); |
| 5385 | return NULL; |
| 5386 | } |
| 5387 | |
| 5388 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5389 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5390 | { |
| 5391 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5392 | struct lpfc_nodelist *ndlp; |
| 5393 | |
| 5394 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5395 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5396 | if (vport->phba->nvmet_support) |
| 5397 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5398 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5399 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5400 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5401 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5402 | if (!ndlp) |
| 5403 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5404 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5405 | |
| 5406 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5407 | "6453 Setup New Node 2B_DISC x%x " |
| 5408 | "Data:x%x x%x x%x\n", |
| 5409 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5410 | ndlp->nlp_state, vport->fc_flag); |
| 5411 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5412 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5414 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5415 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5416 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5417 | if (vport->phba->nvmet_support) |
| 5418 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5419 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5420 | if (!ndlp) { |
| 5421 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, |
| 5422 | "0014 Could not enable ndlp\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5423 | return NULL; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 5424 | } |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5425 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5426 | "6454 Setup Enabled Node 2B_DISC x%x " |
| 5427 | "Data:x%x x%x x%x\n", |
| 5428 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5429 | ndlp->nlp_state, vport->fc_flag); |
| 5430 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5431 | spin_lock_irq(shost->host_lock); |
| 5432 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5433 | spin_unlock_irq(shost->host_lock); |
| 5434 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5436 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5437 | /* The NVME Target does not want to actively manage an rport. |
| 5438 | * The goal is to allow the target to reset its state and clear |
| 5439 | * pending IO in preparation for the initiator to recover. |
| 5440 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5441 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5442 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5443 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5444 | |
| 5445 | /* Since this node is marked for discovery, |
| 5446 | * delay timeout is not needed. |
| 5447 | */ |
| 5448 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5449 | |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5450 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5451 | "6455 Setup RSCN Node 2B_DISC x%x " |
| 5452 | "Data:x%x x%x x%x\n", |
| 5453 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5454 | ndlp->nlp_state, vport->fc_flag); |
| 5455 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5456 | /* NVME Target mode waits until rport is known to be |
| 5457 | * impacted by the RSCN before it transitions. No |
| 5458 | * active management - just go to NPR provided the |
| 5459 | * node had a valid login. |
| 5460 | */ |
| 5461 | if (vport->phba->nvmet_support) |
| 5462 | return ndlp; |
| 5463 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5464 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5465 | * we don't need to try to discover it again. |
| 5466 | */ |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5467 | if (ndlp->nlp_flag & NLP_RCV_PLOGI && |
| 5468 | !(ndlp->nlp_type & |
| 5469 | (NLP_FCP_TARGET | NLP_NVME_TARGET))) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5470 | return NULL; |
| 5471 | |
James Smart | 3f97aed | 2019-09-21 20:58:55 -0700 | [diff] [blame] | 5472 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 5473 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5474 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5475 | spin_lock_irq(shost->host_lock); |
| 5476 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5477 | spin_unlock_irq(shost->host_lock); |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5478 | } else { |
| 5479 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5480 | "6456 Skip Setup RSCN Node x%x " |
| 5481 | "Data:x%x x%x x%x\n", |
| 5482 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5483 | ndlp->nlp_state, vport->fc_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | ndlp = NULL; |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5485 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5486 | } else { |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5487 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5488 | "6457 Setup Active Node 2B_DISC x%x " |
| 5489 | "Data:x%x x%x x%x\n", |
| 5490 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5491 | ndlp->nlp_state, vport->fc_flag); |
| 5492 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5493 | /* If the initiator received a PLOGI from this NPort or if the |
| 5494 | * initiator is already in the process of discovery on it, |
| 5495 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5496 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5497 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5498 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5499 | (!vport->phba->nvmet_support && |
| 5500 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5502 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5503 | if (vport->phba->nvmet_support) |
| 5504 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5505 | |
| 5506 | /* Moving to NPR state clears unsolicited flags and |
| 5507 | * allows for rediscovery |
| 5508 | */ |
| 5509 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5511 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5512 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | } |
| 5515 | return ndlp; |
| 5516 | } |
| 5517 | |
| 5518 | /* Build a list of nodes to discover based on the loopmap */ |
| 5519 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5520 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5521 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5522 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | int j; |
| 5524 | uint32_t alpa, index; |
| 5525 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5526 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5528 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5529 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5530 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5531 | |
| 5532 | /* Check for loop map present or not */ |
| 5533 | if (phba->alpa_map[0]) { |
| 5534 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5535 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5536 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | } |
| 5540 | } else { |
| 5541 | /* No alpamap, so try all alpa's */ |
| 5542 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5543 | /* If cfg_scan_down is set, start from highest |
| 5544 | * ALPA (0xef) to lowest (0x1). |
| 5545 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5546 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | index = j; |
| 5548 | else |
| 5549 | index = FC_MAXLOOP - j - 1; |
| 5550 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5551 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5553 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | } |
| 5555 | } |
| 5556 | return; |
| 5557 | } |
| 5558 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5559 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5560 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5561 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5562 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5563 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5565 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5566 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5567 | int rc; |
| 5568 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5569 | /* |
| 5570 | * if it's not a physical port or if we already send |
| 5571 | * clear_la then don't send it. |
| 5572 | */ |
| 5573 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5574 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5575 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5576 | return; |
| 5577 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | /* Link up discovery */ |
| 5579 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5580 | phba->link_state = LPFC_CLEAR_LA; |
| 5581 | lpfc_clear_la(phba, mbox); |
| 5582 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5583 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5584 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5585 | if (rc == MBX_NOT_FINISHED) { |
| 5586 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5587 | lpfc_disc_flush_list(vport); |
| 5588 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5589 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5590 | phba->link_state = LPFC_HBA_ERROR; |
| 5591 | } |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5596 | void |
| 5597 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5598 | { |
| 5599 | LPFC_MBOXQ_t *regvpimbox; |
| 5600 | |
| 5601 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5602 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5603 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5604 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5605 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5606 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5607 | == MBX_NOT_FINISHED) { |
| 5608 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5609 | } |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5614 | void |
| 5615 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5616 | { |
| 5617 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5618 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5619 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5620 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5621 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5622 | if (!lpfc_is_link_up(phba)) { |
| 5623 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5624 | "3315 Link is not up %x\n", |
| 5625 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5626 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5627 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5628 | |
| 5629 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | clear_la_pending = 1; |
| 5631 | else |
| 5632 | clear_la_pending = 0; |
| 5633 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5634 | if (vport->port_state < LPFC_VPORT_READY) |
| 5635 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5637 | lpfc_set_disctmo(vport); |
| 5638 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5639 | vport->fc_prevDID = vport->fc_myDID; |
| 5640 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5641 | |
| 5642 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5643 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5644 | "0202 Start Discovery port state x%x " |
| 5645 | "flg x%x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5646 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
James Smart | b4b3417 | 2019-10-18 14:18:31 -0700 | [diff] [blame] | 5647 | vport->fc_adisc_cnt, vport->fc_npr_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5648 | |
| 5649 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5650 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5651 | |
| 5652 | if (num_sent) |
| 5653 | return; |
| 5654 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5655 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5656 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5657 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5658 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5659 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5660 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5661 | lpfc_issue_reg_vpi(phba, vport); |
| 5662 | return; |
| 5663 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5664 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5665 | /* |
| 5666 | * For SLI2, we need to set port_state to READY and continue |
| 5667 | * discovery. |
| 5668 | */ |
| 5669 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5670 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5671 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5672 | |
| 5673 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | vport->num_disc_nodes = 0; |
| 5675 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5676 | if (vport->fc_npr_cnt) |
| 5677 | lpfc_els_disc_plogi(vport); |
| 5678 | |
| 5679 | if (!vport->num_disc_nodes) { |
| 5680 | spin_lock_irq(shost->host_lock); |
| 5681 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5682 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5683 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | } |
| 5685 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5686 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | } else { |
| 5688 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5689 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | |
| 5691 | if (num_sent) |
| 5692 | return; |
| 5693 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5694 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | /* Check to see if more RSCNs came in while we |
| 5696 | * were processing this one. |
| 5697 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5698 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5699 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5700 | spin_lock_irq(shost->host_lock); |
| 5701 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5702 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5703 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5704 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5705 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5706 | } |
| 5707 | } |
| 5708 | return; |
| 5709 | } |
| 5710 | |
| 5711 | /* |
| 5712 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5713 | * ring the match the sppecified nodelist. |
| 5714 | */ |
| 5715 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5716 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5717 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5718 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5719 | IOCB_t *icmd; |
| 5720 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5721 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5722 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5723 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 5724 | if (unlikely(!pring)) |
| 5725 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5726 | |
| 5727 | /* Error matching iocb on txq or txcmplq |
| 5728 | * First check the txq. |
| 5729 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5730 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5731 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5732 | if (iocb->context1 != ndlp) { |
| 5733 | continue; |
| 5734 | } |
| 5735 | icmd = &iocb->iocb; |
| 5736 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5737 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5738 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5739 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | /* Next check the txcmplq */ |
| 5744 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5745 | if (iocb->context1 != ndlp) { |
| 5746 | continue; |
| 5747 | } |
| 5748 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5750 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5751 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | } |
| 5753 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5754 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5755 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5756 | /* Cancel all the IOCBs from the completions list */ |
| 5757 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5758 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5759 | } |
| 5760 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5761 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5762 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | { |
| 5764 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5765 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5766 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5767 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5768 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5769 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5770 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5771 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5772 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5773 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5774 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5775 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5776 | } |
| 5777 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5778 | } |
| 5779 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5780 | void |
| 5781 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5782 | { |
| 5783 | lpfc_els_flush_rscn(vport); |
| 5784 | lpfc_els_flush_cmd(vport); |
| 5785 | lpfc_disc_flush_list(vport); |
| 5786 | } |
| 5787 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5788 | /*****************************************************************************/ |
| 5789 | /* |
| 5790 | * NAME: lpfc_disc_timeout |
| 5791 | * |
| 5792 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5793 | * |
| 5794 | * EXECUTION ENVIRONMENT: interrupt only |
| 5795 | * |
| 5796 | * CALLED FROM: |
| 5797 | * Timer function |
| 5798 | * |
| 5799 | * RETURNS: |
| 5800 | * none |
| 5801 | */ |
| 5802 | /*****************************************************************************/ |
| 5803 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5804 | lpfc_disc_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5805 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5806 | struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5807 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5808 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5809 | unsigned long flags = 0; |
| 5810 | |
| 5811 | if (unlikely(!phba)) |
| 5812 | return; |
| 5813 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5814 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5815 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5816 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5817 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5818 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5819 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5820 | if (!tmo_posted) |
| 5821 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5822 | return; |
| 5823 | } |
| 5824 | |
| 5825 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5826 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5828 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5829 | struct lpfc_hba *phba = vport->phba; |
| 5830 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5831 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5832 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5833 | int rc, clrlaerr = 0; |
| 5834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5835 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5836 | return; |
| 5837 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5838 | spin_lock_irq(shost->host_lock); |
| 5839 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5840 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5841 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5842 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5843 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5844 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5845 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5846 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5847 | |
| 5848 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5849 | /* |
| 5850 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5851 | * waiting for FAN timeout |
| 5852 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5853 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5854 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5855 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5856 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5857 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5858 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5859 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5860 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5861 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5862 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5863 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5864 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5865 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5866 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5867 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5868 | /* Fail outstanding IO now since device |
| 5869 | * is marked for PLOGI. |
| 5870 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5871 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5872 | } |
| 5873 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5874 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5875 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5876 | lpfc_initial_flogi(vport); |
| 5877 | else |
| 5878 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5879 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5880 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5881 | break; |
| 5882 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5883 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5884 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5885 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5887 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5888 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5889 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5890 | |
| 5891 | /* Assume no Fabric and go on with discovery. |
| 5892 | * Check for outstanding ELS FLOGI to abort. |
| 5893 | */ |
| 5894 | |
| 5895 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5896 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5897 | |
| 5898 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5899 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5900 | break; |
| 5901 | |
| 5902 | case LPFC_FABRIC_CFG_LINK: |
| 5903 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5904 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5905 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5906 | "0223 Timeout while waiting for " |
| 5907 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5908 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5909 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5910 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5911 | lpfc_els_abort(phba, ndlp); |
| 5912 | |
| 5913 | /* ReStart discovery */ |
| 5914 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5915 | |
| 5916 | case LPFC_NS_QRY: |
| 5917 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5918 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5919 | "0224 NameServer Query timeout " |
| 5920 | "Data: x%x x%x\n", |
| 5921 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5922 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5923 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5924 | /* Try it one more time */ |
| 5925 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5926 | vport->gidft_inp = 0; |
| 5927 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5928 | if (rc == 0) |
| 5929 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5932 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5933 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5934 | /* |
| 5935 | * Discovery is over. |
| 5936 | * set port_state to PORT_READY if SLI2. |
| 5937 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5938 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5939 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5940 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5941 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5942 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5943 | lpfc_issue_clear_la(phba, vport); |
| 5944 | vport->port_state = LPFC_VPORT_READY; |
| 5945 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5949 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5950 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5951 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5952 | "0206 Device Discovery " |
| 5953 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5954 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5955 | break; |
| 5956 | } |
| 5957 | |
| 5958 | lpfc_linkdown(phba); |
| 5959 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5960 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5961 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5962 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5963 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5964 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5965 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5966 | if (rc == MBX_NOT_FINISHED) |
| 5967 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5968 | |
| 5969 | break; |
| 5970 | |
| 5971 | case LPFC_DISC_AUTH: |
| 5972 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5973 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5974 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5975 | lpfc_disc_flush_list(vport); |
| 5976 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5977 | /* |
| 5978 | * set port_state to PORT_READY if SLI2. |
| 5979 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5980 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5981 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5982 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5983 | lpfc_issue_reg_vpi(phba, vport); |
| 5984 | else { /* NPIV Not enabled */ |
| 5985 | lpfc_issue_clear_la(phba, vport); |
| 5986 | vport->port_state = LPFC_VPORT_READY; |
| 5987 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5988 | } |
| 5989 | break; |
| 5990 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5991 | case LPFC_VPORT_READY: |
| 5992 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5993 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5994 | "0231 RSCN timeout Data: x%x " |
| 5995 | "x%x\n", |
| 5996 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5997 | |
| 5998 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5999 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6001 | lpfc_els_flush_rscn(vport); |
| 6002 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6003 | } |
| 6004 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6005 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6006 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6007 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6008 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6009 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6010 | break; |
| 6011 | } |
| 6012 | |
| 6013 | switch (phba->link_state) { |
| 6014 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6015 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6016 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 6017 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6018 | clrlaerr = 1; |
| 6019 | break; |
| 6020 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6021 | case LPFC_LINK_UP: |
| 6022 | lpfc_issue_clear_la(phba, vport); |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 6023 | /* fall through */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6024 | case LPFC_LINK_UNKNOWN: |
| 6025 | case LPFC_WARM_START: |
| 6026 | case LPFC_INIT_START: |
| 6027 | case LPFC_INIT_MBX_CMDS: |
| 6028 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6029 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 6031 | "0230 Unexpected timeout, hba link " |
| 6032 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6033 | clrlaerr = 1; |
| 6034 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6035 | |
| 6036 | case LPFC_HBA_READY: |
| 6037 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6041 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6042 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 6043 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 6044 | ~LPFC_STOP_IOCB_EVENT; |
| 6045 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 6046 | ~LPFC_STOP_IOCB_EVENT; |
| 6047 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6048 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6049 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6050 | return; |
| 6051 | } |
| 6052 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6053 | /* |
| 6054 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 6055 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 6056 | * as the completion routine when the command is |
| 6057 | * handed off to the SLI layer. |
| 6058 | */ |
| 6059 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6060 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6061 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6062 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6063 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 6064 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6065 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6066 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 6067 | pmb->ctx_buf = NULL; |
| 6068 | pmb->ctx_ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6069 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6070 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6071 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 6072 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6073 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6074 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6075 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6076 | "0004 rpi:%x DID:%x flg:%x %d map:%x x%px\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6077 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6078 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6079 | ndlp->nlp_usg_map, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6080 | /* |
| 6081 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6082 | * 0xfffffa (FDMI well known port). |
| 6083 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 6084 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6085 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6086 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 6087 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 6088 | else |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6089 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| 6090 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6091 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6092 | /* decrement the node reference count held for this callback |
| 6093 | * function. |
| 6094 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6095 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6096 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6097 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6098 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6099 | |
| 6100 | return; |
| 6101 | } |
| 6102 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6103 | static int |
| 6104 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 6105 | { |
| 6106 | uint16_t *rpi = param; |
| 6107 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 6108 | /* check for active node */ |
| 6109 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 6110 | return 0; |
| 6111 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6112 | return ndlp->nlp_rpi == *rpi; |
| 6113 | } |
| 6114 | |
| 6115 | static int |
| 6116 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 6117 | { |
| 6118 | return memcmp(&ndlp->nlp_portname, param, |
| 6119 | sizeof(ndlp->nlp_portname)) == 0; |
| 6120 | } |
| 6121 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6122 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6123 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6124 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6125 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6126 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6127 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6128 | if (filter(ndlp, param)) { |
| 6129 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6130 | "3185 FIND node filter %ps DID " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6131 | "ndlp x%px did x%x flg x%x st x%x " |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6132 | "xri x%x type x%x rpi x%x\n", |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6133 | filter, ndlp, ndlp->nlp_DID, |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame] | 6134 | ndlp->nlp_flag, ndlp->nlp_state, |
| 6135 | ndlp->nlp_xri, ndlp->nlp_type, |
| 6136 | ndlp->nlp_rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6137 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6138 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6139 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 6140 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 6141 | "3186 FIND node filter %ps NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 6142 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6143 | } |
| 6144 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6145 | /* |
| 6146 | * 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] | 6147 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6148 | */ |
| 6149 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6150 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6151 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6152 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6153 | } |
| 6154 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6155 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6156 | * 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] | 6157 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6158 | */ |
| 6159 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6160 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6161 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6162 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6163 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6165 | spin_lock_irq(shost->host_lock); |
| 6166 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 6167 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6168 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 6169 | } |
| 6170 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6171 | /* |
| 6172 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 6173 | * is found, the routine returns the node element list pointer else |
| 6174 | * return NULL. |
| 6175 | */ |
| 6176 | struct lpfc_nodelist * |
| 6177 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 6178 | { |
| 6179 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6180 | struct lpfc_nodelist *ndlp; |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6181 | unsigned long flags; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6182 | |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6183 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6184 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
Fuqian Huang | 78d4b13 | 2019-08-12 16:31:34 +0800 | [diff] [blame] | 6185 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6186 | return ndlp; |
| 6187 | } |
| 6188 | |
| 6189 | /** |
| 6190 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 6191 | * @phba: pointer to lpfc hba data structure. |
| 6192 | * @vpi: the physical host virtual N_Port identifier. |
| 6193 | * |
| 6194 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6195 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6196 | * of the vport with the matching @vpi. |
| 6197 | * |
| 6198 | * Return code |
| 6199 | * NULL - No vport with the matching @vpi found |
| 6200 | * Otherwise - Address to the vport with the matching @vpi. |
| 6201 | **/ |
| 6202 | struct lpfc_vport * |
| 6203 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6204 | { |
| 6205 | struct lpfc_vport *vport; |
| 6206 | unsigned long flags; |
| 6207 | int i = 0; |
| 6208 | |
| 6209 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 6210 | if (vpi > 0) { |
| 6211 | /* |
| 6212 | * Translate the physical vpi to the logical vpi. The |
| 6213 | * vport stores the logical vpi. |
| 6214 | */ |
| 6215 | for (i = 0; i < phba->max_vpi; i++) { |
| 6216 | if (vpi == phba->vpi_ids[i]) |
| 6217 | break; |
| 6218 | } |
| 6219 | |
| 6220 | if (i >= phba->max_vpi) { |
| 6221 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 6222 | "2936 Could not find Vport mapped " |
| 6223 | "to vpi %d\n", vpi); |
| 6224 | return NULL; |
| 6225 | } |
| 6226 | } |
| 6227 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6228 | spin_lock_irqsave(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6229 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 6230 | if (vport->vpi == i) { |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6231 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6232 | return vport; |
| 6233 | } |
| 6234 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6235 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 6236 | return NULL; |
| 6237 | } |
| 6238 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6239 | struct lpfc_nodelist * |
| 6240 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6241 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6242 | struct lpfc_nodelist *ndlp; |
| 6243 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 6244 | |
| 6245 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 6246 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 6247 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 6248 | return NULL; |
| 6249 | } |
| 6250 | |
| 6251 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 6252 | if (!ndlp) { |
| 6253 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 6254 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 6255 | return NULL; |
| 6256 | } |
| 6257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6258 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 6259 | |
| 6260 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6261 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6262 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6263 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6264 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY, |
| 6265 | "0007 Init New ndlp x%px, rpi:x%x DID:%x " |
| 6266 | "flg:x%x refcnt:%d map:x%x\n", |
| 6267 | ndlp, ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6268 | ndlp->nlp_flag, kref_read(&ndlp->kref), |
| 6269 | ndlp->nlp_usg_map); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6270 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6271 | ndlp->active_rrqs_xri_bitmap = |
| 6272 | mempool_alloc(vport->phba->active_rrq_pool, |
| 6273 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 6274 | if (ndlp->active_rrqs_xri_bitmap) |
| 6275 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 6276 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6277 | } |
| 6278 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 6279 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6280 | |
| 6281 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 6282 | "node init: did:x%x", |
| 6283 | ndlp->nlp_DID, 0, 0); |
| 6284 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6285 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6286 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6287 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6288 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 6289 | * and mempool_free's the nodelist. |
| 6290 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 6291 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6292 | lpfc_nlp_release(struct kref *kref) |
| 6293 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6294 | struct lpfc_hba *phba; |
| 6295 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6296 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 6297 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6298 | |
| 6299 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6300 | "node release: did:x%x flg:x%x type:x%x", |
| 6301 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 6302 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6303 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6304 | "0279 %s: ndlp:x%px did %x " |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6305 | "usgmap:x%x refcnt:%d rpi:%x\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6306 | __func__, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6307 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6308 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6309 | |
| 6310 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6311 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6312 | |
| 6313 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6314 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6315 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6316 | NLP_CLR_NODE_ACT(ndlp); |
| 6317 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6318 | |
| 6319 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6320 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 6321 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6322 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6323 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6324 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6325 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6326 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6327 | } |
| 6328 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6329 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6330 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6331 | * is using it. |
| 6332 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6333 | struct lpfc_nodelist * |
| 6334 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6335 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6336 | struct lpfc_hba *phba; |
| 6337 | unsigned long flags; |
| 6338 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6339 | if (ndlp) { |
| 6340 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6341 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6342 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6343 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6344 | /* The check of ndlp usage to prevent incrementing the |
| 6345 | * ndlp reference count that is in the process of being |
| 6346 | * released. |
| 6347 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6348 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6349 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6350 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 6351 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6352 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6353 | "0276 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6354 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6355 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6356 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6357 | return NULL; |
| 6358 | } else |
| 6359 | kref_get(&ndlp->kref); |
| 6360 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6361 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6362 | return ndlp; |
| 6363 | } |
| 6364 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6365 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6366 | * count goes to 0, this indicates the the associated nodelist should be |
| 6367 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 6368 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 6369 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6370 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6371 | int |
| 6372 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6373 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6374 | struct lpfc_hba *phba; |
| 6375 | unsigned long flags; |
| 6376 | |
| 6377 | if (!ndlp) |
| 6378 | return 1; |
| 6379 | |
| 6380 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6381 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6382 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 6383 | kref_read(&ndlp->kref)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6384 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6385 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6386 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 6387 | * possible race condition that kref_put got invoked again |
| 6388 | * after previous one has done ndlp memory free. |
| 6389 | */ |
| 6390 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 6391 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6392 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6393 | "0274 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6394 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6395 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6396 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6397 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6398 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6399 | /* Check the ndlp inactivate log flag to avoid the possible |
| 6400 | * race condition that kref_put got invoked again after ndlp |
| 6401 | * is already in inactivating state. |
| 6402 | */ |
| 6403 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 6404 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6405 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6406 | "0275 %s: ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6407 | "usgmap:x%x refcnt:%d\n", |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6408 | __func__, (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6409 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6410 | return 1; |
| 6411 | } |
| 6412 | /* For last put, mark the ndlp usage flags to make sure no |
| 6413 | * other kref_get and kref_put on the same ndlp shall get |
| 6414 | * in between the process when the final kref_put has been |
| 6415 | * invoked on this ndlp. |
| 6416 | */ |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6417 | if (kref_read(&ndlp->kref) == 1) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6418 | /* Indicate ndlp is put to inactive state. */ |
| 6419 | NLP_SET_IACT_REQ(ndlp); |
| 6420 | /* Acknowledge ndlp memory free has been seen. */ |
| 6421 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 6422 | NLP_SET_FREE_ACK(ndlp); |
| 6423 | } |
| 6424 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6425 | /* Note, the kref_put returns 1 when decrementing a reference |
| 6426 | * count that was 1, it invokes the release callback function, |
| 6427 | * but it still left the reference count as 1 (not actually |
| 6428 | * performs the last decrementation). Otherwise, it actually |
| 6429 | * decrements the reference count and returns 0. |
| 6430 | */ |
| 6431 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6432 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6433 | |
| 6434 | /* 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] | 6435 | * by any other discovery thread. This routine returns 1 if the |
| 6436 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6437 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6438 | */ |
| 6439 | int |
| 6440 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6441 | { |
| 6442 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6443 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6444 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6445 | kref_read(&ndlp->kref)); |
| 6446 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6447 | if (lpfc_nlp_put(ndlp)) |
| 6448 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6449 | return 0; |
| 6450 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6451 | |
| 6452 | /** |
| 6453 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6454 | * @phba: Pointer to hba context object. |
| 6455 | * |
| 6456 | * This function iterate through all FC nodes associated |
| 6457 | * will all vports to check if there is any node with |
| 6458 | * fc_rports associated with it. If there is an fc_rport |
| 6459 | * associated with the node, then the node is either in |
| 6460 | * discovered state or its devloss_timer is pending. |
| 6461 | */ |
| 6462 | static int |
| 6463 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6464 | { |
| 6465 | struct lpfc_vport **vports; |
| 6466 | int i, ret = 0; |
| 6467 | struct lpfc_nodelist *ndlp; |
| 6468 | struct Scsi_Host *shost; |
| 6469 | |
| 6470 | vports = lpfc_create_vport_work_array(phba); |
| 6471 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6472 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6473 | if (!vports) |
| 6474 | return 1; |
| 6475 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6476 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6477 | shost = lpfc_shost_from_vport(vports[i]); |
| 6478 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6479 | /* |
| 6480 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6481 | * flogi. |
| 6482 | * If dev_loss fires while we are waiting we do not want to |
| 6483 | * unreg the fcf. |
| 6484 | */ |
| 6485 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6486 | spin_unlock_irq(shost->host_lock); |
| 6487 | ret = 1; |
| 6488 | goto out; |
| 6489 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6490 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 6491 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 6492 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6493 | ret = 1; |
| 6494 | spin_unlock_irq(shost->host_lock); |
| 6495 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6496 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6497 | ret = 1; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 6498 | lpfc_printf_log(phba, KERN_INFO, |
| 6499 | LOG_NODE | LOG_DISCOVERY, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6500 | "2624 RPI %x DID %x flag %x " |
| 6501 | "still logged in\n", |
| 6502 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6503 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6504 | } |
| 6505 | } |
| 6506 | spin_unlock_irq(shost->host_lock); |
| 6507 | } |
| 6508 | out: |
| 6509 | lpfc_destroy_vport_work_array(phba, vports); |
| 6510 | return ret; |
| 6511 | } |
| 6512 | |
| 6513 | /** |
| 6514 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6515 | * @phba: Pointer to hba context object. |
| 6516 | * @mboxq: Pointer to mailbox object. |
| 6517 | * |
| 6518 | * This function frees memory associated with the mailbox command. |
| 6519 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6520 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6521 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6522 | { |
| 6523 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6524 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6525 | |
| 6526 | if (mboxq->u.mb.mbxStatus) { |
| 6527 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6528 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6529 | "HBA state x%x\n", |
| 6530 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6531 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6532 | spin_lock_irq(shost->host_lock); |
| 6533 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6534 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6535 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6536 | return; |
| 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6541 | * @phba: Pointer to hba context object. |
| 6542 | * @mboxq: Pointer to mailbox object. |
| 6543 | * |
| 6544 | * This function frees memory associated with the mailbox command. |
| 6545 | */ |
| 6546 | static void |
| 6547 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6548 | { |
| 6549 | struct lpfc_vport *vport = mboxq->vport; |
| 6550 | |
| 6551 | if (mboxq->u.mb.mbxStatus) { |
| 6552 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6553 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6554 | "HBA state x%x\n", |
| 6555 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6556 | } |
| 6557 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6558 | return; |
| 6559 | } |
| 6560 | |
| 6561 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6562 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6563 | * @phba: Pointer to hba context object. |
| 6564 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6565 | * This function prepare the HBA for unregistering the currently registered |
| 6566 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6567 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6568 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6569 | int |
| 6570 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6571 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6572 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6573 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6574 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6575 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6576 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6577 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6578 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6579 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6580 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6581 | /* At this point, all discovery is aborted */ |
| 6582 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6583 | |
| 6584 | /* Unregister VPIs */ |
| 6585 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6586 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6587 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6588 | /* Stop FLOGI/FDISC retries */ |
| 6589 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6590 | if (ndlp) |
| 6591 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6592 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6593 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6594 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6595 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6596 | shost = lpfc_shost_from_vport(vports[i]); |
| 6597 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6598 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6599 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6600 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6601 | } |
| 6602 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6603 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6604 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6605 | if (ndlp) |
| 6606 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6607 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6608 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6609 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6610 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6611 | shost = lpfc_shost_from_vport(phba->pport); |
| 6612 | spin_lock_irq(shost->host_lock); |
| 6613 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6614 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6615 | spin_unlock_irq(shost->host_lock); |
| 6616 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6617 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6618 | /* Cleanup any outstanding ELS commands */ |
| 6619 | lpfc_els_flush_all_cmd(phba); |
| 6620 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6621 | /* Unregister the physical port VFI */ |
| 6622 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6623 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | /** |
| 6627 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6628 | * @phba: Pointer to hba context object. |
| 6629 | * |
| 6630 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6631 | * unregister the currently registered FCF record. The driver does not reset |
| 6632 | * the driver FCF usage state flags. |
| 6633 | * |
| 6634 | * Return 0 if successfully issued, none-zero otherwise. |
| 6635 | */ |
| 6636 | int |
| 6637 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6638 | { |
| 6639 | LPFC_MBOXQ_t *mbox; |
| 6640 | int rc; |
| 6641 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6642 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6643 | if (!mbox) { |
| 6644 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6645 | "2551 UNREG_FCFI mbox allocation failed" |
| 6646 | "HBA state x%x\n", phba->pport->port_state); |
| 6647 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6648 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6649 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6650 | mbox->vport = phba->pport; |
| 6651 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6652 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6653 | |
| 6654 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6655 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6656 | "2552 Unregister FCFI command failed rc x%x " |
| 6657 | "HBA state x%x\n", |
| 6658 | rc, phba->pport->port_state); |
| 6659 | return -EINVAL; |
| 6660 | } |
| 6661 | return 0; |
| 6662 | } |
| 6663 | |
| 6664 | /** |
| 6665 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6666 | * @phba: Pointer to hba context object. |
| 6667 | * |
| 6668 | * This function unregisters the currently reigstered FCF. This function |
| 6669 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6670 | */ |
| 6671 | void |
| 6672 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6673 | { |
| 6674 | int rc; |
| 6675 | |
| 6676 | /* Preparation for unregistering fcf */ |
| 6677 | rc = lpfc_unregister_fcf_prep(phba); |
| 6678 | if (rc) { |
| 6679 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6680 | "2748 Failed to prepare for unregistering " |
| 6681 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6682 | return; |
| 6683 | } |
| 6684 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6685 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6686 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6687 | if (rc) |
| 6688 | return; |
| 6689 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6690 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6691 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6692 | |
| 6693 | /* |
| 6694 | * If driver is not unloading, check if there is any other |
| 6695 | * FCF record that can be used for discovery. |
| 6696 | */ |
| 6697 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6698 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6699 | return; |
| 6700 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6701 | /* This is considered as the initial FCF discovery scan */ |
| 6702 | spin_lock_irq(&phba->hbalock); |
| 6703 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6704 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6705 | |
| 6706 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6707 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6708 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6709 | 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] | 6710 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6711 | if (rc) { |
| 6712 | spin_lock_irq(&phba->hbalock); |
| 6713 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6714 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6715 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6716 | "2553 lpfc_unregister_unused_fcf failed " |
| 6717 | "to read FCF record HBA state x%x\n", |
| 6718 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6719 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6720 | } |
| 6721 | |
| 6722 | /** |
| 6723 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6724 | * @phba: Pointer to hba context object. |
| 6725 | * |
| 6726 | * This function just unregisters the currently reigstered FCF. It does not |
| 6727 | * try to find another FCF for discovery. |
| 6728 | */ |
| 6729 | void |
| 6730 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6731 | { |
| 6732 | int rc; |
| 6733 | |
| 6734 | /* Preparation for unregistering fcf */ |
| 6735 | rc = lpfc_unregister_fcf_prep(phba); |
| 6736 | if (rc) { |
| 6737 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6738 | "2749 Failed to prepare for unregistering " |
| 6739 | "HBA's FCF record: rc=%d\n", rc); |
| 6740 | return; |
| 6741 | } |
| 6742 | |
| 6743 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6744 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6745 | if (rc) |
| 6746 | return; |
| 6747 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6748 | spin_lock_irq(&phba->hbalock); |
| 6749 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6750 | spin_unlock_irq(&phba->hbalock); |
| 6751 | } |
| 6752 | |
| 6753 | /** |
| 6754 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6755 | * @phba: Pointer to hba context object. |
| 6756 | * |
| 6757 | * This function check if there are any connected remote port for the FCF and |
| 6758 | * if all the devices are disconnected, this function unregister FCFI. |
| 6759 | * This function also tries to use another FCF for discovery. |
| 6760 | */ |
| 6761 | void |
| 6762 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6763 | { |
| 6764 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6765 | * If HBA is not running in FIP mode, if HBA does not support |
| 6766 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6767 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6768 | */ |
| 6769 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6770 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6771 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6772 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6773 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6774 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6775 | spin_unlock_irq(&phba->hbalock); |
| 6776 | return; |
| 6777 | } |
| 6778 | spin_unlock_irq(&phba->hbalock); |
| 6779 | |
| 6780 | if (lpfc_fcf_inuse(phba)) |
| 6781 | return; |
| 6782 | |
| 6783 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | /** |
| 6787 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6788 | * @phba: Pointer to hba context object. |
| 6789 | * @buff: Buffer containing the FCF connection table as in the config |
| 6790 | * region. |
| 6791 | * This function create driver data structure for the FCF connection |
| 6792 | * record table read from config region 23. |
| 6793 | */ |
| 6794 | static void |
| 6795 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6796 | uint8_t *buff) |
| 6797 | { |
| 6798 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6799 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6800 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6801 | uint32_t record_count; |
| 6802 | int i; |
| 6803 | |
| 6804 | /* Free the current connect table */ |
| 6805 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6806 | &phba->fcf_conn_rec_list, list) { |
| 6807 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6808 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6809 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6810 | |
| 6811 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6812 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6813 | sizeof(struct lpfc_fcf_conn_rec); |
| 6814 | |
| 6815 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6816 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6817 | |
| 6818 | for (i = 0; i < record_count; i++) { |
| 6819 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6820 | continue; |
| 6821 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6822 | GFP_KERNEL); |
| 6823 | if (!conn_entry) { |
| 6824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6825 | "2566 Failed to allocate connection" |
| 6826 | " table entry\n"); |
| 6827 | return; |
| 6828 | } |
| 6829 | |
| 6830 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6831 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6832 | list_add_tail(&conn_entry->list, |
| 6833 | &phba->fcf_conn_rec_list); |
| 6834 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6835 | |
| 6836 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6837 | i = 0; |
| 6838 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6839 | list) { |
| 6840 | conn_rec = &conn_entry->conn_rec; |
| 6841 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6842 | "3345 FCF connection list rec[%02d]: " |
| 6843 | "flags:x%04x, vtag:x%04x, " |
| 6844 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6845 | "%02x:%02x:%02x:%02x, " |
| 6846 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6847 | "%02x:%02x:%02x:%02x\n", i++, |
| 6848 | conn_rec->flags, conn_rec->vlan_tag, |
| 6849 | conn_rec->fabric_name[0], |
| 6850 | conn_rec->fabric_name[1], |
| 6851 | conn_rec->fabric_name[2], |
| 6852 | conn_rec->fabric_name[3], |
| 6853 | conn_rec->fabric_name[4], |
| 6854 | conn_rec->fabric_name[5], |
| 6855 | conn_rec->fabric_name[6], |
| 6856 | conn_rec->fabric_name[7], |
| 6857 | conn_rec->switch_name[0], |
| 6858 | conn_rec->switch_name[1], |
| 6859 | conn_rec->switch_name[2], |
| 6860 | conn_rec->switch_name[3], |
| 6861 | conn_rec->switch_name[4], |
| 6862 | conn_rec->switch_name[5], |
| 6863 | conn_rec->switch_name[6], |
| 6864 | conn_rec->switch_name[7]); |
| 6865 | } |
| 6866 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6867 | } |
| 6868 | |
| 6869 | /** |
| 6870 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6871 | * @phba: Pointer to hba context object. |
| 6872 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6873 | * |
| 6874 | * This function update driver data structure with config |
| 6875 | * parameters read from config region 23. |
| 6876 | */ |
| 6877 | static void |
| 6878 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6879 | uint8_t *buff) |
| 6880 | { |
| 6881 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6882 | struct lpfc_fcoe_params *fcoe_param; |
| 6883 | |
| 6884 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6885 | buff; |
| 6886 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6887 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6888 | |
| 6889 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6890 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6891 | return; |
| 6892 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6893 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6894 | phba->valid_vlan = 1; |
| 6895 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6896 | 0xFFF; |
| 6897 | } |
| 6898 | |
| 6899 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6900 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6901 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6902 | return; |
| 6903 | } |
| 6904 | |
| 6905 | /** |
| 6906 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6907 | * @buff: Buffer containing config region 23 data. |
| 6908 | * @size: Size of the data buffer. |
| 6909 | * @rec_type: Record type to be searched. |
| 6910 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6911 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6912 | * of the record specified by record_type. If record found, this |
| 6913 | * function return pointer to the record else return NULL. |
| 6914 | */ |
| 6915 | static uint8_t * |
| 6916 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6917 | { |
| 6918 | uint32_t offset = 0, rec_length; |
| 6919 | |
| 6920 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6921 | (size < sizeof(uint32_t))) |
| 6922 | return NULL; |
| 6923 | |
| 6924 | rec_length = buff[offset + 1]; |
| 6925 | |
| 6926 | /* |
| 6927 | * One TLV record has one word header and number of data words |
| 6928 | * specified in the rec_length field of the record header. |
| 6929 | */ |
| 6930 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6931 | <= size) { |
| 6932 | if (buff[offset] == rec_type) |
| 6933 | return &buff[offset]; |
| 6934 | |
| 6935 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6936 | return NULL; |
| 6937 | |
| 6938 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6939 | rec_length = buff[offset + 1]; |
| 6940 | } |
| 6941 | return NULL; |
| 6942 | } |
| 6943 | |
| 6944 | /** |
| 6945 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6946 | * @phba: Pointer to lpfc_hba data structure. |
| 6947 | * @buff: Buffer containing config region 23 data. |
| 6948 | * @size: Size of the data buffer. |
| 6949 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6950 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6951 | * populate driver data structure with the parameters. |
| 6952 | */ |
| 6953 | void |
| 6954 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6955 | uint8_t *buff, |
| 6956 | uint32_t size) |
| 6957 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6958 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6959 | uint8_t *rec_ptr; |
| 6960 | |
| 6961 | /* |
| 6962 | * If data size is less than 2 words signature and version cannot be |
| 6963 | * verified. |
| 6964 | */ |
| 6965 | if (size < 2*sizeof(uint32_t)) |
| 6966 | return; |
| 6967 | |
| 6968 | /* Check the region signature first */ |
| 6969 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6971 | "2567 Config region 23 has bad signature\n"); |
| 6972 | return; |
| 6973 | } |
| 6974 | |
| 6975 | offset += 4; |
| 6976 | |
| 6977 | /* Check the data structure version */ |
| 6978 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6980 | "2568 Config region 23 has bad version\n"); |
| 6981 | return; |
| 6982 | } |
| 6983 | offset += 4; |
| 6984 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6985 | /* Read FCoE param record */ |
| 6986 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6987 | size - offset, FCOE_PARAM_TYPE); |
| 6988 | if (rec_ptr) |
| 6989 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6990 | |
| 6991 | /* Read FCF connection table */ |
| 6992 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6993 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6994 | if (rec_ptr) |
| 6995 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6996 | |
| 6997 | } |