| 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 | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 25 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <linux/pci.h> |
| 28 | #include <linux/kthread.h> |
| 29 | #include <linux/interrupt.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 30 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
| 37 | |
| 38 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 40 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 42 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_disc.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 47 | #include "lpfc_scsi.h" |
| 48 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_logmsg.h" |
| 50 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 52 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | |
| 54 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 55 | static uint8_t lpfcAlpaArray[] = { |
| 56 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 57 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 58 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 59 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 60 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 61 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 62 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 63 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 64 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 65 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 66 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 67 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 68 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 69 | }; |
| 70 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 71 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 72 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 73 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 74 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 76 | void |
| 77 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 79 | struct lpfc_rport_data *rdata; |
| 80 | struct lpfc_nodelist * ndlp; |
| 81 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 83 | rdata = rport->dd_data; |
| 84 | ndlp = rdata->pnode; |
| 85 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 86 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 87 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 88 | printk(KERN_ERR "Cannot find remote node" |
| 89 | " to terminate I/O Data x%x\n", |
| 90 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 94 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 95 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 96 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 97 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 98 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 99 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 100 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 101 | lpfc_sli_abort_iocb(ndlp->vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 102 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 103 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 104 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * This function will be called when dev_loss_tmo fire. |
| 109 | */ |
| 110 | void |
| 111 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 112 | { |
| 113 | struct lpfc_rport_data *rdata; |
| 114 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 115 | struct lpfc_vport *vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 116 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 117 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 118 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 119 | int put_node; |
| 120 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 121 | |
| 122 | rdata = rport->dd_data; |
| 123 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 124 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 125 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 126 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 127 | vport = ndlp->vport; |
| 128 | phba = vport->phba; |
| 129 | |
| 130 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 131 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 132 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 133 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 134 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 135 | "3181 dev_loss_callbk x%06x, rport %p flg x%x\n", |
| 136 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 137 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 138 | /* Don't defer this if we are in the process of deleting the vport |
| 139 | * or unloading the driver. The unload will cleanup the node |
| 140 | * appropriately we just need to cleanup the ndlp rport info here. |
| 141 | */ |
| 142 | if (vport->load_flag & FC_UNLOADING) { |
| 143 | put_node = rdata->pnode != NULL; |
| 144 | put_rport = ndlp->rport != NULL; |
| 145 | rdata->pnode = NULL; |
| 146 | ndlp->rport = NULL; |
| 147 | if (put_node) |
| 148 | lpfc_nlp_put(ndlp); |
| 149 | if (put_rport) |
| 150 | put_device(&rport->dev); |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 155 | return; |
| 156 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 157 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
| 158 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 159 | "6789 rport name %llx != node port name %llx", |
| 160 | rport->port_name, |
| 161 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 162 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 163 | evtp = &ndlp->dev_loss_evt; |
| 164 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 165 | if (!list_empty(&evtp->evt_listp)) { |
| 166 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 167 | "6790 rport name %llx dev_loss_evt pending", |
| 168 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 169 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 170 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 171 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 172 | shost = lpfc_shost_from_vport(vport); |
| 173 | spin_lock_irq(shost->host_lock); |
| 174 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
| 175 | spin_unlock_irq(shost->host_lock); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 176 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 177 | /* We need to hold the node by incrementing the reference |
| 178 | * count until this queued work is done |
| 179 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 180 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 181 | |
| 182 | spin_lock_irq(&phba->hbalock); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 183 | if (evtp->evt_arg1) { |
| 184 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 185 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 186 | lpfc_worker_wake_up(phba); |
| 187 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 188 | spin_unlock_irq(&phba->hbalock); |
| 189 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 193 | /** |
| 194 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 195 | * @ndlp: Pointer to remote node object. |
| 196 | * |
| 197 | * This function is called from the worker thread when devloss timeout timer |
| 198 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 199 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 200 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 201 | * when devloss timeout happened to this @ndlp. |
| 202 | **/ |
| 203 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 204 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 205 | { |
| 206 | struct lpfc_rport_data *rdata; |
| 207 | struct fc_rport *rport; |
| 208 | struct lpfc_vport *vport; |
| 209 | struct lpfc_hba *phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 210 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 211 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 212 | int put_node; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 213 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 214 | int fcf_inuse = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 215 | |
| 216 | rport = ndlp->rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 217 | vport = ndlp->vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 218 | shost = lpfc_shost_from_vport(vport); |
| 219 | |
| 220 | spin_lock_irq(shost->host_lock); |
| 221 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
| 222 | spin_unlock_irq(shost->host_lock); |
| 223 | |
| 224 | if (!rport) |
| 225 | return fcf_inuse; |
| 226 | |
| 227 | name = (uint8_t *) &ndlp->nlp_portname; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 228 | phba = vport->phba; |
| 229 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 230 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 231 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 233 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 234 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 235 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 236 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 237 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 238 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", |
| 239 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 240 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 241 | /* |
| 242 | * lpfc_nlp_remove if reached with dangling rport drops the |
| 243 | * reference. To make sure that does not happen clear rport |
| 244 | * pointer in ndlp before lpfc_nlp_put. |
| 245 | */ |
| 246 | rdata = rport->dd_data; |
| 247 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 248 | /* Don't defer this if we are in the process of deleting the vport |
| 249 | * or unloading the driver. The unload will cleanup the node |
| 250 | * appropriately we just need to cleanup the ndlp rport info here. |
| 251 | */ |
| 252 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 253 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 254 | /* flush the target */ |
| 255 | lpfc_sli_abort_iocb(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 256 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
| 257 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 258 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 259 | put_node = rdata->pnode != NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 260 | rdata->pnode = NULL; |
| 261 | ndlp->rport = NULL; |
| 262 | if (put_node) |
| 263 | lpfc_nlp_put(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 264 | put_device(&rport->dev); |
| 265 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 266 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 267 | } |
| 268 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 269 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 270 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 271 | "0284 Devloss timeout Ignored on " |
| 272 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 273 | "NPort x%x\n", |
| 274 | *name, *(name+1), *(name+2), *(name+3), |
| 275 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 276 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 277 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 278 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 279 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 280 | put_node = rdata->pnode != NULL; |
| 281 | rdata->pnode = NULL; |
| 282 | ndlp->rport = NULL; |
| 283 | if (put_node) |
| 284 | lpfc_nlp_put(ndlp); |
| 285 | put_device(&rport->dev); |
| 286 | |
| 287 | if (ndlp->nlp_type & NLP_FABRIC) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 288 | return fcf_inuse; |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 291 | warn_on = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 292 | lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 293 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 295 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 296 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 297 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 298 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 299 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 300 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 301 | *name, *(name+1), *(name+2), *(name+3), |
| 302 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 303 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 304 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 305 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 306 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 307 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 308 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 309 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 310 | *name, *(name+1), *(name+2), *(name+3), |
| 311 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 312 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 313 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 314 | } |
| 315 | |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 316 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 317 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 318 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 319 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 320 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 321 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 322 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 323 | return fcf_inuse; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 328 | * @phba: Pointer to hba context object. |
| 329 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 330 | * @nlp_did: remote node identifer with devloss timeout. |
| 331 | * |
| 332 | * This function is called from the worker thread after invoking devloss |
| 333 | * timeout handler and releasing the reference count for the ndlp with |
| 334 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 335 | * timeout of the last remote node which had been in use of FCF, when this |
| 336 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 337 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 338 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 339 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 340 | * engine is in FCF discovery process, the devloss timeout state shall |
| 341 | * be set for either the FCF table scan process or roundrobin failover |
| 342 | * process to unregister the in-use FCF. |
| 343 | **/ |
| 344 | static void |
| 345 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 346 | uint32_t nlp_did) |
| 347 | { |
| 348 | /* If devloss timeout happened to a remote node when FCF had no |
| 349 | * longer been in-use, do nothing. |
| 350 | */ |
| 351 | if (!fcf_inuse) |
| 352 | return; |
| 353 | |
| 354 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 355 | spin_lock_irq(&phba->hbalock); |
| 356 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 357 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 358 | spin_unlock_irq(&phba->hbalock); |
| 359 | return; |
| 360 | } |
| 361 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 362 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 363 | "2847 Last remote node (x%x) using " |
| 364 | "FCF devloss tmo\n", nlp_did); |
| 365 | } |
| 366 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 367 | spin_unlock_irq(&phba->hbalock); |
| 368 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 369 | "2868 Devloss tmo to FCF rediscovery " |
| 370 | "in progress\n"); |
| 371 | return; |
| 372 | } |
| 373 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 374 | spin_unlock_irq(&phba->hbalock); |
| 375 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 376 | "2869 Devloss tmo to idle FIP engine, " |
| 377 | "unreg in-use FCF and rescan.\n"); |
| 378 | /* Unregister in-use FCF and rescan */ |
| 379 | lpfc_unregister_fcf_rescan(phba); |
| 380 | return; |
| 381 | } |
| 382 | spin_unlock_irq(&phba->hbalock); |
| 383 | if (phba->hba_flag & FCF_TS_INPROG) |
| 384 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 385 | "2870 FCF table scan in progress\n"); |
| 386 | if (phba->hba_flag & FCF_RR_INPROG) |
| 387 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 388 | "2871 FLOGI roundrobin FCF failover " |
| 389 | "in progress\n"); |
| 390 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 391 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 392 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 393 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 395 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 396 | * @phba: Pointer to hba context object. |
| 397 | * |
| 398 | * This function is called from the functions which need to post |
| 399 | * events from interrupt context. This function allocates data |
| 400 | * structure required for posting event. It also keeps track of |
| 401 | * number of events pending and prevent event storm when there are |
| 402 | * too many events. |
| 403 | **/ |
| 404 | struct lpfc_fast_path_event * |
| 405 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 406 | struct lpfc_fast_path_event *ret; |
| 407 | |
| 408 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 409 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 410 | return NULL; |
| 411 | |
| 412 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 413 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 414 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 415 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 416 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 417 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 418 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 423 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 424 | * @phba: Pointer to hba context object. |
| 425 | * @evt: Event object which need to be freed. |
| 426 | * |
| 427 | * This function frees the data structure required for posting |
| 428 | * events. |
| 429 | **/ |
| 430 | void |
| 431 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 432 | struct lpfc_fast_path_event *evt) { |
| 433 | |
| 434 | atomic_dec(&phba->fast_event_count); |
| 435 | kfree(evt); |
| 436 | } |
| 437 | |
| 438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 439 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 440 | * @phba: Pointer to hba context object. |
| 441 | * @evtp: Event data structure. |
| 442 | * |
| 443 | * This function is called from worker thread, when the interrupt |
| 444 | * context need to post an event. This function posts the event |
| 445 | * to fc transport netlink interface. |
| 446 | **/ |
| 447 | static void |
| 448 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 449 | struct lpfc_work_evt *evtp) |
| 450 | { |
| 451 | unsigned long evt_category, evt_sub_category; |
| 452 | struct lpfc_fast_path_event *fast_evt_data; |
| 453 | char *evt_data; |
| 454 | uint32_t evt_data_size; |
| 455 | struct Scsi_Host *shost; |
| 456 | |
| 457 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 458 | work_evt); |
| 459 | |
| 460 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 461 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 462 | fabric_evt.subcategory; |
| 463 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 464 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 465 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 466 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 467 | evt_data_size = sizeof(fast_evt_data->un. |
| 468 | read_check_error); |
| 469 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 470 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 471 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 472 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 473 | } else { |
| 474 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 475 | return; |
| 476 | } |
| 477 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 478 | switch (evt_sub_category) { |
| 479 | case LPFC_EVENT_QFULL: |
| 480 | case LPFC_EVENT_DEVBSY: |
| 481 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 482 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 483 | break; |
| 484 | case LPFC_EVENT_CHECK_COND: |
| 485 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 486 | evt_data_size = sizeof(fast_evt_data->un. |
| 487 | check_cond_evt); |
| 488 | break; |
| 489 | case LPFC_EVENT_VARQUEDEPTH: |
| 490 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 491 | evt_data_size = sizeof(fast_evt_data->un. |
| 492 | queue_depth_evt); |
| 493 | break; |
| 494 | default: |
| 495 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 496 | return; |
| 497 | } |
| 498 | } else { |
| 499 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 500 | return; |
| 501 | } |
| 502 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 503 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 504 | fc_host_post_vendor_event(shost, |
| 505 | fc_get_event_number(), |
| 506 | evt_data_size, |
| 507 | evt_data, |
| 508 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 509 | |
| 510 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 511 | return; |
| 512 | } |
| 513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | { |
| 517 | struct lpfc_work_evt *evtp = NULL; |
| 518 | struct lpfc_nodelist *ndlp; |
| 519 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 520 | int fcf_inuse; |
| 521 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 522 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | spin_lock_irq(&phba->hbalock); |
| 524 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 526 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 529 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 531 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 533 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 534 | /* decrement the node reference count held |
| 535 | * for this queued work |
| 536 | */ |
| 537 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 539 | case LPFC_EVT_DEV_LOSS: |
| 540 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 541 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 542 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 543 | /* decrement the node reference count held for |
| 544 | * this queued work |
| 545 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 546 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 547 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 548 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 549 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 550 | fcf_inuse, |
| 551 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 552 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 554 | if (phba->link_state < LPFC_LINK_DOWN) |
| 555 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 556 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 557 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 558 | complete((struct completion *)(evtp->evt_arg2)); |
| 559 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 560 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 561 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 562 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 563 | *(int *)(evtp->evt_arg1) = 0; |
| 564 | complete((struct completion *)(evtp->evt_arg2)); |
| 565 | break; |
| 566 | case LPFC_EVT_OFFLINE: |
| 567 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 568 | lpfc_sli_brdrestart(phba); |
| 569 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 570 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 571 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 572 | complete((struct completion *)(evtp->evt_arg2)); |
| 573 | break; |
| 574 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 575 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 576 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 577 | lpfc_sli_brdreset(phba); |
| 578 | lpfc_hba_down_post(phba); |
| 579 | *(int *)(evtp->evt_arg1) = |
| 580 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 581 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 582 | complete((struct completion *)(evtp->evt_arg2)); |
| 583 | break; |
| 584 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 585 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 586 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 587 | = (phba->pport->stopped) |
| 588 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 589 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 590 | complete((struct completion *)(evtp->evt_arg2)); |
| 591 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 592 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 593 | lpfc_send_fastpath_evt(phba, evtp); |
| 594 | free_evt = 0; |
| 595 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 596 | case LPFC_EVT_RESET_HBA: |
| 597 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 598 | lpfc_reset_hba(phba); |
| 599 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | } |
| 601 | if (free_evt) |
| 602 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 603 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 604 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 605 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | |
| 607 | } |
| 608 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 609 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 610 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 611 | { |
| 612 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 613 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 614 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 615 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 616 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | ha_copy = phba->work_ha; |
| 620 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 621 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 623 | /* First, try to post the next mailbox command to SLI4 device */ |
| 624 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 625 | lpfc_sli4_post_async_mbox(phba); |
| 626 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 627 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 628 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | lpfc_handle_eratt(phba); |
| 630 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 631 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | lpfc_sli_handle_mb_event(phba); |
| 633 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 634 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 636 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 637 | /* Process SLI4 events */ |
| 638 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 639 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 640 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 641 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 642 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 643 | if (phba->hba_flag & NVME_XRI_ABORT_EVENT) |
| 644 | lpfc_sli4_nvme_xri_abort_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 645 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 646 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 647 | if (phba->hba_flag & ASYNC_EVENT) |
| 648 | lpfc_sli4_async_event_proc(phba); |
| 649 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 650 | spin_lock_irq(&phba->hbalock); |
| 651 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 652 | spin_unlock_irq(&phba->hbalock); |
| 653 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 654 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 655 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 656 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 657 | } |
| 658 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 659 | vports = lpfc_create_vport_work_array(phba); |
| 660 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 661 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 662 | /* |
| 663 | * We could have no vports in array if unloading, so if |
| 664 | * this happens then just use the pport |
| 665 | */ |
| 666 | if (vports[i] == NULL && i == 0) |
| 667 | vport = phba->pport; |
| 668 | else |
| 669 | vport = vports[i]; |
| 670 | if (vport == NULL) |
| 671 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 672 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 673 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 674 | vport->work_port_events &= ~work_port_events; |
| 675 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 676 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 677 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 678 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 679 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 680 | if (work_port_events & WORKER_HB_TMO) |
| 681 | lpfc_hb_timeout_handler(phba); |
| 682 | if (work_port_events & WORKER_MBOX_TMO) |
| 683 | lpfc_mbox_timeout_handler(phba); |
| 684 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 685 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 686 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 687 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 688 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 689 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 690 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 691 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 692 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 693 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 694 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 695 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 696 | if ((status & HA_RXMASK) || |
| 697 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 698 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 699 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 700 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 701 | /* Set the lpfc data pending flag */ |
| 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 | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 704 | if (phba->link_state >= LPFC_LINK_UP) { |
| 705 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 706 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 707 | (status & |
| 708 | HA_RXMASK)); |
| 709 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 710 | } |
Sebastian Herbszt | b103918 | 2015-07-22 10:53:22 +0200 | [diff] [blame] | 711 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 712 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 713 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 714 | /* |
| 715 | * Turn on Ring interrupts |
| 716 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 717 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 718 | spin_lock_irq(&phba->hbalock); |
| 719 | control = readl(phba->HCregaddr); |
| 720 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 721 | lpfc_debugfs_slow_ring_trc(phba, |
| 722 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 723 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 724 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 725 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 726 | writel(control, phba->HCregaddr); |
| 727 | readl(phba->HCregaddr); /* flush */ |
| 728 | } else { |
| 729 | lpfc_debugfs_slow_ring_trc(phba, |
| 730 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 731 | control, ha_copy, 0); |
| 732 | } |
| 733 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | } |
| 735 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 736 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | } |
| 738 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | int |
| 740 | lpfc_do_work(void *p) |
| 741 | { |
| 742 | struct lpfc_hba *phba = p; |
| 743 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 744 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 745 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 746 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 747 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 749 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 750 | /* wait and check worker queue activities */ |
| 751 | rc = wait_event_interruptible(phba->work_waitq, |
| 752 | (test_and_clear_bit(LPFC_DATA_READY, |
| 753 | &phba->data_flags) |
| 754 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 755 | /* Signal wakeup shall terminate the worker thread */ |
| 756 | if (rc) { |
| 757 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 758 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 759 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 760 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 762 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 765 | phba->worker_thread = NULL; |
| 766 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 767 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /* |
| 772 | * 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] | 773 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | * embedding it in the IOCB. |
| 775 | */ |
| 776 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | uint32_t evt) |
| 779 | { |
| 780 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 781 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | |
| 783 | /* |
| 784 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 785 | * be queued to worker thread for processing |
| 786 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 787 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | if (!evtp) |
| 789 | return 0; |
| 790 | |
| 791 | evtp->evt_arg1 = arg1; |
| 792 | evtp->evt_arg2 = arg2; |
| 793 | evtp->evt = evt; |
| 794 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 795 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 796 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 797 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 799 | lpfc_worker_wake_up(phba); |
| 800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | return 1; |
| 802 | } |
| 803 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 804 | void |
| 805 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 806 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 807 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 808 | struct lpfc_hba *phba = vport->phba; |
| 809 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 810 | |
| 811 | 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] | 812 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 813 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 814 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 815 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 816 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 817 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 818 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | lpfc_unreg_rpi(vport, ndlp); |
| 820 | |
| 821 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 822 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 823 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | continue; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 825 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 826 | remove |
| 827 | ? NLP_EVT_DEVICE_RM |
| 828 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 829 | } |
| 830 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 831 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 832 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 833 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 834 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 835 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 836 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 840 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 841 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 842 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 843 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 844 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 845 | /* Cleanup any outstanding received buffers */ |
| 846 | lpfc_cleanup_rcv_buffers(vport); |
| 847 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 848 | /* Cleanup any outstanding RSCN activity */ |
| 849 | lpfc_els_flush_rscn(vport); |
| 850 | |
| 851 | /* Cleanup any outstanding ELS commands */ |
| 852 | lpfc_els_flush_cmd(vport); |
| 853 | |
| 854 | lpfc_cleanup_rpis(vport, 0); |
| 855 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 856 | /* Turn off discovery timer if its running */ |
| 857 | lpfc_can_disctmo(vport); |
| 858 | } |
| 859 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 860 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 861 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 862 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 863 | struct lpfc_hba *phba = vport->phba; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 864 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 865 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 866 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 867 | fc_host_post_event(shost, fc_get_event_number(), |
| 868 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 869 | |
| 870 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 871 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 872 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 873 | |
| 874 | lpfc_port_link_failure(vport); |
| 875 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 876 | /* Stop delayed Nport discovery */ |
| 877 | spin_lock_irq(shost->host_lock); |
| 878 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 879 | spin_unlock_irq(shost->host_lock); |
| 880 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 881 | } |
| 882 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 884 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 886 | struct lpfc_vport *vport = phba->pport; |
| 887 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 888 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 889 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 890 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 892 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 893 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 894 | |
| 895 | /* Block all SCSI stack I/Os */ |
| 896 | lpfc_scsi_dev_block(phba); |
| 897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 898 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 899 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 900 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 901 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 902 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 903 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 904 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 905 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 906 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 907 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 908 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 909 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 910 | /* Issue a LINK DOWN event to all nodes */ |
| 911 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 912 | |
| 913 | vports[i]->fc_myDID = 0; |
| 914 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 915 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 916 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 917 | if (phba->nvmet_support) |
| 918 | lpfc_nvmet_update_targetport(phba); |
| 919 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 920 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 921 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 922 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 923 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 924 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 927 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 928 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 929 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 931 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 932 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 933 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 938 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 939 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 940 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 942 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 943 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 944 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | } |
| 948 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 950 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 951 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 953 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 954 | } |
| 955 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 956 | static void |
| 957 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 959 | struct lpfc_nodelist *ndlp; |
| 960 | |
| 961 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 962 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 963 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 965 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 966 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 967 | /* On Linkup its safe to clean up the ndlp |
| 968 | * from Fabric connections. |
| 969 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 970 | if (ndlp->nlp_DID != Fabric_DID) |
| 971 | lpfc_unreg_rpi(vport, ndlp); |
| 972 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 973 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 974 | /* Fail outstanding IO now since device is |
| 975 | * marked for PLOGI. |
| 976 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 977 | lpfc_unreg_rpi(vport, ndlp); |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | static void |
| 983 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 984 | { |
| 985 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 986 | struct lpfc_hba *phba = vport->phba; |
| 987 | |
| 988 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 989 | return; |
| 990 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 991 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 992 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 993 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 994 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 995 | /* If NPIV is not enabled, only bring the physical port up */ |
| 996 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 997 | (vport != phba->pport)) |
| 998 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1000 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 1001 | fc_host_post_event(shost, fc_get_event_number(), |
| 1002 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1003 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1004 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1005 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1006 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1007 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1008 | vport->fc_ns_retry = 0; |
| 1009 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1011 | if (vport->fc_flag & FC_LBIT) |
| 1012 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | static int |
| 1017 | lpfc_linkup(struct lpfc_hba *phba) |
| 1018 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1019 | struct lpfc_vport **vports; |
| 1020 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1021 | |
| 1022 | phba->link_state = LPFC_LINK_UP; |
| 1023 | |
| 1024 | /* Unblock fabric iocbs if they are blocked */ |
| 1025 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1026 | del_timer_sync(&phba->fabric_block_timer); |
| 1027 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1028 | vports = lpfc_create_vport_work_array(phba); |
| 1029 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1030 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1031 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1032 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | /* |
| 1038 | * This routine handles processing a CLEAR_LA mailbox |
| 1039 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1040 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1041 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1042 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1043 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1044 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1046 | struct lpfc_vport *vport = pmb->vport; |
| 1047 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1048 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1049 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | uint32_t control; |
| 1051 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1053 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1054 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | |
| 1056 | /* Check for error */ |
| 1057 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1058 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1059 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1060 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1061 | "state x%x\n", |
| 1062 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | goto out; |
| 1065 | } |
| 1066 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1067 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1068 | phba->link_state = LPFC_HBA_READY; |
| 1069 | |
| 1070 | spin_lock_irq(&phba->hbalock); |
| 1071 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1072 | control = readl(phba->HCregaddr); |
| 1073 | control |= HC_LAINT_ENA; |
| 1074 | writel(control, phba->HCregaddr); |
| 1075 | readl(phba->HCregaddr); /* flush */ |
| 1076 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1077 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1078 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | out: |
| 1081 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1082 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1083 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1084 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1085 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1086 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1087 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1090 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1091 | |
| 1092 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1093 | |
| 1094 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1096 | control = readl(phba->HCregaddr); |
| 1097 | control |= HC_LAINT_ENA; |
| 1098 | writel(control, phba->HCregaddr); |
| 1099 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1100 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | |
| 1102 | return; |
| 1103 | } |
| 1104 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1106 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1107 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1109 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1111 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1114 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1115 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1116 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1117 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1118 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1119 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1120 | return; |
| 1121 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1122 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1124 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1125 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1127 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1128 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1130 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1131 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1133 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1134 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1135 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1136 | if (vport->port_state != LPFC_FLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1137 | lpfc_initial_flogi(vport); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1138 | else if (vport->fc_flag & FC_PT2PT) |
| 1139 | lpfc_disc_start(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1140 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | |
| 1142 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1143 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1144 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1145 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1146 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1147 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1148 | |
| 1149 | lpfc_linkdown(phba); |
| 1150 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1151 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1152 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1153 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1155 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | return; |
| 1157 | } |
| 1158 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1159 | /** |
| 1160 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1161 | * @phba pointer to the struct lpfc_hba for this port. |
| 1162 | * This fucnction resets the round robin bit mask and clears the |
| 1163 | * fcf priority list. The list deletions are done while holding the |
| 1164 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1165 | * from the lpfc_fcf_pri record. |
| 1166 | **/ |
| 1167 | void |
| 1168 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1169 | { |
| 1170 | struct lpfc_fcf_pri *fcf_pri; |
| 1171 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1172 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1173 | spin_lock_irq(&phba->hbalock); |
| 1174 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1175 | &phba->fcf.fcf_pri_list, list) { |
| 1176 | list_del_init(&fcf_pri->list); |
| 1177 | fcf_pri->fcf_rec.flag = 0; |
| 1178 | } |
| 1179 | spin_unlock_irq(&phba->hbalock); |
| 1180 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1181 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1182 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1183 | { |
| 1184 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1185 | |
| 1186 | if (mboxq->u.mb.mbxStatus) { |
| 1187 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1188 | "2017 REG_FCFI mbxStatus error x%x " |
| 1189 | "HBA state x%x\n", |
| 1190 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1191 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1195 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1196 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1197 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1198 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1199 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1200 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1201 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1202 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1203 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1204 | goto fail_out; |
| 1205 | |
| 1206 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1207 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1208 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1209 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1210 | if (vport->port_state != LPFC_FLOGI) { |
| 1211 | phba->hba_flag |= FCF_RR_INPROG; |
| 1212 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1213 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1214 | goto out; |
| 1215 | } |
| 1216 | spin_unlock_irq(&phba->hbalock); |
| 1217 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1218 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1219 | fail_out: |
| 1220 | spin_lock_irq(&phba->hbalock); |
| 1221 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1222 | spin_unlock_irq(&phba->hbalock); |
| 1223 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1224 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1229 | * @fab_name: pointer to fabric name. |
| 1230 | * @new_fcf_record: pointer to fcf record. |
| 1231 | * |
| 1232 | * This routine compare the fcf record's fabric name with provided |
| 1233 | * fabric name. If the fabric name are identical this function |
| 1234 | * returns 1 else return 0. |
| 1235 | **/ |
| 1236 | static uint32_t |
| 1237 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1238 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1239 | 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] | 1240 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1241 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1242 | return 0; |
| 1243 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1244 | return 0; |
| 1245 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1246 | return 0; |
| 1247 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1248 | return 0; |
| 1249 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1250 | return 0; |
| 1251 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1252 | return 0; |
| 1253 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1254 | return 0; |
| 1255 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1259 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1260 | * @fab_name: pointer to fabric name. |
| 1261 | * @new_fcf_record: pointer to fcf record. |
| 1262 | * |
| 1263 | * This routine compare the fcf record's switch name with provided |
| 1264 | * switch name. If the switch name are identical this function |
| 1265 | * returns 1 else return 0. |
| 1266 | **/ |
| 1267 | static uint32_t |
| 1268 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1269 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1270 | 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] | 1271 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1272 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1273 | return 0; |
| 1274 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1275 | return 0; |
| 1276 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1277 | return 0; |
| 1278 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1279 | return 0; |
| 1280 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1281 | return 0; |
| 1282 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1283 | return 0; |
| 1284 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1285 | return 0; |
| 1286 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1290 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1291 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1292 | * @new_fcf_record: pointer to fcf record. |
| 1293 | * |
| 1294 | * This routine compare the fcf record's mac address with HBA's |
| 1295 | * FCF mac address. If the mac addresses are identical this function |
| 1296 | * returns 1 else return 0. |
| 1297 | **/ |
| 1298 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1299 | 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] | 1300 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1301 | 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] | 1302 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1303 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1304 | return 0; |
| 1305 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1306 | return 0; |
| 1307 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1308 | return 0; |
| 1309 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1310 | return 0; |
| 1311 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1312 | return 0; |
| 1313 | return 1; |
| 1314 | } |
| 1315 | |
| 1316 | static bool |
| 1317 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1318 | { |
| 1319 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1323 | * lpfc_update_fcf_record - Update driver fcf record |
| 1324 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1325 | * @phba: pointer to lpfc hba data structure. |
| 1326 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1327 | * @new_fcf_record: pointer to hba fcf record. |
| 1328 | * |
| 1329 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1330 | * record. This routine is called with the host lock held. |
| 1331 | **/ |
| 1332 | static void |
| 1333 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1334 | struct fcf_record *new_fcf_record |
| 1335 | ) |
| 1336 | { |
| 1337 | struct lpfc_fcf_pri *fcf_pri; |
| 1338 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1339 | lockdep_assert_held(&phba->hbalock); |
| 1340 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1341 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1342 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1343 | /* FCF record priority */ |
| 1344 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1345 | |
| 1346 | } |
| 1347 | |
| 1348 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1349 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1350 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1351 | * @new_fcf_record: pointer to fcf record. |
| 1352 | * |
| 1353 | * This routine copies the FCF information from the FCF |
| 1354 | * record to lpfc_hba data structure. |
| 1355 | **/ |
| 1356 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1357 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1358 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1359 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1360 | /* Fabric name */ |
| 1361 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1362 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1363 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1364 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1365 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1366 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1367 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1368 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1370 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1371 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1372 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1373 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1374 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1375 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1376 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1377 | /* Mac address */ |
| 1378 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1379 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1380 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1381 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1382 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1383 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1384 | /* FCF record index */ |
| 1385 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1386 | /* FCF record priority */ |
| 1387 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1388 | /* Switch name */ |
| 1389 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1390 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1391 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1392 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1393 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1394 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1395 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1396 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1397 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1398 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1399 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1400 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1401 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1402 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1403 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1404 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1408 | * lpfc_update_fcf_record - Update driver fcf record |
| 1409 | * @phba: pointer to lpfc hba data structure. |
| 1410 | * @fcf_rec: pointer to driver fcf record. |
| 1411 | * @new_fcf_record: pointer to hba fcf record. |
| 1412 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1413 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1414 | * @flag: flag bits to be set to the driver fcf record. |
| 1415 | * |
| 1416 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1417 | * together with the address mode, vlan_id, and other informations. This |
| 1418 | * routine is called with the host lock held. |
| 1419 | **/ |
| 1420 | static void |
| 1421 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1422 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1423 | uint16_t vlan_id, uint32_t flag) |
| 1424 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1425 | lockdep_assert_held(&phba->hbalock); |
| 1426 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1427 | /* Copy the fields from the HBA's FCF record */ |
| 1428 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1429 | /* Update other fields of driver FCF record */ |
| 1430 | fcf_rec->addr_mode = addr_mode; |
| 1431 | fcf_rec->vlan_id = vlan_id; |
| 1432 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1433 | __lpfc_update_fcf_record_pri(phba, |
| 1434 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1435 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1439 | * lpfc_register_fcf - Register the FCF with hba. |
| 1440 | * @phba: pointer to lpfc hba data structure. |
| 1441 | * |
| 1442 | * This routine issues a register fcfi mailbox command to register |
| 1443 | * the fcf with HBA. |
| 1444 | **/ |
| 1445 | static void |
| 1446 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1447 | { |
| 1448 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1449 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1450 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1451 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1452 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1453 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1454 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1455 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1456 | return; |
| 1457 | } |
| 1458 | |
| 1459 | /* The FCF is already registered, start discovery */ |
| 1460 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1461 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1462 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1463 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1464 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1465 | phba->hba_flag |= FCF_RR_INPROG; |
| 1466 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1467 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1468 | return; |
| 1469 | } |
| 1470 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1471 | return; |
| 1472 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1473 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1474 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1475 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1476 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1477 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1478 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1479 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1480 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1481 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1482 | |
| 1483 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1484 | fcf_mbxq->vport = phba->pport; |
| 1485 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1486 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1487 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1488 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1489 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1490 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1491 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1492 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1493 | |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1499 | * @phba: pointer to lpfc hba data structure. |
| 1500 | * @new_fcf_record: pointer to fcf record. |
| 1501 | * @boot_flag: Indicates if this record used by boot bios. |
| 1502 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1503 | * @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] | 1504 | * |
| 1505 | * This routine compare the fcf record with connect list obtained from the |
| 1506 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1507 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1508 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1509 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1510 | * used for this FCF when the function returns. |
| 1511 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1512 | * 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] | 1513 | * 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] | 1514 | **/ |
| 1515 | static int |
| 1516 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1517 | struct fcf_record *new_fcf_record, |
| 1518 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1519 | uint16_t *vlan_id) |
| 1520 | { |
| 1521 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1522 | int i, j, fcf_vlan_id = 0; |
| 1523 | |
| 1524 | /* Find the lowest VLAN id in the FCF record */ |
| 1525 | for (i = 0; i < 512; i++) { |
| 1526 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1527 | fcf_vlan_id = i * 8; |
| 1528 | j = 0; |
| 1529 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1530 | j++; |
| 1531 | fcf_vlan_id++; |
| 1532 | } |
| 1533 | break; |
| 1534 | } |
| 1535 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1536 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1537 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1538 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1539 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1540 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1541 | return 0; |
| 1542 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1543 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1544 | *boot_flag = 0; |
| 1545 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1546 | new_fcf_record); |
| 1547 | if (phba->valid_vlan) |
| 1548 | *vlan_id = phba->vlan_id; |
| 1549 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1550 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1551 | return 1; |
| 1552 | } |
| 1553 | |
| 1554 | /* |
| 1555 | * If there are no FCF connection table entry, driver connect to all |
| 1556 | * FCFs. |
| 1557 | */ |
| 1558 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1559 | *boot_flag = 0; |
| 1560 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1561 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1562 | |
| 1563 | /* |
| 1564 | * When there are no FCF connect entries, use driver's default |
| 1565 | * addressing mode - FPMA. |
| 1566 | */ |
| 1567 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1568 | *addr_mode = LPFC_FCF_FPMA; |
| 1569 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1570 | /* If FCF record report a vlan id use that vlan id */ |
| 1571 | if (fcf_vlan_id) |
| 1572 | *vlan_id = fcf_vlan_id; |
| 1573 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1574 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
| 1577 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1578 | list_for_each_entry(conn_entry, |
| 1579 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1580 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1581 | continue; |
| 1582 | |
| 1583 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1584 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1585 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1586 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1587 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1588 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1589 | new_fcf_record)) |
| 1590 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1591 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1592 | /* |
| 1593 | * If the vlan bit map does not have the bit set for the |
| 1594 | * vlan id to be used, then it is not a match. |
| 1595 | */ |
| 1596 | if (!(new_fcf_record->vlan_bitmap |
| 1597 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1598 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1599 | continue; |
| 1600 | } |
| 1601 | |
| 1602 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1603 | * If connection record does not support any addressing mode, |
| 1604 | * skip the FCF record. |
| 1605 | */ |
| 1606 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1607 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1608 | continue; |
| 1609 | |
| 1610 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1611 | * Check if the connection record specifies a required |
| 1612 | * addressing mode. |
| 1613 | */ |
| 1614 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1615 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1616 | |
| 1617 | /* |
| 1618 | * If SPMA required but FCF not support this continue. |
| 1619 | */ |
| 1620 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1621 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1622 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1623 | continue; |
| 1624 | |
| 1625 | /* |
| 1626 | * If FPMA required but FCF not support this continue. |
| 1627 | */ |
| 1628 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1629 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1630 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1631 | continue; |
| 1632 | } |
| 1633 | |
| 1634 | /* |
| 1635 | * This fcf record matches filtering criteria. |
| 1636 | */ |
| 1637 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1638 | *boot_flag = 1; |
| 1639 | else |
| 1640 | *boot_flag = 0; |
| 1641 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1642 | /* |
| 1643 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1644 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1645 | * by FCF, allow fabric to pick the addressing mode. |
| 1646 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1647 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1648 | new_fcf_record); |
| 1649 | /* |
| 1650 | * If the user specified a required address mode, assign that |
| 1651 | * address mode |
| 1652 | */ |
| 1653 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1654 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1655 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1656 | FCFCNCT_AM_SPMA) ? |
| 1657 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1658 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1659 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1660 | * addr mode only if FCF support the addr_mode. |
| 1661 | */ |
| 1662 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1663 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1664 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1665 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1666 | *addr_mode = LPFC_FCF_SPMA; |
| 1667 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1668 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1669 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1670 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1671 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1672 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1673 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1674 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1675 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1676 | /* |
| 1677 | * If no vlan id is specified in connect list, use the vlan id |
| 1678 | * in the FCF record |
| 1679 | */ |
| 1680 | else if (fcf_vlan_id) |
| 1681 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1682 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1683 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1684 | |
| 1685 | return 1; |
| 1686 | } |
| 1687 | |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
| 1691 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1692 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1693 | * @phba: pointer to lpfc hba data structure. |
| 1694 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1695 | * |
| 1696 | * This function check if there is any fcoe event pending while driver |
| 1697 | * scan FCF entries. If there is any pending event, it will restart the |
| 1698 | * FCF saning and return 1 else return 0. |
| 1699 | */ |
| 1700 | int |
| 1701 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1702 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1703 | /* |
| 1704 | * If the Link is up and no FCoE events while in the |
| 1705 | * FCF discovery, no need to restart FCF discovery. |
| 1706 | */ |
| 1707 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1708 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1709 | return 0; |
| 1710 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1711 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1712 | "2768 Pending link or FCF event during current " |
| 1713 | "handling of the previous event: link_state:x%x, " |
| 1714 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1715 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1716 | phba->fcoe_eventtag); |
| 1717 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1718 | spin_lock_irq(&phba->hbalock); |
| 1719 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1720 | spin_unlock_irq(&phba->hbalock); |
| 1721 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1722 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1723 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1724 | "2780 Restart FCF table scan due to " |
| 1725 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1726 | "evt_tag_current:x%x\n", |
| 1727 | phba->fcoe_eventtag_at_fcf_scan, |
| 1728 | phba->fcoe_eventtag); |
| 1729 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1730 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1731 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1732 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1733 | * flag |
| 1734 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1735 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1736 | "2833 Stop FCF discovery process due to link " |
| 1737 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1738 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1739 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1740 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1741 | spin_unlock_irq(&phba->hbalock); |
| 1742 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1743 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1744 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1745 | if (unreg_fcf) { |
| 1746 | spin_lock_irq(&phba->hbalock); |
| 1747 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1748 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1749 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1750 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1751 | return 1; |
| 1752 | } |
| 1753 | |
| 1754 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1755 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1756 | * @phba: pointer to lpfc hba data structure. |
| 1757 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1758 | * |
| 1759 | * This function makes an running random selection decision on FCF record to |
| 1760 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1761 | * probability. To perform integer manunipulation of random numbers with |
| 1762 | * 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] | 1763 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1764 | * |
| 1765 | * Returns true when outcome is for the newly read FCF record should be |
| 1766 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1767 | * chosen FCF record. |
| 1768 | **/ |
| 1769 | static bool |
| 1770 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1771 | { |
| 1772 | uint32_t rand_num; |
| 1773 | |
| 1774 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1775 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1776 | |
| 1777 | /* Decision with probability 1/fcf_cnt */ |
| 1778 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1779 | return true; |
| 1780 | else |
| 1781 | return false; |
| 1782 | } |
| 1783 | |
| 1784 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1785 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1786 | * @phba: pointer to lpfc hba data structure. |
| 1787 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1788 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1789 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1790 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1791 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1792 | * SGE parsing, and endianness swapping. |
| 1793 | * |
| 1794 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1795 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1796 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1797 | static struct fcf_record * |
| 1798 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1799 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1800 | { |
| 1801 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1802 | struct lpfc_mbx_sge sge; |
| 1803 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1804 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1805 | union lpfc_sli4_cfg_shdr *shdr; |
| 1806 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1807 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1808 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1809 | * routine only uses a single SGE. |
| 1810 | */ |
| 1811 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1812 | if (unlikely(!mboxq->sge_array)) { |
| 1813 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1814 | "2524 Failed to get the non-embedded SGE " |
| 1815 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1816 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1817 | } |
| 1818 | virt_addr = mboxq->sge_array->addr[0]; |
| 1819 | |
| 1820 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1821 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1822 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1823 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1824 | 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] | 1825 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1826 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1827 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1828 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1829 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1830 | "2726 READ_FCF_RECORD Indicates empty " |
| 1831 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1832 | else |
| 1833 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1834 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1835 | "with status x%x add_status x%x, " |
| 1836 | "mbx\n", shdr_status, shdr_add_status); |
| 1837 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1838 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1839 | |
| 1840 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1841 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1842 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1843 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1844 | *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] | 1845 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1846 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1847 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1848 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1849 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1850 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1851 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1852 | return new_fcf_record; |
| 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1857 | * @phba: pointer to lpfc hba data structure. |
| 1858 | * @fcf_record: pointer to the fcf record. |
| 1859 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1860 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1861 | * |
| 1862 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1863 | * enabled. |
| 1864 | **/ |
| 1865 | static void |
| 1866 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1867 | struct fcf_record *fcf_record, |
| 1868 | uint16_t vlan_id, |
| 1869 | uint16_t next_fcf_index) |
| 1870 | { |
| 1871 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1872 | "2764 READ_FCF_RECORD:\n" |
| 1873 | "\tFCF_Index : x%x\n" |
| 1874 | "\tFCF_Avail : x%x\n" |
| 1875 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1876 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1877 | "\tFIP_Priority : x%x\n" |
| 1878 | "\tMAC_Provider : x%x\n" |
| 1879 | "\tLowest VLANID : x%x\n" |
| 1880 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1881 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1882 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1883 | "\tNext_FCF_Index: x%x\n", |
| 1884 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1885 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1886 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1887 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1888 | fcf_record->fip_priority, |
| 1889 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1890 | vlan_id, |
| 1891 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1892 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1893 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1894 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1895 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1896 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1897 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1898 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1899 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1900 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1901 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1902 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1903 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1904 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1905 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1906 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1907 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1908 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1909 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1910 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1911 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1912 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1913 | next_fcf_index); |
| 1914 | } |
| 1915 | |
| 1916 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1917 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1918 | * @phba: pointer to lpfc hba data structure. |
| 1919 | * @fcf_rec: pointer to an existing FCF record. |
| 1920 | * @new_fcf_record: pointer to a new FCF record. |
| 1921 | * @new_vlan_id: vlan id from the new FCF record. |
| 1922 | * |
| 1923 | * This function performs matching test of a new FCF record against an existing |
| 1924 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1925 | * will not be used as part of the FCF record matching criteria. |
| 1926 | * |
| 1927 | * Returns true if all the fields matching, otherwise returns false. |
| 1928 | */ |
| 1929 | static bool |
| 1930 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1931 | struct lpfc_fcf_rec *fcf_rec, |
| 1932 | struct fcf_record *new_fcf_record, |
| 1933 | uint16_t new_vlan_id) |
| 1934 | { |
| 1935 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1936 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1937 | return false; |
| 1938 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1939 | return false; |
| 1940 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1941 | return false; |
| 1942 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1943 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1944 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1945 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1946 | return true; |
| 1947 | } |
| 1948 | |
| 1949 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1950 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1951 | * @vport: Pointer to vport object. |
| 1952 | * @fcf_index: index to next fcf. |
| 1953 | * |
| 1954 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1955 | * When this function is invoked, there will be a current fcf registered |
| 1956 | * for flogi. |
| 1957 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1958 | * 1 for stop flogi on currently registered fcf; |
| 1959 | */ |
| 1960 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1961 | { |
| 1962 | struct lpfc_hba *phba = vport->phba; |
| 1963 | int rc; |
| 1964 | |
| 1965 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1966 | spin_lock_irq(&phba->hbalock); |
| 1967 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1968 | spin_unlock_irq(&phba->hbalock); |
| 1969 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1970 | "2872 Devloss tmo with no eligible " |
| 1971 | "FCF, unregister in-use FCF (x%x) " |
| 1972 | "and rescan FCF table\n", |
| 1973 | phba->fcf.current_rec.fcf_indx); |
| 1974 | lpfc_unregister_fcf_rescan(phba); |
| 1975 | goto stop_flogi_current_fcf; |
| 1976 | } |
| 1977 | /* Mark the end to FLOGI roundrobin failover */ |
| 1978 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1979 | /* Allow action to new fcf asynchronous event */ |
| 1980 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1981 | spin_unlock_irq(&phba->hbalock); |
| 1982 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1983 | "2865 No FCF available, stop roundrobin FCF " |
| 1984 | "failover and change port state:x%x/x%x\n", |
| 1985 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1986 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1987 | goto stop_flogi_current_fcf; |
| 1988 | } else { |
| 1989 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1990 | "2794 Try FLOGI roundrobin FCF failover to " |
| 1991 | "(x%x)\n", fcf_index); |
| 1992 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 1993 | if (rc) |
| 1994 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 1995 | "2761 FLOGI roundrobin FCF failover " |
| 1996 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 1997 | rc, phba->fcf.current_rec.fcf_indx); |
| 1998 | else |
| 1999 | goto stop_flogi_current_fcf; |
| 2000 | } |
| 2001 | return 0; |
| 2002 | |
| 2003 | stop_flogi_current_fcf: |
| 2004 | lpfc_can_disctmo(vport); |
| 2005 | return 1; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2009 | * lpfc_sli4_fcf_pri_list_del |
| 2010 | * @phba: pointer to lpfc hba data structure. |
| 2011 | * @fcf_index the index of the fcf record to delete |
| 2012 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2013 | * If it is one the list then it is removed from the list, and the flag |
| 2014 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2015 | * record from the list. |
| 2016 | **/ |
| 2017 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2018 | uint16_t fcf_index) |
| 2019 | { |
| 2020 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2021 | |
| 2022 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2023 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2024 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2025 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2026 | new_fcf_pri->fcf_rec.flag); |
| 2027 | spin_lock_irq(&phba->hbalock); |
| 2028 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2029 | if (phba->fcf.current_rec.priority == |
| 2030 | new_fcf_pri->fcf_rec.priority) |
| 2031 | phba->fcf.eligible_fcf_cnt--; |
| 2032 | list_del_init(&new_fcf_pri->list); |
| 2033 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2034 | } |
| 2035 | spin_unlock_irq(&phba->hbalock); |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * lpfc_sli4_set_fcf_flogi_fail |
| 2040 | * @phba: pointer to lpfc hba data structure. |
| 2041 | * @fcf_index the index of the fcf record to update |
| 2042 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2043 | * flag so the the round robin slection for the particular priority level |
| 2044 | * will try a different fcf record that does not have this bit set. |
| 2045 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2046 | * adding it to the priority list. |
| 2047 | **/ |
| 2048 | void |
| 2049 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2050 | { |
| 2051 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2052 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2053 | spin_lock_irq(&phba->hbalock); |
| 2054 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2055 | spin_unlock_irq(&phba->hbalock); |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * lpfc_sli4_fcf_pri_list_add |
| 2060 | * @phba: pointer to lpfc hba data structure. |
| 2061 | * @fcf_index the index of the fcf record to add |
| 2062 | * This routine checks the priority of the fcf_index to be added. |
| 2063 | * If it is a lower priority than the current head of the fcf_pri list |
| 2064 | * then it is added to the list in the right order. |
| 2065 | * If it is the same priority as the current head of the list then it |
| 2066 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2067 | * If the fcf_index to be added is of a higher priority than the current |
| 2068 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2069 | * rr_bmask and it is added to the head of the list. |
| 2070 | * returns: |
| 2071 | * 0=success 1=failure |
| 2072 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2073 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2074 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2075 | struct fcf_record *new_fcf_record) |
| 2076 | { |
| 2077 | uint16_t current_fcf_pri; |
| 2078 | uint16_t last_index; |
| 2079 | struct lpfc_fcf_pri *fcf_pri; |
| 2080 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2081 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2082 | int ret; |
| 2083 | |
| 2084 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2085 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2086 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2087 | fcf_index, new_fcf_record->fip_priority, |
| 2088 | new_fcf_pri->fcf_rec.flag); |
| 2089 | spin_lock_irq(&phba->hbalock); |
| 2090 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2091 | list_del_init(&new_fcf_pri->list); |
| 2092 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2093 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2094 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2095 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2096 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2097 | new_fcf_pri->fcf_rec.fcf_index); |
| 2098 | goto out; |
| 2099 | } |
| 2100 | |
| 2101 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2102 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2103 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2104 | ret = 0; /* Empty rr list */ |
| 2105 | goto out; |
| 2106 | } |
| 2107 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2108 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2109 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2110 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2111 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2112 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2113 | /* fcfs_at_this_priority_level = 1; */ |
| 2114 | phba->fcf.eligible_fcf_cnt = 1; |
| 2115 | } else |
| 2116 | /* fcfs_at_this_priority_level++; */ |
| 2117 | phba->fcf.eligible_fcf_cnt++; |
| 2118 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2119 | new_fcf_pri->fcf_rec.fcf_index); |
| 2120 | goto out; |
| 2121 | } |
| 2122 | |
| 2123 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2124 | &phba->fcf.fcf_pri_list, list) { |
| 2125 | if (new_fcf_pri->fcf_rec.priority <= |
| 2126 | fcf_pri->fcf_rec.priority) { |
| 2127 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2128 | list_add(&new_fcf_pri->list, |
| 2129 | &phba->fcf.fcf_pri_list); |
| 2130 | else |
| 2131 | list_add(&new_fcf_pri->list, |
| 2132 | &((struct lpfc_fcf_pri *) |
| 2133 | fcf_pri->list.prev)->list); |
| 2134 | ret = 0; |
| 2135 | goto out; |
| 2136 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2137 | || new_fcf_pri->fcf_rec.priority < |
| 2138 | next_fcf_pri->fcf_rec.priority) { |
| 2139 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2140 | ret = 0; |
| 2141 | goto out; |
| 2142 | } |
| 2143 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2144 | continue; |
| 2145 | |
| 2146 | } |
| 2147 | ret = 1; |
| 2148 | out: |
| 2149 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2150 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2151 | spin_unlock_irq(&phba->hbalock); |
| 2152 | return ret; |
| 2153 | } |
| 2154 | |
| 2155 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2156 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2157 | * @phba: pointer to lpfc hba data structure. |
| 2158 | * @mboxq: pointer to mailbox object. |
| 2159 | * |
| 2160 | * This function iterates through all the fcf records available in |
| 2161 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2162 | * the FCF for discovery it registers the FCF record and kicks start |
| 2163 | * discovery. |
| 2164 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2165 | * use an FCF record which matches fabric name and mac address of the |
| 2166 | * currently used FCF record. |
| 2167 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2168 | * used by BOOT_BIOS. |
| 2169 | */ |
| 2170 | void |
| 2171 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2172 | { |
| 2173 | struct fcf_record *new_fcf_record; |
| 2174 | uint32_t boot_flag, addr_mode; |
| 2175 | uint16_t fcf_index, next_fcf_index; |
| 2176 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2177 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2178 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2179 | int rc; |
| 2180 | |
| 2181 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2182 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2183 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2184 | return; |
| 2185 | } |
| 2186 | |
| 2187 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2188 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2189 | &next_fcf_index); |
| 2190 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2191 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2192 | "2765 Mailbox command READ_FCF_RECORD " |
| 2193 | "failed to retrieve a FCF record.\n"); |
| 2194 | /* Let next new FCF event trigger fast failover */ |
| 2195 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2196 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2197 | spin_unlock_irq(&phba->hbalock); |
| 2198 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
| 2202 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2203 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2204 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2205 | |
| 2206 | /* Log the FCF record information if turned on */ |
| 2207 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2208 | next_fcf_index); |
| 2209 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2210 | /* |
| 2211 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2212 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2213 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2214 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2215 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2216 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2217 | bf_get(lpfc_fcf_record_fcf_index, |
| 2218 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2219 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2220 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2221 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2222 | bf_get(lpfc_fcf_record_fcf_index, |
| 2223 | new_fcf_record), |
| 2224 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2225 | new_fcf_record), |
| 2226 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2227 | new_fcf_record), |
| 2228 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2229 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2230 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2231 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2232 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2233 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2234 | phba->fcf.current_rec.fcf_indx) { |
| 2235 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2236 | "2862 FCF (x%x) matches property " |
| 2237 | "of in-use FCF (x%x)\n", |
| 2238 | bf_get(lpfc_fcf_record_fcf_index, |
| 2239 | new_fcf_record), |
| 2240 | phba->fcf.current_rec.fcf_indx); |
| 2241 | goto read_next_fcf; |
| 2242 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2243 | /* |
| 2244 | * In case the current in-use FCF record becomes |
| 2245 | * invalid/unavailable during FCF discovery that |
| 2246 | * was not triggered by fast FCF failover process, |
| 2247 | * treat it as fast FCF failover. |
| 2248 | */ |
| 2249 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2250 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2251 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2252 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2253 | "(x%x), enter FCF failover " |
| 2254 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2255 | phba->fcf.current_rec.fcf_indx); |
| 2256 | spin_lock_irq(&phba->hbalock); |
| 2257 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2258 | spin_unlock_irq(&phba->hbalock); |
| 2259 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2260 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2261 | LPFC_FCOE_FCF_GET_FIRST); |
| 2262 | return; |
| 2263 | } |
| 2264 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2265 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2266 | } else { |
| 2267 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2268 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2269 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2270 | if (rc) |
| 2271 | goto read_next_fcf; |
| 2272 | } |
| 2273 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2274 | /* |
| 2275 | * 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] | 2276 | * FCF record for the discovery. The condition that a rescan |
| 2277 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2278 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2279 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2280 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2281 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2282 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2283 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2284 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2285 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2286 | phba->fcf.current_rec.fcf_indx) { |
| 2287 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2288 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2289 | /* Stop FCF redisc wait timer */ |
| 2290 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2291 | phba); |
| 2292 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2293 | /* Fast failover, mark completed */ |
| 2294 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2295 | spin_unlock_irq(&phba->hbalock); |
| 2296 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2297 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2298 | "FCF (x%x), port_state:x%x, " |
| 2299 | "fc_flag:x%x\n", |
| 2300 | phba->fcf.current_rec.fcf_indx, |
| 2301 | phba->pport->port_state, |
| 2302 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2303 | goto out; |
| 2304 | } else |
| 2305 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2306 | "2863 New FCF (x%x) matches " |
| 2307 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2308 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2309 | new_fcf_record), |
| 2310 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2311 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2312 | /* |
| 2313 | * Read next FCF record from HBA searching for the matching |
| 2314 | * with in-use record only if not during the fast failover |
| 2315 | * period. In case of fast failover period, it shall try to |
| 2316 | * determine whether the FCF record just read should be the |
| 2317 | * next candidate. |
| 2318 | */ |
| 2319 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2320 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2321 | goto read_next_fcf; |
| 2322 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2323 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2324 | /* |
| 2325 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2326 | * period; otherwise, update on current FCF record. |
| 2327 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2328 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2329 | fcf_rec = &phba->fcf.failover_rec; |
| 2330 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2331 | fcf_rec = &phba->fcf.current_rec; |
| 2332 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2333 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2334 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2335 | * If the driver FCF record does not have boot flag |
| 2336 | * set and new hba fcf record has boot flag set, use |
| 2337 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2338 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2339 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2340 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2341 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2342 | "2837 Update current FCF record " |
| 2343 | "(x%x) with new FCF record (x%x)\n", |
| 2344 | fcf_rec->fcf_indx, |
| 2345 | bf_get(lpfc_fcf_record_fcf_index, |
| 2346 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2347 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2348 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2349 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2350 | goto read_next_fcf; |
| 2351 | } |
| 2352 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2353 | * If the driver FCF record has boot flag set and the |
| 2354 | * new hba FCF record does not have boot flag, read |
| 2355 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2356 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2357 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2358 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2359 | goto read_next_fcf; |
| 2360 | } |
| 2361 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2362 | * If the new hba FCF record has lower priority value |
| 2363 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2364 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2365 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2366 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2367 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2368 | "2838 Update current FCF record " |
| 2369 | "(x%x) with new FCF record (x%x)\n", |
| 2370 | fcf_rec->fcf_indx, |
| 2371 | bf_get(lpfc_fcf_record_fcf_index, |
| 2372 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2373 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2374 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2375 | /* Reset running random FCF selection count */ |
| 2376 | phba->fcf.eligible_fcf_cnt = 1; |
| 2377 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2378 | /* Update running random FCF selection count */ |
| 2379 | phba->fcf.eligible_fcf_cnt++; |
| 2380 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2381 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2382 | if (select_new_fcf) { |
| 2383 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2384 | "2839 Update current FCF record " |
| 2385 | "(x%x) with new FCF record (x%x)\n", |
| 2386 | fcf_rec->fcf_indx, |
| 2387 | bf_get(lpfc_fcf_record_fcf_index, |
| 2388 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2389 | /* Choose the new FCF by random selection */ |
| 2390 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2391 | new_fcf_record, |
| 2392 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2393 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2394 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2395 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2396 | goto read_next_fcf; |
| 2397 | } |
| 2398 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2399 | * This is the first suitable FCF record, choose this record for |
| 2400 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2401 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2402 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2403 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2404 | "2840 Update initial FCF candidate " |
| 2405 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2406 | bf_get(lpfc_fcf_record_fcf_index, |
| 2407 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2408 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2409 | addr_mode, vlan_id, (boot_flag ? |
| 2410 | BOOT_ENABLE : 0)); |
| 2411 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2412 | /* Setup initial running random FCF selection count */ |
| 2413 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2414 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2415 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2416 | goto read_next_fcf; |
| 2417 | |
| 2418 | read_next_fcf: |
| 2419 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2420 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2421 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2422 | /* |
| 2423 | * Case of FCF fast failover scan |
| 2424 | */ |
| 2425 | |
| 2426 | /* |
| 2427 | * It has not found any suitable FCF record, cancel |
| 2428 | * FCF scan inprogress, and do nothing |
| 2429 | */ |
| 2430 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2431 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2432 | "2782 No suitable FCF found: " |
| 2433 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2434 | phba->fcoe_eventtag_at_fcf_scan, |
| 2435 | bf_get(lpfc_fcf_record_fcf_index, |
| 2436 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2437 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2438 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2439 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2440 | spin_unlock_irq(&phba->hbalock); |
| 2441 | /* Unregister in-use FCF and rescan */ |
| 2442 | lpfc_printf_log(phba, KERN_INFO, |
| 2443 | LOG_FIP, |
| 2444 | "2864 On devloss tmo " |
| 2445 | "unreg in-use FCF and " |
| 2446 | "rescan FCF table\n"); |
| 2447 | lpfc_unregister_fcf_rescan(phba); |
| 2448 | return; |
| 2449 | } |
| 2450 | /* |
| 2451 | * Let next new FCF event trigger fast failover |
| 2452 | */ |
| 2453 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2454 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2455 | return; |
| 2456 | } |
| 2457 | /* |
| 2458 | * It has found a suitable FCF record that is not |
| 2459 | * the same as in-use FCF record, unregister the |
| 2460 | * in-use FCF record, replace the in-use FCF record |
| 2461 | * with the new FCF record, mark FCF fast failover |
| 2462 | * completed, and then start register the new FCF |
| 2463 | * record. |
| 2464 | */ |
| 2465 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2466 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2467 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2468 | |
| 2469 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2470 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2471 | "2842 Replace in-use FCF (x%x) " |
| 2472 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2473 | phba->fcf.current_rec.fcf_indx, |
| 2474 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2475 | memcpy(&phba->fcf.current_rec, |
| 2476 | &phba->fcf.failover_rec, |
| 2477 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2478 | /* |
| 2479 | * Mark the fast FCF failover rediscovery completed |
| 2480 | * and the start of the first round of the roundrobin |
| 2481 | * FCF failover. |
| 2482 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2483 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2484 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2485 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2486 | /* Register to the new FCF record */ |
| 2487 | lpfc_register_fcf(phba); |
| 2488 | } else { |
| 2489 | /* |
| 2490 | * In case of transaction period to fast FCF failover, |
| 2491 | * do nothing when search to the end of the FCF table. |
| 2492 | */ |
| 2493 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2494 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2495 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2496 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2497 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2498 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2499 | /* |
| 2500 | * In case the current in-use FCF record no |
| 2501 | * longer existed during FCF discovery that |
| 2502 | * was not triggered by fast FCF failover |
| 2503 | * process, treat it as fast FCF failover. |
| 2504 | */ |
| 2505 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2506 | "2841 In-use FCF record (x%x) " |
| 2507 | "not reported, entering fast " |
| 2508 | "FCF failover mode scanning.\n", |
| 2509 | phba->fcf.current_rec.fcf_indx); |
| 2510 | spin_lock_irq(&phba->hbalock); |
| 2511 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2512 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2513 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2514 | LPFC_FCOE_FCF_GET_FIRST); |
| 2515 | return; |
| 2516 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2517 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2518 | lpfc_register_fcf(phba); |
| 2519 | } |
| 2520 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2521 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2522 | return; |
| 2523 | |
| 2524 | out: |
| 2525 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2526 | lpfc_register_fcf(phba); |
| 2527 | |
| 2528 | return; |
| 2529 | } |
| 2530 | |
| 2531 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2532 | * 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] | 2533 | * @phba: pointer to lpfc hba data structure. |
| 2534 | * @mboxq: pointer to mailbox object. |
| 2535 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2536 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2537 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2538 | * performing the failover. If the FCF read back is not valid/available, it |
| 2539 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2540 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2541 | * newly read FCF record to the failover FCF record, unregister currently |
| 2542 | * registered FCF record, copy the failover FCF record to the current |
| 2543 | * FCF record, and then register the current FCF record before proceeding |
| 2544 | * to trying FLOGI on the new failover FCF. |
| 2545 | */ |
| 2546 | void |
| 2547 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2548 | { |
| 2549 | struct fcf_record *new_fcf_record; |
| 2550 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2551 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2552 | uint16_t current_fcf_index; |
| 2553 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2554 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2555 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2556 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2557 | if (phba->link_state < LPFC_LINK_UP) { |
| 2558 | spin_lock_irq(&phba->hbalock); |
| 2559 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2560 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2561 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2562 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2566 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2567 | &next_fcf_index); |
| 2568 | if (!new_fcf_record) { |
| 2569 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2570 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2571 | "failed to retrieve a FCF record. " |
| 2572 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2573 | phba->fcf.fcf_flag); |
| 2574 | lpfc_unregister_fcf_rescan(phba); |
| 2575 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2579 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2580 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2581 | |
| 2582 | /* Log the FCF record information if turned on */ |
| 2583 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2584 | next_fcf_index); |
| 2585 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2586 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2587 | if (!rc) { |
| 2588 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2589 | "2848 Remove ineligible FCF (x%x) from " |
| 2590 | "from roundrobin bmask\n", fcf_index); |
| 2591 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2592 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2593 | /* Perform next round of roundrobin FCF failover */ |
| 2594 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2595 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2596 | if (rc) |
| 2597 | goto out; |
| 2598 | goto error_out; |
| 2599 | } |
| 2600 | |
| 2601 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2602 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2603 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2604 | "FCF (x%x) back to FCF (x%x)\n", |
| 2605 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2606 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2607 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2608 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2609 | goto out; |
| 2610 | } |
| 2611 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2612 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2613 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2614 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2615 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2616 | spin_lock_irq(&phba->hbalock); |
| 2617 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2618 | new_fcf_record, addr_mode, vlan_id, |
| 2619 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2620 | spin_unlock_irq(&phba->hbalock); |
| 2621 | |
| 2622 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2623 | |
| 2624 | /* Unregister the current in-use FCF record */ |
| 2625 | lpfc_unregister_fcf(phba); |
| 2626 | |
| 2627 | /* Replace in-use record with the new record */ |
| 2628 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2629 | sizeof(struct lpfc_fcf_rec)); |
| 2630 | |
| 2631 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2632 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2633 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2634 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2635 | error_out: |
| 2636 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2637 | out: |
| 2638 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | /** |
| 2642 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2643 | * @phba: pointer to lpfc hba data structure. |
| 2644 | * @mboxq: pointer to mailbox object. |
| 2645 | * |
| 2646 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2647 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2648 | * failover when a new FCF event happened. If the FCF read back is |
| 2649 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2650 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2651 | */ |
| 2652 | void |
| 2653 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2654 | { |
| 2655 | struct fcf_record *new_fcf_record; |
| 2656 | uint32_t boot_flag, addr_mode; |
| 2657 | uint16_t fcf_index, next_fcf_index; |
| 2658 | uint16_t vlan_id; |
| 2659 | int rc; |
| 2660 | |
| 2661 | /* If link state is not up, no need to proceed */ |
| 2662 | if (phba->link_state < LPFC_LINK_UP) |
| 2663 | goto out; |
| 2664 | |
| 2665 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2666 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2667 | goto out; |
| 2668 | |
| 2669 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2670 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2671 | &next_fcf_index); |
| 2672 | if (!new_fcf_record) { |
| 2673 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2674 | "2767 Mailbox command READ_FCF_RECORD " |
| 2675 | "failed to retrieve a FCF record.\n"); |
| 2676 | goto out; |
| 2677 | } |
| 2678 | |
| 2679 | /* Check the connection list for eligibility */ |
| 2680 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2681 | &addr_mode, &vlan_id); |
| 2682 | |
| 2683 | /* Log the FCF record information if turned on */ |
| 2684 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2685 | next_fcf_index); |
| 2686 | |
| 2687 | if (!rc) |
| 2688 | goto out; |
| 2689 | |
| 2690 | /* Update the eligible FCF record index bmask */ |
| 2691 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2692 | |
| 2693 | 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] | 2694 | |
| 2695 | out: |
| 2696 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2697 | } |
| 2698 | |
| 2699 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2700 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2701 | * @phba: pointer to lpfc hba data structure. |
| 2702 | * @mboxq: pointer to mailbox data structure. |
| 2703 | * |
| 2704 | * This function handles completion of init vfi mailbox command. |
| 2705 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2706 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2707 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2708 | { |
| 2709 | struct lpfc_vport *vport = mboxq->vport; |
| 2710 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2711 | /* |
| 2712 | * VFI not supported on interface type 0, just do the flogi |
| 2713 | * Also continue if the VFI is in use - just use the same one. |
| 2714 | */ |
| 2715 | if (mboxq->u.mb.mbxStatus && |
| 2716 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2717 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2718 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2719 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2720 | LOG_MBOX, |
| 2721 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2722 | mboxq->u.mb.mbxStatus); |
| 2723 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2724 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2725 | return; |
| 2726 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2727 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2728 | lpfc_initial_flogi(vport); |
| 2729 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2730 | return; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
| 2734 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2735 | * @vport: pointer to lpfc_vport data structure. |
| 2736 | * |
| 2737 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2738 | * VPI for the physical port. |
| 2739 | */ |
| 2740 | void |
| 2741 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2742 | { |
| 2743 | LPFC_MBOXQ_t *mboxq; |
| 2744 | int rc; |
| 2745 | struct lpfc_hba *phba = vport->phba; |
| 2746 | |
| 2747 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2748 | if (!mboxq) { |
| 2749 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2750 | LOG_MBOX, "2892 Failed to allocate " |
| 2751 | "init_vfi mailbox\n"); |
| 2752 | return; |
| 2753 | } |
| 2754 | lpfc_init_vfi(mboxq, vport); |
| 2755 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2756 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2757 | if (rc == MBX_NOT_FINISHED) { |
| 2758 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2759 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2760 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2765 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2766 | * @phba: pointer to lpfc hba data structure. |
| 2767 | * @mboxq: pointer to mailbox data structure. |
| 2768 | * |
| 2769 | * This function handles completion of init vpi mailbox command. |
| 2770 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2771 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2772 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2773 | { |
| 2774 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2775 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2776 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2777 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2778 | if (mboxq->u.mb.mbxStatus) { |
| 2779 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2780 | LOG_MBOX, |
| 2781 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2782 | mboxq->u.mb.mbxStatus); |
| 2783 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2784 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2785 | return; |
| 2786 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2787 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2788 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2789 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2790 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2791 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2792 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2793 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2794 | if (!ndlp) |
| 2795 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2796 | LOG_DISCOVERY, |
| 2797 | "2731 Cannot find fabric " |
| 2798 | "controller node\n"); |
| 2799 | else |
| 2800 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2801 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2802 | return; |
| 2803 | } |
| 2804 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2805 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2806 | lpfc_initial_fdisc(vport); |
| 2807 | else { |
| 2808 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2809 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2810 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2811 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2812 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2813 | return; |
| 2814 | } |
| 2815 | |
| 2816 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2817 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2818 | * @vport: pointer to lpfc_vport data structure. |
| 2819 | * |
| 2820 | * This function issue a init_vpi mailbox command to initialize |
| 2821 | * VPI for the vport. |
| 2822 | */ |
| 2823 | void |
| 2824 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2825 | { |
| 2826 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2827 | int rc, vpi; |
| 2828 | |
| 2829 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2830 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2831 | if (!vpi) { |
| 2832 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2833 | LOG_MBOX, |
| 2834 | "3303 Failed to obtain vport vpi\n"); |
| 2835 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2836 | return; |
| 2837 | } |
| 2838 | vport->vpi = vpi; |
| 2839 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2840 | |
| 2841 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2842 | if (!mboxq) { |
| 2843 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2844 | LOG_MBOX, "2607 Failed to allocate " |
| 2845 | "init_vpi mailbox\n"); |
| 2846 | return; |
| 2847 | } |
| 2848 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2849 | mboxq->vport = vport; |
| 2850 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2851 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2852 | if (rc == MBX_NOT_FINISHED) { |
| 2853 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2854 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2855 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2860 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2861 | * @phba: pointer to lpfc hba data structure. |
| 2862 | * |
| 2863 | * This function loops through the list of vports on the @phba and issues an |
| 2864 | * FDISC if possible. |
| 2865 | */ |
| 2866 | void |
| 2867 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2868 | { |
| 2869 | struct lpfc_vport **vports; |
| 2870 | int i; |
| 2871 | |
| 2872 | vports = lpfc_create_vport_work_array(phba); |
| 2873 | if (vports != NULL) { |
| 2874 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2875 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2876 | continue; |
| 2877 | /* There are no vpi for this vport */ |
| 2878 | if (vports[i]->vpi > phba->max_vpi) { |
| 2879 | lpfc_vport_set_state(vports[i], |
| 2880 | FC_VPORT_FAILED); |
| 2881 | continue; |
| 2882 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2883 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2884 | lpfc_vport_set_state(vports[i], |
| 2885 | FC_VPORT_LINKDOWN); |
| 2886 | continue; |
| 2887 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2888 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2889 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2890 | continue; |
| 2891 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2892 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2893 | lpfc_initial_fdisc(vports[i]); |
| 2894 | else { |
| 2895 | lpfc_vport_set_state(vports[i], |
| 2896 | FC_VPORT_NO_FABRIC_SUPP); |
| 2897 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2898 | LOG_ELS, |
| 2899 | "0259 No NPIV " |
| 2900 | "Fabric support\n"); |
| 2901 | } |
| 2902 | } |
| 2903 | } |
| 2904 | lpfc_destroy_vport_work_array(phba, vports); |
| 2905 | } |
| 2906 | |
| 2907 | void |
| 2908 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2909 | { |
| 2910 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2911 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2912 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2913 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2914 | /* |
| 2915 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2916 | * error (except VFI in use) and continue with the discovery. |
| 2917 | */ |
| 2918 | if (mboxq->u.mb.mbxStatus && |
| 2919 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2920 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2921 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2922 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2923 | "2018 REG_VFI mbxStatus error x%x " |
| 2924 | "HBA state x%x\n", |
| 2925 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2926 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2927 | /* FLOGI failed, use loop map to make discovery list */ |
| 2928 | lpfc_disc_list_loopmap(vport); |
| 2929 | /* Start discovery */ |
| 2930 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2931 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2932 | } |
| 2933 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2934 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2935 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2936 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2937 | /* If the VFI is already registered, there is nothing else to do |
| 2938 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2939 | * we should drop through to set the port state to ready. |
| 2940 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2941 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2942 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2943 | vport->fc_flag & FC_PT2PT)) |
| 2944 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2945 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2946 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2947 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2948 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2949 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2950 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2951 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2952 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2953 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2954 | /* In case SLI4 FC loopback test, we are ready */ |
| 2955 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2956 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2957 | phba->link_state = LPFC_HBA_READY; |
| 2958 | goto out_free_mem; |
| 2959 | } |
| 2960 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2962 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 2963 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 2964 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 2965 | vport->phba->alpa_map[0], |
| 2966 | phba->link_state, phba->fc_topology); |
| 2967 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2968 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2969 | /* |
| 2970 | * For private loop or for NPort pt2pt, |
| 2971 | * just start discovery and we are done. |
| 2972 | */ |
| 2973 | if ((vport->fc_flag & FC_PT2PT) || |
| 2974 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2975 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2976 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2977 | /* Use loop map to make discovery list */ |
| 2978 | lpfc_disc_list_loopmap(vport); |
| 2979 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2980 | if (vport->fc_flag & FC_PT2PT) |
| 2981 | vport->port_state = LPFC_VPORT_READY; |
| 2982 | else |
| 2983 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2984 | } else { |
| 2985 | lpfc_start_fdiscs(phba); |
| 2986 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2987 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2988 | } |
| 2989 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2990 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2991 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 2992 | if (dmabuf) { |
| 2993 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2994 | kfree(dmabuf); |
| 2995 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2996 | return; |
| 2997 | } |
| 2998 | |
| 2999 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3000 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3002 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3004 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3005 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3006 | struct serv_parm *sp = &vport->fc_sparam; |
| 3007 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | |
| 3009 | /* Check for error */ |
| 3010 | if (mb->mbxStatus) { |
| 3011 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3012 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3013 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3014 | "hba state x%x>\n", |
| 3015 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | goto out; |
| 3018 | } |
| 3019 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3020 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3022 | |
| 3023 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3024 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3025 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3026 | |
| 3027 | phba->fc_edtov = ed_tov; |
| 3028 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3029 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3030 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3031 | phba->fc_ratov = FF_DEF_RATOV; |
| 3032 | } |
| 3033 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3034 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3035 | 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] | 3036 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3037 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3038 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3039 | } |
| 3040 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3042 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3043 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3044 | return; |
| 3045 | |
| 3046 | out: |
| 3047 | pmb->context1 = NULL; |
| 3048 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3049 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3050 | lpfc_issue_clear_la(phba, vport); |
| 3051 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | return; |
| 3053 | } |
| 3054 | |
| 3055 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3056 | 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] | 3057 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3058 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3059 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3060 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3061 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3062 | struct lpfc_dmabuf *mp; |
| 3063 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3064 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3065 | uint32_t fc_flags = 0; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3066 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | spin_lock_irq(&phba->hbalock); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3068 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3069 | |
| 3070 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3071 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3072 | case LPFC_LINK_SPEED_1GHZ: |
| 3073 | case LPFC_LINK_SPEED_2GHZ: |
| 3074 | case LPFC_LINK_SPEED_4GHZ: |
| 3075 | case LPFC_LINK_SPEED_8GHZ: |
| 3076 | case LPFC_LINK_SPEED_10GHZ: |
| 3077 | case LPFC_LINK_SPEED_16GHZ: |
| 3078 | case LPFC_LINK_SPEED_32GHZ: |
| 3079 | break; |
| 3080 | default: |
| 3081 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3082 | break; |
| 3083 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | } |
| 3085 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3086 | if (phba->fc_topology && |
| 3087 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3088 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3089 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3090 | phba->fc_topology, |
| 3091 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3092 | phba->fc_topology_changed = 1; |
| 3093 | } |
| 3094 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3095 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3096 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3098 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3099 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3100 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3102 | /* if npiv is enabled and this adapter supports npiv log |
| 3103 | * a message that npiv is not supported in this topology |
| 3104 | */ |
| 3105 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3106 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3107 | "1309 Link Up Event npiv not supported in loop " |
| 3108 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3109 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3110 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3111 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3113 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3114 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3115 | |
| 3116 | if (i == 0) { |
| 3117 | phba->alpa_map[0] = 0; |
| 3118 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3119 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | int numalpa, j, k; |
| 3121 | union { |
| 3122 | uint8_t pamap[16]; |
| 3123 | struct { |
| 3124 | uint32_t wd1; |
| 3125 | uint32_t wd2; |
| 3126 | uint32_t wd3; |
| 3127 | uint32_t wd4; |
| 3128 | } pa; |
| 3129 | } un; |
| 3130 | numalpa = phba->alpa_map[0]; |
| 3131 | j = 0; |
| 3132 | while (j < numalpa) { |
| 3133 | memset(un.pamap, 0, 16); |
| 3134 | for (k = 1; j < numalpa; k++) { |
| 3135 | un.pamap[k - 1] = |
| 3136 | phba->alpa_map[j + 1]; |
| 3137 | j++; |
| 3138 | if (k == 16) |
| 3139 | break; |
| 3140 | } |
| 3141 | /* Link Up Event ALPA map */ |
| 3142 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3143 | KERN_WARNING, |
| 3144 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3145 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3146 | "ALPA map Data: x%x " |
| 3147 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3148 | un.pa.wd1, un.pa.wd2, |
| 3149 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | } |
| 3153 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3154 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3155 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3156 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3157 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3158 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3159 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3160 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3161 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3164 | if (fc_flags) { |
| 3165 | spin_lock_irq(shost->host_lock); |
| 3166 | vport->fc_flag |= fc_flags; |
| 3167 | spin_unlock_irq(shost->host_lock); |
| 3168 | } |
| 3169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3171 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3172 | if (!sparam_mbox) |
| 3173 | goto out; |
| 3174 | |
| 3175 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3176 | if (rc) { |
| 3177 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3178 | goto out; |
| 3179 | } |
| 3180 | sparam_mbox->vport = vport; |
| 3181 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3182 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3183 | if (rc == MBX_NOT_FINISHED) { |
| 3184 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3185 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3186 | kfree(mp); |
| 3187 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3188 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3189 | } |
| 3190 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3191 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3192 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3193 | if (!cfglink_mbox) |
| 3194 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3197 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3198 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3199 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3200 | if (rc == MBX_NOT_FINISHED) { |
| 3201 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3202 | goto out; |
| 3203 | } |
| 3204 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3205 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3206 | /* |
| 3207 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3208 | * is phase 1 implementation that support FCF index 0 and driver |
| 3209 | * defaults. |
| 3210 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3211 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3212 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3213 | GFP_KERNEL); |
| 3214 | if (unlikely(!fcf_record)) { |
| 3215 | lpfc_printf_log(phba, KERN_ERR, |
| 3216 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3217 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3218 | "fcf record\n"); |
| 3219 | rc = -ENODEV; |
| 3220 | goto out; |
| 3221 | } |
| 3222 | |
| 3223 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3224 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3225 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3226 | if (unlikely(rc)) { |
| 3227 | lpfc_printf_log(phba, KERN_ERR, |
| 3228 | LOG_MBOX | LOG_SLI, |
| 3229 | "2013 Could not manually add FCF " |
| 3230 | "record 0, status %d\n", rc); |
| 3231 | rc = -ENODEV; |
| 3232 | kfree(fcf_record); |
| 3233 | goto out; |
| 3234 | } |
| 3235 | kfree(fcf_record); |
| 3236 | } |
| 3237 | /* |
| 3238 | * The driver is expected to do FIP/FCF. Call the port |
| 3239 | * and get the FCF Table. |
| 3240 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3241 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3242 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3243 | spin_unlock_irq(&phba->hbalock); |
| 3244 | return; |
| 3245 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3246 | /* This is the initial FCF discovery scan */ |
| 3247 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3248 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3249 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3250 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3251 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3252 | LPFC_FCOE_FCF_GET_FIRST); |
| 3253 | if (rc) { |
| 3254 | spin_lock_irq(&phba->hbalock); |
| 3255 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3256 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3257 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3258 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3259 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3260 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3262 | |
| 3263 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | out: |
| 3265 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3266 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3267 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3268 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3269 | lpfc_issue_clear_la(phba, vport); |
| 3270 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3274 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3275 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | uint32_t control; |
| 3277 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3278 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3280 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3281 | control = readl(phba->HCregaddr); |
| 3282 | control |= HC_LAINT_ENA; |
| 3283 | writel(control, phba->HCregaddr); |
| 3284 | readl(phba->HCregaddr); /* flush */ |
| 3285 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3286 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3287 | } |
| 3288 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3289 | static void |
| 3290 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3291 | { |
| 3292 | lpfc_linkdown(phba); |
| 3293 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3294 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3295 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3296 | } |
| 3297 | |
| 3298 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3299 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3300 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3302 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3303 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | */ |
| 3305 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3306 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3308 | struct lpfc_vport *vport = pmb->vport; |
| 3309 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3310 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3311 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3312 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3314 | uint8_t attn_type; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3316 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3317 | pring = lpfc_phba_elsring(phba); |
| 3318 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3319 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | /* Check for error */ |
| 3321 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3322 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3323 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3324 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3327 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | } |
| 3329 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3330 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3331 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | |
| 3333 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3334 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3336 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3337 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3338 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3340 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3341 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3342 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3344 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | if (phba->fc_eventTag != 0) |
| 3346 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | |
| 3349 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3350 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3351 | spin_lock_irq(&phba->hbalock); |
| 3352 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3353 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3354 | else |
| 3355 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| 3356 | spin_unlock_irq(&phba->hbalock); |
| 3357 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3359 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3360 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3361 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3364 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3365 | "1306 Link Up Event in loop back mode " |
| 3366 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3367 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3368 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3369 | la), |
| 3370 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3371 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3372 | } else { |
| 3373 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3374 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3375 | "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] | 3376 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3377 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3378 | la), |
| 3379 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3380 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3381 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3382 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3383 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3384 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3385 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3386 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3387 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3389 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3390 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3391 | "1308 Link Down Event in loop back mode " |
| 3392 | "x%x received " |
| 3393 | "Data: x%x x%x x%x\n", |
| 3394 | la->eventTag, phba->fc_eventTag, |
| 3395 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3396 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3397 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3398 | "1313 Link Down UNEXP WWPN Event x%x received " |
| 3399 | "Data: x%x x%x x%x x%x x%x\n", |
| 3400 | la->eventTag, phba->fc_eventTag, |
| 3401 | phba->pport->port_state, vport->fc_flag, |
| 3402 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3403 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3404 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3405 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3406 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3407 | "Data: x%x x%x x%x x%x x%x\n", |
| 3408 | la->eventTag, phba->fc_eventTag, |
| 3409 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3410 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3411 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3412 | lpfc_mbx_issue_link_down(phba); |
| 3413 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3414 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3415 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3416 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3417 | phba->fc_stat.LinkDown++; |
| 3418 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3419 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3421 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3423 | lpfc_mbx_issue_link_down(phba); |
| 3424 | } else |
| 3425 | lpfc_enable_la(phba); |
| 3426 | |
| 3427 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3428 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3429 | "Data: x%x x%x x%x\n", |
| 3430 | la->eventTag, phba->fc_eventTag, |
| 3431 | phba->pport->port_state, vport->fc_flag); |
| 3432 | /* |
| 3433 | * The cmnd that triggered this will be waiting for this |
| 3434 | * signal. |
| 3435 | */ |
| 3436 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3437 | if (phba->wait_4_mlo_maint_flg) { |
| 3438 | phba->wait_4_mlo_maint_flg = 0; |
| 3439 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3440 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3441 | } |
| 3442 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3443 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3444 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3445 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3446 | lpfc_issue_clear_la(phba, vport); |
| 3447 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3448 | "1311 fa %d\n", |
| 3449 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | } |
| 3451 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3452 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3454 | kfree(mp); |
| 3455 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3456 | return; |
| 3457 | } |
| 3458 | |
| 3459 | /* |
| 3460 | * This routine handles processing a REG_LOGIN mailbox |
| 3461 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3462 | * as the completion routine when the command is |
| 3463 | * handed off to the SLI layer. |
| 3464 | */ |
| 3465 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3466 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3468 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3469 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3470 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3471 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3474 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3476 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3477 | "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 3478 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3479 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3480 | ndlp->nlp_usg_map, ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3481 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3482 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3483 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3484 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3485 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3486 | /* We rcvd a rscn after issuing this |
| 3487 | * mbox reg login, we may have cycled |
| 3488 | * back through the state and be |
| 3489 | * back at reg login state so this |
| 3490 | * mbox needs to be ignored becase |
| 3491 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3492 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3493 | */ |
| 3494 | spin_lock_irq(shost->host_lock); |
| 3495 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3496 | spin_unlock_irq(shost->host_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3497 | |
| 3498 | /* |
| 3499 | * We cannot leave the RPI registered because |
| 3500 | * if we go thru discovery again for this ndlp |
| 3501 | * a subsequent REG_RPI will fail. |
| 3502 | */ |
| 3503 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3504 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | /* Call state machine */ |
| 3508 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3511 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3512 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3513 | /* decrement the node reference count held for this callback |
| 3514 | * function. |
| 3515 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3516 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | |
| 3518 | return; |
| 3519 | } |
| 3520 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3521 | static void |
| 3522 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3523 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3524 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3525 | struct lpfc_vport *vport = pmb->vport; |
| 3526 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3527 | |
| 3528 | switch (mb->mbxStatus) { |
| 3529 | case 0x0011: |
| 3530 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3531 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3532 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3533 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3534 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3535 | /* If VPI is busy, reset the HBA */ |
| 3536 | case 0x9700: |
| 3537 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3538 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3539 | vport->vpi, mb->mbxStatus); |
| 3540 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3541 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3542 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3543 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3544 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3545 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3546 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3547 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3548 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3549 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3550 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3551 | /* |
| 3552 | * This shost reference might have been taken at the beginning of |
| 3553 | * lpfc_vport_delete() |
| 3554 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3555 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3556 | scsi_host_put(shost); |
| 3557 | } |
| 3558 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3559 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3560 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3561 | { |
| 3562 | struct lpfc_hba *phba = vport->phba; |
| 3563 | LPFC_MBOXQ_t *mbox; |
| 3564 | int rc; |
| 3565 | |
| 3566 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3567 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3568 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3569 | |
| 3570 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3571 | mbox->vport = vport; |
| 3572 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3573 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3574 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3575 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3576 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3577 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3578 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3579 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3580 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3581 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | static void |
| 3585 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3586 | { |
| 3587 | struct lpfc_vport *vport = pmb->vport; |
| 3588 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3589 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3590 | |
| 3591 | switch (mb->mbxStatus) { |
| 3592 | case 0x0011: |
| 3593 | case 0x9601: |
| 3594 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3595 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3596 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3597 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3598 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3599 | spin_lock_irq(shost->host_lock); |
| 3600 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3601 | spin_unlock_irq(shost->host_lock); |
| 3602 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3603 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3604 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3605 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3606 | if (phba->nvmet_support) |
| 3607 | lpfc_nvmet_update_targetport(phba); |
| 3608 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3609 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3610 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3611 | goto out; |
| 3612 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3613 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3614 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3615 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3616 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3617 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3618 | vport->num_disc_nodes = 0; |
| 3619 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3620 | if (vport->fc_npr_cnt) |
| 3621 | lpfc_els_disc_plogi(vport); |
| 3622 | |
| 3623 | if (!vport->num_disc_nodes) { |
| 3624 | spin_lock_irq(shost->host_lock); |
| 3625 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3626 | spin_unlock_irq(shost->host_lock); |
| 3627 | lpfc_can_disctmo(vport); |
| 3628 | } |
| 3629 | vport->port_state = LPFC_VPORT_READY; |
| 3630 | |
| 3631 | out: |
| 3632 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3633 | return; |
| 3634 | } |
| 3635 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3636 | /** |
| 3637 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3638 | * @phba: pointer to lpfc hba data structure. |
| 3639 | * |
| 3640 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3641 | * the list of static vports to be created. The function create vports |
| 3642 | * based on the information returned from the HBA. |
| 3643 | **/ |
| 3644 | void |
| 3645 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3646 | { |
| 3647 | LPFC_MBOXQ_t *pmb = NULL; |
| 3648 | MAILBOX_t *mb; |
| 3649 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3650 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3651 | struct fc_vport_identifiers vport_id; |
| 3652 | struct fc_vport *new_fc_vport; |
| 3653 | struct Scsi_Host *shost; |
| 3654 | struct lpfc_vport *vport; |
| 3655 | uint16_t offset = 0; |
| 3656 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3657 | struct lpfc_dmabuf *mp; |
| 3658 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3659 | |
| 3660 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3661 | if (!pmb) { |
| 3662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3663 | "0542 lpfc_create_static_vport failed to" |
| 3664 | " allocate mailbox memory\n"); |
| 3665 | return; |
| 3666 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3667 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3668 | mb = &pmb->u.mb; |
| 3669 | |
| 3670 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3671 | if (!vport_info) { |
| 3672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3673 | "0543 lpfc_create_static_vport failed to" |
| 3674 | " allocate vport_info\n"); |
| 3675 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3676 | return; |
| 3677 | } |
| 3678 | |
| 3679 | vport_buff = (uint8_t *) vport_info; |
| 3680 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3681 | /* free dma buffer from previous round */ |
| 3682 | if (pmb->context1) { |
| 3683 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3684 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3685 | kfree(mp); |
| 3686 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3687 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3688 | goto out; |
| 3689 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3690 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3691 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3692 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3693 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3694 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3695 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3696 | "0544 lpfc_create_static_vport failed to" |
| 3697 | " issue dump mailbox command ret 0x%x " |
| 3698 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3699 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3700 | goto out; |
| 3701 | } |
| 3702 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3703 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3704 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3705 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3706 | if (byte_count > sizeof(struct static_vport_info) - |
| 3707 | offset) |
| 3708 | byte_count = sizeof(struct static_vport_info) |
| 3709 | - offset; |
| 3710 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3711 | offset += byte_count; |
| 3712 | } else { |
| 3713 | if (mb->un.varDmp.word_cnt > |
| 3714 | sizeof(struct static_vport_info) - offset) |
| 3715 | mb->un.varDmp.word_cnt = |
| 3716 | sizeof(struct static_vport_info) |
| 3717 | - offset; |
| 3718 | byte_count = mb->un.varDmp.word_cnt; |
| 3719 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3720 | vport_buff + offset, |
| 3721 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3722 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3723 | offset += byte_count; |
| 3724 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3725 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3726 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3727 | offset < sizeof(struct static_vport_info)); |
| 3728 | |
| 3729 | |
| 3730 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3731 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3732 | != VPORT_INFO_REV)) { |
| 3733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3734 | "0545 lpfc_create_static_vport bad" |
| 3735 | " information header 0x%x 0x%x\n", |
| 3736 | le32_to_cpu(vport_info->signature), |
| 3737 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3738 | |
| 3739 | goto out; |
| 3740 | } |
| 3741 | |
| 3742 | shost = lpfc_shost_from_vport(phba->pport); |
| 3743 | |
| 3744 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3745 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3746 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3747 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3748 | if (!vport_id.port_name || !vport_id.node_name) |
| 3749 | continue; |
| 3750 | |
| 3751 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3752 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3753 | vport_id.disable = false; |
| 3754 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3755 | |
| 3756 | if (!new_fc_vport) { |
| 3757 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3758 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3759 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3760 | continue; |
| 3761 | } |
| 3762 | |
| 3763 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3764 | vport->vport_flag |= STATIC_VPORT; |
| 3765 | } |
| 3766 | |
| 3767 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3768 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3769 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3770 | if (pmb->context1) { |
| 3771 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3772 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3773 | kfree(mp); |
| 3774 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3775 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3776 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3777 | |
| 3778 | return; |
| 3779 | } |
| 3780 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | /* |
| 3782 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3783 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3784 | * as the completion routine when the command is |
| 3785 | * handed off to the SLI layer. |
| 3786 | */ |
| 3787 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3790 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3791 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3792 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3793 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3794 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3796 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3797 | pmb->context1 = NULL; |
| 3798 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3801 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3802 | "0258 Register Fabric login error: 0x%x\n", |
| 3803 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3805 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3806 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3808 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3809 | /* FLOGI failed, use loop map to make discovery list */ |
| 3810 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3812 | /* Start discovery */ |
| 3813 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3814 | /* Decrement the reference count to ndlp after the |
| 3815 | * reference to the ndlp are done. |
| 3816 | */ |
| 3817 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3818 | return; |
| 3819 | } |
| 3820 | |
| 3821 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3822 | /* Decrement the reference count to ndlp after the reference |
| 3823 | * to the ndlp are done. |
| 3824 | */ |
| 3825 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | return; |
| 3827 | } |
| 3828 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3829 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3830 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3831 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3836 | /* when physical port receive logo donot start |
| 3837 | * vport discovery */ |
| 3838 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3839 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3840 | else { |
| 3841 | shost = lpfc_shost_from_vport(vport); |
| 3842 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3843 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3844 | spin_unlock_irq(shost->host_lock); |
| 3845 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3846 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3850 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3851 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3852 | |
| 3853 | /* Drop the reference count from the mbox at the end after |
| 3854 | * all the current reference to the ndlp have been done. |
| 3855 | */ |
| 3856 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | return; |
| 3858 | } |
| 3859 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3860 | /* |
| 3861 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3862 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3863 | */ |
| 3864 | int |
| 3865 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3866 | { |
| 3867 | struct lpfc_hba *phba = vport->phba; |
| 3868 | |
| 3869 | /* Good status, issue CT Request to NameServer */ |
| 3870 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3871 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
| 3872 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3873 | /* Cannot issue NameServer FCP Query, so finish up |
| 3874 | * discovery |
| 3875 | */ |
| 3876 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3877 | "0604 %s FC TYPE %x %s\n", |
| 3878 | "Failed to issue GID_FT to ", |
| 3879 | FC_TYPE_FCP, |
| 3880 | "Finishing discovery."); |
| 3881 | return 0; |
| 3882 | } |
| 3883 | vport->gidft_inp++; |
| 3884 | } |
| 3885 | |
| 3886 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3887 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
| 3888 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 3889 | /* Cannot issue NameServer NVME Query, so finish up |
| 3890 | * discovery |
| 3891 | */ |
| 3892 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3893 | "0605 %s FC_TYPE %x %s %d\n", |
| 3894 | "Failed to issue GID_FT to ", |
| 3895 | FC_TYPE_NVME, |
| 3896 | "Finishing discovery: gidftinp ", |
| 3897 | vport->gidft_inp); |
| 3898 | if (vport->gidft_inp == 0) |
| 3899 | return 0; |
| 3900 | } else |
| 3901 | vport->gidft_inp++; |
| 3902 | } |
| 3903 | return vport->gidft_inp; |
| 3904 | } |
| 3905 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | /* |
| 3907 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3908 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3909 | * as the completion routine when the command is |
| 3910 | * handed off to the SLI layer. |
| 3911 | */ |
| 3912 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3915 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3916 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3917 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3918 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3920 | pmb->context1 = NULL; |
| 3921 | pmb->context2 = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3922 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3923 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3925 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3926 | "0260 Register NameServer error: 0x%x\n", |
| 3927 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3928 | |
| 3929 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3930 | /* decrement the node reference count held for this |
| 3931 | * callback function. |
| 3932 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3933 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3935 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3936 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3937 | |
| 3938 | /* If no other thread is using the ndlp, free it */ |
| 3939 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3941 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3942 | /* |
| 3943 | * RegLogin failed, use loop map to make discovery |
| 3944 | * list |
| 3945 | */ |
| 3946 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3947 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3948 | /* Start discovery */ |
| 3949 | lpfc_disc_start(vport); |
| 3950 | return; |
| 3951 | } |
| 3952 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | return; |
| 3954 | } |
| 3955 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3956 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3957 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3958 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3959 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3960 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3962 | "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", |
| 3963 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3964 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3965 | ndlp->nlp_usg_map, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3968 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3969 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3970 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3971 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3972 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3973 | |
| 3974 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3975 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
| 3976 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 3977 | |
| 3978 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3979 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3980 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 3981 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3982 | |
| 3983 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3984 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | } |
| 3986 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3988 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3989 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3990 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3991 | /* |
| 3992 | * At this point in time we may need to wait for multiple |
| 3993 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 3994 | * |
| 3995 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3996 | * callback function. |
| 3997 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3998 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4000 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | |
| 4003 | return; |
| 4004 | } |
| 4005 | |
| 4006 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4010 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | struct lpfc_rport_data *rdata; |
| 4012 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4015 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4016 | return; |
| 4017 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4019 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4020 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4021 | rport_ids.port_id = ndlp->nlp_DID; |
| 4022 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4024 | /* |
| 4025 | * We leave our node pointer in rport->dd_data when we unregister a |
| 4026 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 4027 | * rport->dd_data points. So, if we're reusing a previously |
| 4028 | * registered port, drop the reference that we took the last time we |
| 4029 | * registered the port. |
| 4030 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4031 | rport = ndlp->rport; |
| 4032 | if (rport) { |
| 4033 | rdata = rport->dd_data; |
| 4034 | /* break the link before dropping the ref */ |
| 4035 | ndlp->rport = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4036 | if (rdata) { |
| 4037 | if (rdata->pnode == ndlp) |
| 4038 | lpfc_nlp_put(ndlp); |
| 4039 | rdata->pnode = NULL; |
| 4040 | } |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4041 | /* drop reference for earlier registeration */ |
| 4042 | put_device(&rport->dev); |
| 4043 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4044 | |
| 4045 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 4046 | "rport add: did:x%x flg:x%x type x%x", |
| 4047 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4048 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4049 | /* Don't add the remote port if unloading. */ |
| 4050 | if (vport->load_flag & FC_UNLOADING) |
| 4051 | return; |
| 4052 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4053 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4054 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4055 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4056 | "Warning: fc_remote_port_add failed\n"); |
| 4057 | return; |
| 4058 | } |
| 4059 | |
| 4060 | /* initialize static port data */ |
| 4061 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4062 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4064 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4065 | |
| 4066 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 4067 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 4068 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 4069 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4070 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4071 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4072 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4073 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4074 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4075 | "3183 rport register x%06x, rport %p role x%x\n", |
| 4076 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 4077 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4078 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4079 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4080 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4081 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4082 | return; |
| 4083 | } |
| 4084 | |
| 4085 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4086 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4087 | { |
| 4088 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4089 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4090 | struct lpfc_hba *phba = vport->phba; |
| 4091 | |
| 4092 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4093 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4094 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4095 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4096 | "rport delete: did:x%x flg:x%x type x%x", |
| 4097 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4098 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4099 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4100 | "3184 rport unregister x%06x, rport %p\n", |
| 4101 | ndlp->nlp_DID, rport); |
| 4102 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4103 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | |
| 4105 | return; |
| 4106 | } |
| 4107 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4108 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4110 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4112 | |
| 4113 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4114 | switch (state) { |
| 4115 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4116 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4117 | break; |
| 4118 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4119 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4120 | break; |
| 4121 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4122 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4123 | break; |
| 4124 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4126 | break; |
| 4127 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4129 | break; |
| 4130 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4131 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4132 | break; |
| 4133 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4135 | break; |
| 4136 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4137 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4138 | vport->fc_npr_cnt = 0; |
| 4139 | else |
| 4140 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4141 | break; |
| 4142 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4143 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4144 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4145 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4146 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4147 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4148 | int old_state, int new_state) |
| 4149 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4151 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4152 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4153 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4154 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4155 | } |
| 4156 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4157 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4158 | if (new_state == NLP_STE_NPR_NODE) |
| 4159 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4161 | /* FCP and NVME Transport interface */ |
| 4162 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4163 | old_state == NLP_STE_UNMAPPED_NODE)) { |
| 4164 | if (ndlp->rport) { |
| 4165 | vport->phba->nport_event_cnt++; |
| 4166 | lpfc_unregister_remote_port(ndlp); |
| 4167 | } |
| 4168 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4169 | /* Notify the NVME transport of this rport's loss on the |
| 4170 | * Initiator. For NVME Target, should upcall transport |
| 4171 | * in the else clause when API available. |
| 4172 | */ |
| 4173 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4174 | vport->phba->nport_event_cnt++; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4175 | if (vport->phba->nvmet_support == 0) |
| 4176 | lpfc_nvme_unregister_port(vport, ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4177 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4180 | /* FCP and NVME Transport interfaces */ |
| 4181 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4182 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4183 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4184 | if ((ndlp->nlp_fc4_type & NLP_FC4_FCP) || |
| 4185 | (ndlp->nlp_DID == Fabric_DID)) { |
| 4186 | vport->phba->nport_event_cnt++; |
| 4187 | /* |
| 4188 | * Tell the fc transport about the port, if we haven't |
| 4189 | * already. If we have, and it's a scsi entity, be |
| 4190 | */ |
| 4191 | lpfc_register_remote_port(vport, ndlp); |
| 4192 | } |
| 4193 | /* Notify the NVME transport of this new rport. */ |
| 4194 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
| 4195 | if (vport->phba->nvmet_support == 0) { |
| 4196 | /* Register this rport with the transport. |
| 4197 | * Initiators take the NDLP ref count in |
| 4198 | * the register. |
| 4199 | */ |
| 4200 | vport->phba->nport_event_cnt++; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4201 | lpfc_nvme_register_port(vport, ndlp); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4202 | } else { |
| 4203 | /* Just take an NDLP ref count since the |
| 4204 | * target does not register rports. |
| 4205 | */ |
| 4206 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4207 | } |
| 4208 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4209 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4210 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4211 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4212 | (vport->stat_data_enabled)) { |
| 4213 | /* |
| 4214 | * A new target is discovered, if there is no buffer for |
| 4215 | * statistical data collection allocate buffer. |
| 4216 | */ |
| 4217 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4218 | sizeof(struct lpfc_scsicmd_bkt), |
| 4219 | GFP_KERNEL); |
| 4220 | |
| 4221 | if (!ndlp->lat_data) |
| 4222 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4223 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4224 | "allocate statistical data buffer DID " |
| 4225 | "0x%x\n", ndlp->nlp_DID); |
| 4226 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4227 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4228 | * If the node just added to Mapped list was an FCP target, |
| 4229 | * but the remote port registration failed or assigned a target |
| 4230 | * id outside the presentable range - move the node to the |
| 4231 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4232 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4233 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4234 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4235 | (!ndlp->rport || |
| 4236 | ndlp->rport->scsi_target_id == -1 || |
| 4237 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4238 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4239 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4240 | spin_unlock_irq(shost->host_lock); |
| 4241 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4243 | } |
| 4244 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4245 | static char * |
| 4246 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4247 | { |
| 4248 | static char *states[] = { |
| 4249 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4250 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4251 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4252 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4253 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4254 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4255 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4256 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4257 | [NLP_STE_NPR_NODE] = "NPR", |
| 4258 | }; |
| 4259 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4260 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4261 | strlcpy(buffer, states[state], size); |
| 4262 | else |
| 4263 | snprintf(buffer, size, "unknown (%d)", state); |
| 4264 | return buffer; |
| 4265 | } |
| 4266 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4267 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4268 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4269 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4270 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4272 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4273 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4274 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4275 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4276 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4277 | ndlp->nlp_DID, |
| 4278 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4279 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4280 | |
| 4281 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4282 | "node statechg did:x%x old:%d ste:%d", |
| 4283 | ndlp->nlp_DID, old_state, state); |
| 4284 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4285 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4286 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4288 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4289 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4290 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4291 | } |
| 4292 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4293 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | spin_lock_irq(shost->host_lock); |
| 4295 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4296 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4297 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4298 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4299 | |
| 4300 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | lpfc_nlp_counters(vport, state, 1); |
| 4302 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4306 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4307 | { |
| 4308 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4309 | |
| 4310 | if (list_empty(&ndlp->nlp_listp)) { |
| 4311 | spin_lock_irq(shost->host_lock); |
| 4312 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4313 | spin_unlock_irq(shost->host_lock); |
| 4314 | } |
| 4315 | } |
| 4316 | |
| 4317 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4319 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4321 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4322 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4323 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4324 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4325 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4326 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4328 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4329 | NLP_STE_UNUSED_NODE); |
| 4330 | } |
| 4331 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4332 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4333 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4334 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4335 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4336 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4337 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4338 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4339 | NLP_STE_UNUSED_NODE); |
| 4340 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4342 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4343 | * @vport: Pointer to Virtual Port object. |
| 4344 | * @ndlp: Pointer to FC node object. |
| 4345 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4346 | * |
| 4347 | * This function is always called when node object need to be initialized. |
| 4348 | * It initializes all the fields of the node object. Although the reference |
| 4349 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4350 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4351 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4352 | * the final release of ndlp is determined by its reference count. And, the |
| 4353 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4354 | **/ |
| 4355 | static inline void |
| 4356 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4357 | uint32_t did) |
| 4358 | { |
| 4359 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4360 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Tomas Jasek | 33cc559 | 2017-03-03 13:45:48 +0100 | [diff] [blame] | 4361 | setup_timer(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, |
| 4362 | (unsigned long)ndlp); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4363 | ndlp->nlp_DID = did; |
| 4364 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4365 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4366 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4367 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4368 | kref_init(&ndlp->kref); |
| 4369 | NLP_INT_NODE_ACT(ndlp); |
| 4370 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4371 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4372 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4373 | |
| 4374 | struct lpfc_nodelist * |
| 4375 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4376 | int state) |
| 4377 | { |
| 4378 | struct lpfc_hba *phba = vport->phba; |
| 4379 | uint32_t did; |
| 4380 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4381 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4382 | int rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4383 | |
| 4384 | if (!ndlp) |
| 4385 | return NULL; |
| 4386 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4387 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4388 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 4389 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 4390 | return NULL; |
| 4391 | } |
| 4392 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4393 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4394 | /* The ndlp should not be in memory free mode */ |
| 4395 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4396 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4397 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4398 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4399 | "usgmap:x%x refcnt:%d\n", |
| 4400 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4401 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4402 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4403 | } |
| 4404 | /* The ndlp should not already be in active mode */ |
| 4405 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4406 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4407 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4408 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4409 | "usgmap:x%x refcnt:%d\n", |
| 4410 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4411 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4412 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | /* Keep the original DID */ |
| 4416 | did = ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4417 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4418 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4419 | |
| 4420 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4421 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4422 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4423 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4424 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4425 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4426 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4427 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4428 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4429 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4430 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4431 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4432 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4433 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4434 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4435 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4436 | ndlp->nlp_usg_map, ndlp); |
| 4437 | } |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4438 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4439 | |
| 4440 | if (state != NLP_STE_UNUSED_NODE) |
| 4441 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4442 | |
| 4443 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4444 | "node enable: did:x%x", |
| 4445 | ndlp->nlp_DID, 0, 0); |
| 4446 | return ndlp; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4447 | |
| 4448 | free_rpi: |
| 4449 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4450 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 4451 | return NULL; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4456 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4457 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4458 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4459 | * 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] | 4460 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4461 | * until ALL other outstanding threads have completed. We check |
| 4462 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4463 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4464 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4465 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4466 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4467 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4468 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4469 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4470 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4471 | |
| 4472 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4473 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | } |
| 4475 | |
| 4476 | /* |
| 4477 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4478 | */ |
| 4479 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4483 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4484 | uint32_t tmo; |
| 4485 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4486 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4487 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4488 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4489 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4490 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4491 | * FC spec states we need 3 * ratov for CT requests |
| 4492 | */ |
| 4493 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4494 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4496 | |
| 4497 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4498 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4499 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4500 | tmo, vport->port_state, vport->fc_flag); |
| 4501 | } |
| 4502 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4503 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4504 | spin_lock_irq(shost->host_lock); |
| 4505 | vport->fc_flag |= FC_DISC_TMO; |
| 4506 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | |
| 4508 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4509 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4510 | "0247 Start Discovery Timer state x%x " |
| 4511 | "Data: x%x x%lx x%x x%x\n", |
| 4512 | vport->port_state, tmo, |
| 4513 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4514 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4515 | |
| 4516 | return; |
| 4517 | } |
| 4518 | |
| 4519 | /* |
| 4520 | * Cancel rescue timer for Discovery / RSCN handling |
| 4521 | */ |
| 4522 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4525 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | unsigned long iflags; |
| 4527 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4528 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4529 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4530 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4534 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4535 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4536 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4537 | del_timer_sync(&vport->fc_disctmo); |
| 4538 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4539 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4540 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4544 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4545 | "0248 Cancel Discovery Timer state x%x " |
| 4546 | "Data: x%x x%x x%x\n", |
| 4547 | vport->port_state, vport->fc_flag, |
| 4548 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4549 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | /* |
| 4553 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4554 | * Return true if iocb matches the specified nport |
| 4555 | */ |
| 4556 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4557 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4558 | struct lpfc_sli_ring *pring, |
| 4559 | struct lpfc_iocbq *iocb, |
| 4560 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4563 | struct lpfc_vport *vport = ndlp->vport; |
| 4564 | |
| 4565 | if (iocb->vport != vport) |
| 4566 | return 0; |
| 4567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | if (pring->ringno == LPFC_ELS_RING) { |
| 4569 | switch (icmd->ulpCommand) { |
| 4570 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4571 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4572 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4574 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4575 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4576 | case CMD_XMIT_ELS_RSP64_CX: |
| 4577 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4578 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4579 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4580 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4581 | /* Skip match check if waiting to relogin to FCP target */ |
| 4582 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4583 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4584 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4585 | } |
| 4586 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4590 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | } |
| 4592 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4593 | static void |
| 4594 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4595 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4596 | struct list_head *dequeue_list) |
| 4597 | { |
| 4598 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4599 | |
| 4600 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4601 | /* Check to see if iocb matches the nport */ |
| 4602 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4603 | /* match, dequeue */ |
| 4604 | list_move_tail(&iocb->list, dequeue_list); |
| 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | static void |
| 4609 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4610 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4611 | { |
| 4612 | struct lpfc_sli *psli = &phba->sli; |
| 4613 | uint32_t i; |
| 4614 | |
| 4615 | spin_lock_irq(&phba->hbalock); |
| 4616 | for (i = 0; i < psli->num_rings; i++) |
| 4617 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4618 | dequeue_list); |
| 4619 | spin_unlock_irq(&phba->hbalock); |
| 4620 | } |
| 4621 | |
| 4622 | static void |
| 4623 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4624 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4625 | { |
| 4626 | struct lpfc_sli_ring *pring; |
| 4627 | struct lpfc_queue *qp = NULL; |
| 4628 | |
| 4629 | spin_lock_irq(&phba->hbalock); |
| 4630 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4631 | pring = qp->pring; |
| 4632 | if (!pring) |
| 4633 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4634 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4635 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4636 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4637 | } |
| 4638 | spin_unlock_irq(&phba->hbalock); |
| 4639 | } |
| 4640 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4641 | /* |
| 4642 | * Free resources / clean up outstanding I/Os |
| 4643 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4644 | */ |
| 4645 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4648 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4649 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4650 | lpfc_fabric_abort_nport(ndlp); |
| 4651 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4652 | /* |
| 4653 | * Everything that matches on txcmplq will be returned |
| 4654 | * by firmware with a no rpi error. |
| 4655 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4656 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4657 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4658 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4659 | else |
| 4660 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4661 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4662 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4663 | /* Cancel all the IOCBs from the completions list */ |
| 4664 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4665 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4666 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4667 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
| 4669 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4670 | /** |
| 4671 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4672 | * @phba: Pointer to HBA context object. |
| 4673 | * @pmb: Pointer to mailbox object. |
| 4674 | * |
| 4675 | * This function will issue an ELS LOGO command after completing |
| 4676 | * the UNREG_RPI. |
| 4677 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4678 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4679 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4680 | { |
| 4681 | struct lpfc_vport *vport = pmb->vport; |
| 4682 | struct lpfc_nodelist *ndlp; |
| 4683 | |
| 4684 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4685 | if (!ndlp) |
| 4686 | return; |
| 4687 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4688 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4689 | } |
| 4690 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | /* |
| 4692 | * Free rpi associated with LPFC_NODELIST entry. |
| 4693 | * This routine is called from lpfc_freenode(), when we are removing |
| 4694 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4695 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4696 | * to the remote NPort. In addition, it is called after we receive |
| 4697 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4698 | * we are waiting to PLOGI back to the remote NPort. |
| 4699 | */ |
| 4700 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4701 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4703 | struct lpfc_hba *phba = vport->phba; |
| 4704 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4705 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4706 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4708 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4709 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4710 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 4711 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4712 | "3366 RPI x%x needs to be " |
| 4713 | "unregistered nlp_flag x%x " |
| 4714 | "did x%x\n", |
| 4715 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4716 | ndlp->nlp_DID); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4718 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4719 | /* SLI4 ports require the physical rpi value. */ |
| 4720 | rpi = ndlp->nlp_rpi; |
| 4721 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4722 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4723 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4724 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4725 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4726 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4727 | mbox->context1 = ndlp; |
| 4728 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4729 | } else { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4730 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4731 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4732 | (bf_get(lpfc_sli_intf_if_type, |
| 4733 | &phba->sli4_hba.sli_intf) == |
James Smart | a6517db | 2016-03-31 14:12:29 -0700 | [diff] [blame] | 4734 | LPFC_SLI_INTF_IF_TYPE_2) && |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4735 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4736 | mbox->context1 = lpfc_nlp_get(ndlp); |
| 4737 | mbox->mbox_cmpl = |
| 4738 | lpfc_sli4_unreg_rpi_cmpl_clr; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4739 | /* |
| 4740 | * accept PLOGIs after unreg_rpi_cmpl |
| 4741 | */ |
| 4742 | acc_plogi = 0; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4743 | } else |
| 4744 | mbox->mbox_cmpl = |
| 4745 | lpfc_sli_def_mbox_cmpl; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4746 | } |
| 4747 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4748 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4749 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4751 | acc_plogi = 1; |
| 4752 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4753 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4754 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4755 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4756 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4757 | ndlp->nlp_rpi = 0; |
| 4758 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4759 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4760 | if (acc_plogi) |
| 4761 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4762 | return 1; |
| 4763 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4764 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | return 0; |
| 4766 | } |
| 4767 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4768 | /** |
| 4769 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4770 | * @phba: pointer to lpfc hba data structure. |
| 4771 | * |
| 4772 | * This routine is invoked to unregister all the currently registered RPIs |
| 4773 | * to the HBA. |
| 4774 | **/ |
| 4775 | void |
| 4776 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4777 | { |
| 4778 | struct lpfc_vport **vports; |
| 4779 | struct lpfc_nodelist *ndlp; |
| 4780 | struct Scsi_Host *shost; |
| 4781 | int i; |
| 4782 | |
| 4783 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4784 | if (!vports) { |
| 4785 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4786 | "2884 Vport array allocation failed \n"); |
| 4787 | return; |
| 4788 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4789 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4790 | shost = lpfc_shost_from_vport(vports[i]); |
| 4791 | spin_lock_irq(shost->host_lock); |
| 4792 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4793 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4794 | /* The mempool_alloc might sleep */ |
| 4795 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4796 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4797 | spin_lock_irq(shost->host_lock); |
| 4798 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4799 | } |
| 4800 | spin_unlock_irq(shost->host_lock); |
| 4801 | } |
| 4802 | lpfc_destroy_vport_work_array(phba, vports); |
| 4803 | } |
| 4804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4805 | void |
| 4806 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4807 | { |
| 4808 | struct lpfc_hba *phba = vport->phba; |
| 4809 | LPFC_MBOXQ_t *mbox; |
| 4810 | int rc; |
| 4811 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4812 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4813 | lpfc_sli4_unreg_all_rpis(vport); |
| 4814 | return; |
| 4815 | } |
| 4816 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4817 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4818 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4819 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4820 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4821 | mbox->vport = vport; |
| 4822 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4823 | mbox->context1 = NULL; |
| 4824 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4825 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4826 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4827 | |
| 4828 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4829 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4830 | "1836 Could not issue " |
| 4831 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | void |
| 4836 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4837 | { |
| 4838 | struct lpfc_hba *phba = vport->phba; |
| 4839 | LPFC_MBOXQ_t *mbox; |
| 4840 | int rc; |
| 4841 | |
| 4842 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4843 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4844 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4845 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4846 | mbox->vport = vport; |
| 4847 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4848 | mbox->context1 = NULL; |
| 4849 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4850 | if (rc != MBX_TIMEOUT) |
| 4851 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4852 | |
| 4853 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4854 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4855 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4856 | "unreg_did (default rpis) status %d\n", |
| 4857 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4858 | } |
| 4859 | } |
| 4860 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | /* |
| 4862 | * Free resources associated with LPFC_NODELIST entry |
| 4863 | * so it can be freed. |
| 4864 | */ |
| 4865 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4866 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4867 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4868 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4869 | struct lpfc_hba *phba = vport->phba; |
| 4870 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4871 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4872 | |
| 4873 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4875 | "0900 Cleanup node for NPort x%x " |
| 4876 | "Data: x%x x%x x%x\n", |
| 4877 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4878 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4879 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4880 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4881 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4882 | "usgmap:x%x refcnt:%d\n", |
| 4883 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4884 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4885 | lpfc_dequeue_node(vport, ndlp); |
| 4886 | } else { |
| 4887 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4888 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4889 | "usgmap:x%x refcnt:%d\n", |
| 4890 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4891 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4892 | lpfc_disable_node(vport, ndlp); |
| 4893 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4894 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4895 | |
| 4896 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4899 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4900 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4901 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4903 | mb->context2 = NULL; |
| 4904 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4905 | } |
| 4906 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4907 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4908 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4909 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4910 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4911 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4912 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4913 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4914 | continue; |
| 4915 | |
| 4916 | mb->context2 = NULL; |
| 4917 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4918 | } |
| 4919 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4920 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4921 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4922 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4923 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4924 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4925 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | kfree(mp); |
| 4928 | } |
| 4929 | list_del(&mb->list); |
| 4930 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4931 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4932 | * the ndlp reference count as we are in the process |
| 4933 | * of lpfc_nlp_release. |
| 4934 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | } |
| 4936 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4937 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4939 | lpfc_els_abort(phba, ndlp); |
| 4940 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4941 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4942 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4943 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4945 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4947 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4948 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4949 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4950 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4951 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4952 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4953 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | /* |
| 4957 | * Check to see if we can free the nlp back to the freelist. |
| 4958 | * If we are in the middle of using the nlp in the discovery state |
| 4959 | * machine, defer the free till we reach the end of the state machine. |
| 4960 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4961 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4962 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4964 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4965 | struct lpfc_rport_data *rdata; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4966 | struct fc_rport *rport; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4967 | LPFC_MBOXQ_t *mbox; |
| 4968 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4970 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4971 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4972 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4973 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4974 | /* For this case we need to cleanup the default rpi |
| 4975 | * allocated by the firmware. |
| 4976 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4977 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4978 | "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 4979 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4980 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4981 | ndlp->nlp_usg_map, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4982 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4983 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4984 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4985 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4986 | if (rc) { |
| 4987 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4988 | } |
| 4989 | else { |
| 4990 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4991 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4992 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4993 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4994 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4995 | if (rc == MBX_NOT_FINISHED) { |
| 4996 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4997 | } |
| 4998 | } |
| 4999 | } |
| 5000 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5001 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5002 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5003 | /* |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5004 | * ndlp->rport must be set to NULL before it reaches here |
| 5005 | * i.e. break rport/node link before doing lpfc_nlp_put for |
| 5006 | * registered rport and then drop the reference of rport. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5008 | if (ndlp->rport) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5009 | /* |
| 5010 | * extra lpfc_nlp_put dropped the reference of ndlp |
| 5011 | * for registered rport so need to cleanup rport |
| 5012 | */ |
| 5013 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 5014 | "0940 removed node x%p DID x%x " |
| 5015 | " rport not null %p\n", |
| 5016 | ndlp, ndlp->nlp_DID, ndlp->rport); |
| 5017 | rport = ndlp->rport; |
| 5018 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5019 | rdata->pnode = NULL; |
| 5020 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5021 | put_device(&rport->dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5026 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5027 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5029 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | |
| 5031 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5032 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5034 | /* First check for Direct match */ |
| 5035 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5036 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | |
| 5038 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5039 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5041 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | matchdid.un.word = did; |
| 5045 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5046 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5047 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5048 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5049 | /* This code is supposed to match the ID |
| 5050 | * for a private loop device that is |
| 5051 | * connect to fl_port. But we need to |
| 5052 | * check that the port did not just go |
| 5053 | * from pt2pt to fabric or we could end |
| 5054 | * up matching ndlp->nlp_DID 000001 to |
| 5055 | * fabric DID 0x20101 |
| 5056 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5057 | if ((ndlpdid.un.b.domain == 0) && |
| 5058 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5059 | if (ndlpdid.un.b.id && |
| 5060 | vport->phba->fc_topology == |
| 5061 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5062 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5063 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5064 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | matchdid.un.word = ndlp->nlp_DID; |
| 5068 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5069 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5070 | if ((matchdid.un.b.domain == 0) && |
| 5071 | (matchdid.un.b.area == 0)) { |
| 5072 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5073 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5074 | } |
| 5075 | } |
| 5076 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5077 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5078 | } |
| 5079 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5080 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5081 | static struct lpfc_nodelist * |
| 5082 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5084 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5085 | uint32_t data1; |
| 5086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5087 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5088 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5089 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 5090 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 5091 | ((uint32_t) ndlp->nlp_type << 8) | |
| 5092 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5093 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5094 | "0929 FIND node DID " |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5095 | "Data: x%p x%x x%x x%x %p\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5096 | ndlp, ndlp->nlp_DID, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5097 | ndlp->nlp_flag, data1, |
| 5098 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5099 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5100 | } |
| 5101 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5103 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5104 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5105 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | return NULL; |
| 5107 | } |
| 5108 | |
| 5109 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5110 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5112 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5114 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5115 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5116 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5117 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5118 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5119 | return ndlp; |
| 5120 | } |
| 5121 | |
| 5122 | struct lpfc_nodelist * |
| 5123 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5124 | { |
| 5125 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5126 | struct lpfc_nodelist *ndlp; |
| 5127 | |
| 5128 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5129 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5130 | if (vport->phba->nvmet_support) |
| 5131 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5132 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5133 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5135 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5136 | if (!ndlp) |
| 5137 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5138 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5139 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5140 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5141 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5142 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5143 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5144 | if (vport->phba->nvmet_support) |
| 5145 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5146 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 5147 | if (!ndlp) |
| 5148 | return NULL; |
| 5149 | spin_lock_irq(shost->host_lock); |
| 5150 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5151 | spin_unlock_irq(shost->host_lock); |
| 5152 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5153 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5154 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5155 | /* The NVME Target does not want to actively manage an rport. |
| 5156 | * The goal is to allow the target to reset its state and clear |
| 5157 | * pending IO in preparation for the initiator to recover. |
| 5158 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5159 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5160 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5161 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5162 | |
| 5163 | /* Since this node is marked for discovery, |
| 5164 | * delay timeout is not needed. |
| 5165 | */ |
| 5166 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5167 | |
| 5168 | /* NVME Target mode waits until rport is known to be |
| 5169 | * impacted by the RSCN before it transitions. No |
| 5170 | * active management - just go to NPR provided the |
| 5171 | * node had a valid login. |
| 5172 | */ |
| 5173 | if (vport->phba->nvmet_support) |
| 5174 | return ndlp; |
| 5175 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5176 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5177 | * we don't need to try to discover it again. |
| 5178 | */ |
| 5179 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 5180 | return NULL; |
| 5181 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5182 | spin_lock_irq(shost->host_lock); |
| 5183 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5184 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 5185 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5186 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5187 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5188 | /* If the initiator received a PLOGI from this NPort or if the |
| 5189 | * initiator is already in the process of discovery on it, |
| 5190 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5191 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5192 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5193 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5194 | (!vport->phba->nvmet_support && |
| 5195 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5196 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5197 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5198 | if (vport->phba->nvmet_support) |
| 5199 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5200 | |
| 5201 | /* Moving to NPR state clears unsolicited flags and |
| 5202 | * allows for rediscovery |
| 5203 | */ |
| 5204 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5205 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5206 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5207 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5208 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5209 | } |
| 5210 | return ndlp; |
| 5211 | } |
| 5212 | |
| 5213 | /* Build a list of nodes to discover based on the loopmap */ |
| 5214 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5215 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5217 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5218 | int j; |
| 5219 | uint32_t alpa, index; |
| 5220 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5221 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5224 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5225 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | |
| 5227 | /* Check for loop map present or not */ |
| 5228 | if (phba->alpa_map[0]) { |
| 5229 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5230 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | } |
| 5235 | } else { |
| 5236 | /* No alpamap, so try all alpa's */ |
| 5237 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5238 | /* If cfg_scan_down is set, start from highest |
| 5239 | * ALPA (0xef) to lowest (0x1). |
| 5240 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5241 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | index = j; |
| 5243 | else |
| 5244 | index = FC_MAXLOOP - j - 1; |
| 5245 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5247 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5248 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | return; |
| 5252 | } |
| 5253 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5254 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5255 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5256 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5259 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5260 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5261 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5262 | int rc; |
| 5263 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5264 | /* |
| 5265 | * if it's not a physical port or if we already send |
| 5266 | * clear_la then don't send it. |
| 5267 | */ |
| 5268 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5269 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5270 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5271 | return; |
| 5272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5273 | /* Link up discovery */ |
| 5274 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5275 | phba->link_state = LPFC_CLEAR_LA; |
| 5276 | lpfc_clear_la(phba, mbox); |
| 5277 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5278 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5279 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5280 | if (rc == MBX_NOT_FINISHED) { |
| 5281 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5282 | lpfc_disc_flush_list(vport); |
| 5283 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5284 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5285 | phba->link_state = LPFC_HBA_ERROR; |
| 5286 | } |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5291 | void |
| 5292 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5293 | { |
| 5294 | LPFC_MBOXQ_t *regvpimbox; |
| 5295 | |
| 5296 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5297 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5298 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5299 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5300 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5301 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5302 | == MBX_NOT_FINISHED) { |
| 5303 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | } |
| 5307 | |
| 5308 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5309 | void |
| 5310 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5311 | { |
| 5312 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5313 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5314 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5315 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5316 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5317 | if (!lpfc_is_link_up(phba)) { |
| 5318 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5319 | "3315 Link is not up %x\n", |
| 5320 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5321 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5322 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5323 | |
| 5324 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 | clear_la_pending = 1; |
| 5326 | else |
| 5327 | clear_la_pending = 0; |
| 5328 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5329 | if (vport->port_state < LPFC_VPORT_READY) |
| 5330 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5332 | lpfc_set_disctmo(vport); |
| 5333 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5334 | vport->fc_prevDID = vport->fc_myDID; |
| 5335 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5336 | |
| 5337 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5338 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5339 | "0202 Start Discovery hba state x%x " |
| 5340 | "Data: x%x x%x x%x\n", |
| 5341 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 5342 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | |
| 5344 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5345 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | |
| 5347 | if (num_sent) |
| 5348 | return; |
| 5349 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5350 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5351 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5352 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5353 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5354 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5355 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5356 | lpfc_issue_reg_vpi(phba, vport); |
| 5357 | return; |
| 5358 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5360 | /* |
| 5361 | * For SLI2, we need to set port_state to READY and continue |
| 5362 | * discovery. |
| 5363 | */ |
| 5364 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5365 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5366 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5367 | |
| 5368 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5369 | vport->num_disc_nodes = 0; |
| 5370 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5371 | if (vport->fc_npr_cnt) |
| 5372 | lpfc_els_disc_plogi(vport); |
| 5373 | |
| 5374 | if (!vport->num_disc_nodes) { |
| 5375 | spin_lock_irq(shost->host_lock); |
| 5376 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5377 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5378 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | } |
| 5380 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5381 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5382 | } else { |
| 5383 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5384 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5385 | |
| 5386 | if (num_sent) |
| 5387 | return; |
| 5388 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5389 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5390 | /* Check to see if more RSCNs came in while we |
| 5391 | * were processing this one. |
| 5392 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5393 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5394 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5395 | spin_lock_irq(shost->host_lock); |
| 5396 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5397 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5398 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5399 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5400 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5401 | } |
| 5402 | } |
| 5403 | return; |
| 5404 | } |
| 5405 | |
| 5406 | /* |
| 5407 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5408 | * ring the match the sppecified nodelist. |
| 5409 | */ |
| 5410 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5411 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5413 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | struct lpfc_sli *psli; |
| 5415 | IOCB_t *icmd; |
| 5416 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5417 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5418 | |
| 5419 | psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5420 | pring = lpfc_phba_elsring(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5421 | |
| 5422 | /* Error matching iocb on txq or txcmplq |
| 5423 | * First check the txq. |
| 5424 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5425 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5427 | if (iocb->context1 != ndlp) { |
| 5428 | continue; |
| 5429 | } |
| 5430 | icmd = &iocb->iocb; |
| 5431 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5432 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5433 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5434 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | /* Next check the txcmplq */ |
| 5439 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5440 | if (iocb->context1 != ndlp) { |
| 5441 | continue; |
| 5442 | } |
| 5443 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5444 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5445 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5446 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | } |
| 5448 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5450 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5451 | /* Cancel all the IOCBs from the completions list */ |
| 5452 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5453 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5454 | } |
| 5455 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5456 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | { |
| 5459 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5460 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5462 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5463 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5464 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5465 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5466 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5467 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5468 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5469 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5470 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5471 | } |
| 5472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | } |
| 5474 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5475 | void |
| 5476 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5477 | { |
| 5478 | lpfc_els_flush_rscn(vport); |
| 5479 | lpfc_els_flush_cmd(vport); |
| 5480 | lpfc_disc_flush_list(vport); |
| 5481 | } |
| 5482 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5483 | /*****************************************************************************/ |
| 5484 | /* |
| 5485 | * NAME: lpfc_disc_timeout |
| 5486 | * |
| 5487 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5488 | * |
| 5489 | * EXECUTION ENVIRONMENT: interrupt only |
| 5490 | * |
| 5491 | * CALLED FROM: |
| 5492 | * Timer function |
| 5493 | * |
| 5494 | * RETURNS: |
| 5495 | * none |
| 5496 | */ |
| 5497 | /*****************************************************************************/ |
| 5498 | void |
| 5499 | lpfc_disc_timeout(unsigned long ptr) |
| 5500 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5501 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5502 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5503 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | unsigned long flags = 0; |
| 5505 | |
| 5506 | if (unlikely(!phba)) |
| 5507 | return; |
| 5508 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5509 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5510 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5511 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5513 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5514 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5515 | if (!tmo_posted) |
| 5516 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5517 | return; |
| 5518 | } |
| 5519 | |
| 5520 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5521 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5522 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5523 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5524 | struct lpfc_hba *phba = vport->phba; |
| 5525 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5526 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5527 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5528 | int rc, clrlaerr = 0; |
| 5529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5530 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5531 | return; |
| 5532 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | spin_lock_irq(shost->host_lock); |
| 5534 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5535 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5537 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5538 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5539 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5541 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5542 | |
| 5543 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5544 | /* |
| 5545 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5546 | * waiting for FAN timeout |
| 5547 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5548 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5549 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5550 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5551 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5552 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5553 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5554 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5555 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5556 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5557 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5558 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5559 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5560 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5561 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5562 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5563 | /* Fail outstanding IO now since device |
| 5564 | * is marked for PLOGI. |
| 5565 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5567 | } |
| 5568 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5569 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5570 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5571 | lpfc_initial_flogi(vport); |
| 5572 | else |
| 5573 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5574 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5575 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5576 | break; |
| 5577 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5578 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5579 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5580 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5582 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5583 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5584 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5585 | |
| 5586 | /* Assume no Fabric and go on with discovery. |
| 5587 | * Check for outstanding ELS FLOGI to abort. |
| 5588 | */ |
| 5589 | |
| 5590 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5591 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5592 | |
| 5593 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5594 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | break; |
| 5596 | |
| 5597 | case LPFC_FABRIC_CFG_LINK: |
| 5598 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5599 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5600 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5601 | "0223 Timeout while waiting for " |
| 5602 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5605 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5606 | lpfc_els_abort(phba, ndlp); |
| 5607 | |
| 5608 | /* ReStart discovery */ |
| 5609 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5610 | |
| 5611 | case LPFC_NS_QRY: |
| 5612 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5613 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5614 | "0224 NameServer Query timeout " |
| 5615 | "Data: x%x x%x\n", |
| 5616 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5617 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5618 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5619 | /* Try it one more time */ |
| 5620 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5621 | vport->gidft_inp = 0; |
| 5622 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5623 | if (rc == 0) |
| 5624 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5625 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5626 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5628 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5629 | /* |
| 5630 | * Discovery is over. |
| 5631 | * set port_state to PORT_READY if SLI2. |
| 5632 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5633 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5634 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5635 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5636 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5637 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5638 | lpfc_issue_clear_la(phba, vport); |
| 5639 | vport->port_state = LPFC_VPORT_READY; |
| 5640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5644 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5645 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5646 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5647 | "0206 Device Discovery " |
| 5648 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5649 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5650 | break; |
| 5651 | } |
| 5652 | |
| 5653 | lpfc_linkdown(phba); |
| 5654 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5655 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5656 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5657 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5658 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5659 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5660 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5661 | if (rc == MBX_NOT_FINISHED) |
| 5662 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5663 | |
| 5664 | break; |
| 5665 | |
| 5666 | case LPFC_DISC_AUTH: |
| 5667 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5668 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5669 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5670 | lpfc_disc_flush_list(vport); |
| 5671 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5672 | /* |
| 5673 | * set port_state to PORT_READY if SLI2. |
| 5674 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5675 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5676 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5677 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5678 | lpfc_issue_reg_vpi(phba, vport); |
| 5679 | else { /* NPIV Not enabled */ |
| 5680 | lpfc_issue_clear_la(phba, vport); |
| 5681 | vport->port_state = LPFC_VPORT_READY; |
| 5682 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5683 | } |
| 5684 | break; |
| 5685 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5686 | case LPFC_VPORT_READY: |
| 5687 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5688 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5689 | "0231 RSCN timeout Data: x%x " |
| 5690 | "x%x\n", |
| 5691 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | |
| 5693 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5694 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5696 | lpfc_els_flush_rscn(vport); |
| 5697 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | } |
| 5699 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5700 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5701 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5702 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5703 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5704 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5705 | break; |
| 5706 | } |
| 5707 | |
| 5708 | switch (phba->link_state) { |
| 5709 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5710 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5711 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5712 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5713 | clrlaerr = 1; |
| 5714 | break; |
| 5715 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5716 | case LPFC_LINK_UP: |
| 5717 | lpfc_issue_clear_la(phba, vport); |
| 5718 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5719 | case LPFC_LINK_UNKNOWN: |
| 5720 | case LPFC_WARM_START: |
| 5721 | case LPFC_INIT_START: |
| 5722 | case LPFC_INIT_MBX_CMDS: |
| 5723 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5724 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5726 | "0230 Unexpected timeout, hba link " |
| 5727 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5728 | clrlaerr = 1; |
| 5729 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5730 | |
| 5731 | case LPFC_HBA_READY: |
| 5732 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5736 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5737 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 5738 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 5739 | ~LPFC_STOP_IOCB_EVENT; |
| 5740 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 5741 | ~LPFC_STOP_IOCB_EVENT; |
| 5742 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5743 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5744 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5745 | return; |
| 5746 | } |
| 5747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5748 | /* |
| 5749 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5750 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5751 | * as the completion routine when the command is |
| 5752 | * handed off to the SLI layer. |
| 5753 | */ |
| 5754 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5755 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5756 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5757 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5758 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5759 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5760 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5761 | |
| 5762 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5763 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5764 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5765 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5766 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5767 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5769 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5770 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5771 | "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 5772 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5773 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5774 | ndlp->nlp_usg_map, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5775 | /* |
| 5776 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5777 | * 0xfffffa (FDMI well known port). |
| 5778 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 5779 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5780 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5781 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5782 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 5783 | else |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5784 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| 5785 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5786 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5787 | /* decrement the node reference count held for this callback |
| 5788 | * function. |
| 5789 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5790 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5792 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5793 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5794 | |
| 5795 | return; |
| 5796 | } |
| 5797 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5798 | static int |
| 5799 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5800 | { |
| 5801 | uint16_t *rpi = param; |
| 5802 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5803 | /* check for active node */ |
| 5804 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5805 | return 0; |
| 5806 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5807 | return ndlp->nlp_rpi == *rpi; |
| 5808 | } |
| 5809 | |
| 5810 | static int |
| 5811 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5812 | { |
| 5813 | return memcmp(&ndlp->nlp_portname, param, |
| 5814 | sizeof(ndlp->nlp_portname)) == 0; |
| 5815 | } |
| 5816 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5817 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5818 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5819 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5820 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5821 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5822 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5823 | if (filter(ndlp, param)) { |
| 5824 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5825 | "3185 FIND node filter %p DID " |
| 5826 | "Data: x%p x%x x%x\n", |
| 5827 | filter, ndlp, ndlp->nlp_DID, |
| 5828 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5829 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5830 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5831 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5832 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5833 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5834 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5835 | } |
| 5836 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5837 | /* |
| 5838 | * 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] | 5839 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5840 | */ |
| 5841 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5842 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5843 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5844 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5845 | } |
| 5846 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5847 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5848 | * 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] | 5849 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5850 | */ |
| 5851 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5852 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5853 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5854 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5855 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5856 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5857 | spin_lock_irq(shost->host_lock); |
| 5858 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5859 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5860 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5861 | } |
| 5862 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5863 | /* |
| 5864 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5865 | * is found, the routine returns the node element list pointer else |
| 5866 | * return NULL. |
| 5867 | */ |
| 5868 | struct lpfc_nodelist * |
| 5869 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5870 | { |
| 5871 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5872 | struct lpfc_nodelist *ndlp; |
| 5873 | |
| 5874 | spin_lock_irq(shost->host_lock); |
| 5875 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5876 | spin_unlock_irq(shost->host_lock); |
| 5877 | return ndlp; |
| 5878 | } |
| 5879 | |
| 5880 | /** |
| 5881 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5882 | * @phba: pointer to lpfc hba data structure. |
| 5883 | * @vpi: the physical host virtual N_Port identifier. |
| 5884 | * |
| 5885 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5886 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5887 | * of the vport with the matching @vpi. |
| 5888 | * |
| 5889 | * Return code |
| 5890 | * NULL - No vport with the matching @vpi found |
| 5891 | * Otherwise - Address to the vport with the matching @vpi. |
| 5892 | **/ |
| 5893 | struct lpfc_vport * |
| 5894 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5895 | { |
| 5896 | struct lpfc_vport *vport; |
| 5897 | unsigned long flags; |
| 5898 | int i = 0; |
| 5899 | |
| 5900 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5901 | if (vpi > 0) { |
| 5902 | /* |
| 5903 | * Translate the physical vpi to the logical vpi. The |
| 5904 | * vport stores the logical vpi. |
| 5905 | */ |
| 5906 | for (i = 0; i < phba->max_vpi; i++) { |
| 5907 | if (vpi == phba->vpi_ids[i]) |
| 5908 | break; |
| 5909 | } |
| 5910 | |
| 5911 | if (i >= phba->max_vpi) { |
| 5912 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5913 | "2936 Could not find Vport mapped " |
| 5914 | "to vpi %d\n", vpi); |
| 5915 | return NULL; |
| 5916 | } |
| 5917 | } |
| 5918 | |
| 5919 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5920 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5921 | if (vport->vpi == i) { |
| 5922 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5923 | return vport; |
| 5924 | } |
| 5925 | } |
| 5926 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5927 | return NULL; |
| 5928 | } |
| 5929 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5930 | struct lpfc_nodelist * |
| 5931 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5932 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5933 | struct lpfc_nodelist *ndlp; |
| 5934 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 5935 | |
| 5936 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 5937 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 5938 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 5939 | return NULL; |
| 5940 | } |
| 5941 | |
| 5942 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 5943 | if (!ndlp) { |
| 5944 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5945 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 5946 | return NULL; |
| 5947 | } |
| 5948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5949 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5950 | |
| 5951 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5952 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5953 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5954 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5955 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5956 | "0007 rpi:%x DID:%x flg:%x refcnt:%d " |
| 5957 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5958 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5959 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5960 | ndlp->nlp_usg_map, ndlp); |
| 5961 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5962 | ndlp->active_rrqs_xri_bitmap = |
| 5963 | mempool_alloc(vport->phba->active_rrq_pool, |
| 5964 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 5965 | if (ndlp->active_rrqs_xri_bitmap) |
| 5966 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 5967 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5968 | } |
| 5969 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5970 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5971 | |
| 5972 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5973 | "node init: did:x%x", |
| 5974 | ndlp->nlp_DID, 0, 0); |
| 5975 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5976 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5977 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5978 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5979 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5980 | * and mempool_free's the nodelist. |
| 5981 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5982 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5983 | lpfc_nlp_release(struct kref *kref) |
| 5984 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5985 | struct lpfc_hba *phba; |
| 5986 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5987 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 5988 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5989 | |
| 5990 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5991 | "node release: did:x%x flg:x%x type:x%x", |
| 5992 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 5993 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5994 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5995 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5996 | "usgmap:x%x refcnt:%d rpi:%x\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5997 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5998 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5999 | |
| 6000 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6001 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6002 | |
| 6003 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6004 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6005 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6006 | NLP_CLR_NODE_ACT(ndlp); |
| 6007 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 6008 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6009 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6010 | |
| 6011 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6012 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 6013 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6014 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6015 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6016 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6017 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6018 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6019 | } |
| 6020 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6021 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6022 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6023 | * is using it. |
| 6024 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6025 | struct lpfc_nodelist * |
| 6026 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6027 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6028 | struct lpfc_hba *phba; |
| 6029 | unsigned long flags; |
| 6030 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6031 | if (ndlp) { |
| 6032 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6033 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6034 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6035 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6036 | /* The check of ndlp usage to prevent incrementing the |
| 6037 | * ndlp reference count that is in the process of being |
| 6038 | * released. |
| 6039 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6040 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6041 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6042 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 6043 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6044 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6045 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 6046 | "usgmap:x%x refcnt:%d\n", |
| 6047 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6048 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6049 | return NULL; |
| 6050 | } else |
| 6051 | kref_get(&ndlp->kref); |
| 6052 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6053 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6054 | return ndlp; |
| 6055 | } |
| 6056 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6057 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6058 | * count goes to 0, this indicates the the associated nodelist should be |
| 6059 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 6060 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 6061 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6062 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6063 | int |
| 6064 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6065 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6066 | struct lpfc_hba *phba; |
| 6067 | unsigned long flags; |
| 6068 | |
| 6069 | if (!ndlp) |
| 6070 | return 1; |
| 6071 | |
| 6072 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6073 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6074 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6075 | kref_read(&ndlp->kref)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6076 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6077 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6078 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 6079 | * possible race condition that kref_put got invoked again |
| 6080 | * after previous one has done ndlp memory free. |
| 6081 | */ |
| 6082 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 6083 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6084 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6085 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 6086 | "usgmap:x%x refcnt:%d\n", |
| 6087 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6088 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6089 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6090 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6091 | /* Check the ndlp inactivate log flag to avoid the possible |
| 6092 | * race condition that kref_put got invoked again after ndlp |
| 6093 | * is already in inactivating state. |
| 6094 | */ |
| 6095 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 6096 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6097 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6098 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 6099 | "usgmap:x%x refcnt:%d\n", |
| 6100 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6101 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6102 | return 1; |
| 6103 | } |
| 6104 | /* For last put, mark the ndlp usage flags to make sure no |
| 6105 | * other kref_get and kref_put on the same ndlp shall get |
| 6106 | * in between the process when the final kref_put has been |
| 6107 | * invoked on this ndlp. |
| 6108 | */ |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6109 | if (kref_read(&ndlp->kref) == 1) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6110 | /* Indicate ndlp is put to inactive state. */ |
| 6111 | NLP_SET_IACT_REQ(ndlp); |
| 6112 | /* Acknowledge ndlp memory free has been seen. */ |
| 6113 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 6114 | NLP_SET_FREE_ACK(ndlp); |
| 6115 | } |
| 6116 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6117 | /* Note, the kref_put returns 1 when decrementing a reference |
| 6118 | * count that was 1, it invokes the release callback function, |
| 6119 | * but it still left the reference count as 1 (not actually |
| 6120 | * performs the last decrementation). Otherwise, it actually |
| 6121 | * decrements the reference count and returns 0. |
| 6122 | */ |
| 6123 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6124 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6125 | |
| 6126 | /* 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] | 6127 | * by any other discovery thread. This routine returns 1 if the |
| 6128 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6129 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6130 | */ |
| 6131 | int |
| 6132 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6133 | { |
| 6134 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6135 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6136 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6137 | kref_read(&ndlp->kref)); |
| 6138 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6139 | if (lpfc_nlp_put(ndlp)) |
| 6140 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6141 | return 0; |
| 6142 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6143 | |
| 6144 | /** |
| 6145 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6146 | * @phba: Pointer to hba context object. |
| 6147 | * |
| 6148 | * This function iterate through all FC nodes associated |
| 6149 | * will all vports to check if there is any node with |
| 6150 | * fc_rports associated with it. If there is an fc_rport |
| 6151 | * associated with the node, then the node is either in |
| 6152 | * discovered state or its devloss_timer is pending. |
| 6153 | */ |
| 6154 | static int |
| 6155 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6156 | { |
| 6157 | struct lpfc_vport **vports; |
| 6158 | int i, ret = 0; |
| 6159 | struct lpfc_nodelist *ndlp; |
| 6160 | struct Scsi_Host *shost; |
| 6161 | |
| 6162 | vports = lpfc_create_vport_work_array(phba); |
| 6163 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6164 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6165 | if (!vports) |
| 6166 | return 1; |
| 6167 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6168 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6169 | shost = lpfc_shost_from_vport(vports[i]); |
| 6170 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6171 | /* |
| 6172 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6173 | * flogi. |
| 6174 | * If dev_loss fires while we are waiting we do not want to |
| 6175 | * unreg the fcf. |
| 6176 | */ |
| 6177 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6178 | spin_unlock_irq(shost->host_lock); |
| 6179 | ret = 1; |
| 6180 | goto out; |
| 6181 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6182 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 6183 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 6184 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6185 | ret = 1; |
| 6186 | spin_unlock_irq(shost->host_lock); |
| 6187 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6188 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6189 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6190 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6191 | "2624 RPI %x DID %x flag %x " |
| 6192 | "still logged in\n", |
| 6193 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6194 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6195 | } |
| 6196 | } |
| 6197 | spin_unlock_irq(shost->host_lock); |
| 6198 | } |
| 6199 | out: |
| 6200 | lpfc_destroy_vport_work_array(phba, vports); |
| 6201 | return ret; |
| 6202 | } |
| 6203 | |
| 6204 | /** |
| 6205 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6206 | * @phba: Pointer to hba context object. |
| 6207 | * @mboxq: Pointer to mailbox object. |
| 6208 | * |
| 6209 | * This function frees memory associated with the mailbox command. |
| 6210 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6211 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6212 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6213 | { |
| 6214 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6215 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6216 | |
| 6217 | if (mboxq->u.mb.mbxStatus) { |
| 6218 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6219 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6220 | "HBA state x%x\n", |
| 6221 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6222 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6223 | spin_lock_irq(shost->host_lock); |
| 6224 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6225 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6226 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6227 | return; |
| 6228 | } |
| 6229 | |
| 6230 | /** |
| 6231 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6232 | * @phba: Pointer to hba context object. |
| 6233 | * @mboxq: Pointer to mailbox object. |
| 6234 | * |
| 6235 | * This function frees memory associated with the mailbox command. |
| 6236 | */ |
| 6237 | static void |
| 6238 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6239 | { |
| 6240 | struct lpfc_vport *vport = mboxq->vport; |
| 6241 | |
| 6242 | if (mboxq->u.mb.mbxStatus) { |
| 6243 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6244 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6245 | "HBA state x%x\n", |
| 6246 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6247 | } |
| 6248 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6249 | return; |
| 6250 | } |
| 6251 | |
| 6252 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6253 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6254 | * @phba: Pointer to hba context object. |
| 6255 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6256 | * This function prepare the HBA for unregistering the currently registered |
| 6257 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6258 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6259 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6260 | int |
| 6261 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6262 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6263 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6264 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6265 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6266 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6267 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6268 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6269 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6270 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6271 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6272 | /* At this point, all discovery is aborted */ |
| 6273 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6274 | |
| 6275 | /* Unregister VPIs */ |
| 6276 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6277 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6278 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6279 | /* Stop FLOGI/FDISC retries */ |
| 6280 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6281 | if (ndlp) |
| 6282 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6283 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6284 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6285 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6286 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6287 | shost = lpfc_shost_from_vport(vports[i]); |
| 6288 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6289 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6290 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6291 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6292 | } |
| 6293 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6294 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6295 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6296 | if (ndlp) |
| 6297 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6298 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6299 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6300 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6301 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6302 | shost = lpfc_shost_from_vport(phba->pport); |
| 6303 | spin_lock_irq(shost->host_lock); |
| 6304 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6305 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6306 | spin_unlock_irq(shost->host_lock); |
| 6307 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6308 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6309 | /* Cleanup any outstanding ELS commands */ |
| 6310 | lpfc_els_flush_all_cmd(phba); |
| 6311 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6312 | /* Unregister the physical port VFI */ |
| 6313 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6314 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6315 | } |
| 6316 | |
| 6317 | /** |
| 6318 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6319 | * @phba: Pointer to hba context object. |
| 6320 | * |
| 6321 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6322 | * unregister the currently registered FCF record. The driver does not reset |
| 6323 | * the driver FCF usage state flags. |
| 6324 | * |
| 6325 | * Return 0 if successfully issued, none-zero otherwise. |
| 6326 | */ |
| 6327 | int |
| 6328 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6329 | { |
| 6330 | LPFC_MBOXQ_t *mbox; |
| 6331 | int rc; |
| 6332 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6333 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6334 | if (!mbox) { |
| 6335 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6336 | "2551 UNREG_FCFI mbox allocation failed" |
| 6337 | "HBA state x%x\n", phba->pport->port_state); |
| 6338 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6339 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6340 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6341 | mbox->vport = phba->pport; |
| 6342 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6343 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6344 | |
| 6345 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6346 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6347 | "2552 Unregister FCFI command failed rc x%x " |
| 6348 | "HBA state x%x\n", |
| 6349 | rc, phba->pport->port_state); |
| 6350 | return -EINVAL; |
| 6351 | } |
| 6352 | return 0; |
| 6353 | } |
| 6354 | |
| 6355 | /** |
| 6356 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6357 | * @phba: Pointer to hba context object. |
| 6358 | * |
| 6359 | * This function unregisters the currently reigstered FCF. This function |
| 6360 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6361 | */ |
| 6362 | void |
| 6363 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6364 | { |
| 6365 | int rc; |
| 6366 | |
| 6367 | /* Preparation for unregistering fcf */ |
| 6368 | rc = lpfc_unregister_fcf_prep(phba); |
| 6369 | if (rc) { |
| 6370 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6371 | "2748 Failed to prepare for unregistering " |
| 6372 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6373 | return; |
| 6374 | } |
| 6375 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6376 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6377 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6378 | if (rc) |
| 6379 | return; |
| 6380 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6381 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6382 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6383 | |
| 6384 | /* |
| 6385 | * If driver is not unloading, check if there is any other |
| 6386 | * FCF record that can be used for discovery. |
| 6387 | */ |
| 6388 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6389 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6390 | return; |
| 6391 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6392 | /* This is considered as the initial FCF discovery scan */ |
| 6393 | spin_lock_irq(&phba->hbalock); |
| 6394 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6395 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6396 | |
| 6397 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6398 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6399 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6400 | 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] | 6401 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6402 | if (rc) { |
| 6403 | spin_lock_irq(&phba->hbalock); |
| 6404 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6405 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6406 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6407 | "2553 lpfc_unregister_unused_fcf failed " |
| 6408 | "to read FCF record HBA state x%x\n", |
| 6409 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6410 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6411 | } |
| 6412 | |
| 6413 | /** |
| 6414 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6415 | * @phba: Pointer to hba context object. |
| 6416 | * |
| 6417 | * This function just unregisters the currently reigstered FCF. It does not |
| 6418 | * try to find another FCF for discovery. |
| 6419 | */ |
| 6420 | void |
| 6421 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6422 | { |
| 6423 | int rc; |
| 6424 | |
| 6425 | /* Preparation for unregistering fcf */ |
| 6426 | rc = lpfc_unregister_fcf_prep(phba); |
| 6427 | if (rc) { |
| 6428 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6429 | "2749 Failed to prepare for unregistering " |
| 6430 | "HBA's FCF record: rc=%d\n", rc); |
| 6431 | return; |
| 6432 | } |
| 6433 | |
| 6434 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6435 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6436 | if (rc) |
| 6437 | return; |
| 6438 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6439 | spin_lock_irq(&phba->hbalock); |
| 6440 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6441 | spin_unlock_irq(&phba->hbalock); |
| 6442 | } |
| 6443 | |
| 6444 | /** |
| 6445 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6446 | * @phba: Pointer to hba context object. |
| 6447 | * |
| 6448 | * This function check if there are any connected remote port for the FCF and |
| 6449 | * if all the devices are disconnected, this function unregister FCFI. |
| 6450 | * This function also tries to use another FCF for discovery. |
| 6451 | */ |
| 6452 | void |
| 6453 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6454 | { |
| 6455 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6456 | * If HBA is not running in FIP mode, if HBA does not support |
| 6457 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6458 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6459 | */ |
| 6460 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6461 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6462 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6463 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6464 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6465 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6466 | spin_unlock_irq(&phba->hbalock); |
| 6467 | return; |
| 6468 | } |
| 6469 | spin_unlock_irq(&phba->hbalock); |
| 6470 | |
| 6471 | if (lpfc_fcf_inuse(phba)) |
| 6472 | return; |
| 6473 | |
| 6474 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | /** |
| 6478 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6479 | * @phba: Pointer to hba context object. |
| 6480 | * @buff: Buffer containing the FCF connection table as in the config |
| 6481 | * region. |
| 6482 | * This function create driver data structure for the FCF connection |
| 6483 | * record table read from config region 23. |
| 6484 | */ |
| 6485 | static void |
| 6486 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6487 | uint8_t *buff) |
| 6488 | { |
| 6489 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6490 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6491 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6492 | uint32_t record_count; |
| 6493 | int i; |
| 6494 | |
| 6495 | /* Free the current connect table */ |
| 6496 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6497 | &phba->fcf_conn_rec_list, list) { |
| 6498 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6499 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6500 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6501 | |
| 6502 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6503 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6504 | sizeof(struct lpfc_fcf_conn_rec); |
| 6505 | |
| 6506 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6507 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6508 | |
| 6509 | for (i = 0; i < record_count; i++) { |
| 6510 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6511 | continue; |
| 6512 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6513 | GFP_KERNEL); |
| 6514 | if (!conn_entry) { |
| 6515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6516 | "2566 Failed to allocate connection" |
| 6517 | " table entry\n"); |
| 6518 | return; |
| 6519 | } |
| 6520 | |
| 6521 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6522 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6523 | list_add_tail(&conn_entry->list, |
| 6524 | &phba->fcf_conn_rec_list); |
| 6525 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6526 | |
| 6527 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6528 | i = 0; |
| 6529 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6530 | list) { |
| 6531 | conn_rec = &conn_entry->conn_rec; |
| 6532 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6533 | "3345 FCF connection list rec[%02d]: " |
| 6534 | "flags:x%04x, vtag:x%04x, " |
| 6535 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6536 | "%02x:%02x:%02x:%02x, " |
| 6537 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6538 | "%02x:%02x:%02x:%02x\n", i++, |
| 6539 | conn_rec->flags, conn_rec->vlan_tag, |
| 6540 | conn_rec->fabric_name[0], |
| 6541 | conn_rec->fabric_name[1], |
| 6542 | conn_rec->fabric_name[2], |
| 6543 | conn_rec->fabric_name[3], |
| 6544 | conn_rec->fabric_name[4], |
| 6545 | conn_rec->fabric_name[5], |
| 6546 | conn_rec->fabric_name[6], |
| 6547 | conn_rec->fabric_name[7], |
| 6548 | conn_rec->switch_name[0], |
| 6549 | conn_rec->switch_name[1], |
| 6550 | conn_rec->switch_name[2], |
| 6551 | conn_rec->switch_name[3], |
| 6552 | conn_rec->switch_name[4], |
| 6553 | conn_rec->switch_name[5], |
| 6554 | conn_rec->switch_name[6], |
| 6555 | conn_rec->switch_name[7]); |
| 6556 | } |
| 6557 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | /** |
| 6561 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6562 | * @phba: Pointer to hba context object. |
| 6563 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6564 | * |
| 6565 | * This function update driver data structure with config |
| 6566 | * parameters read from config region 23. |
| 6567 | */ |
| 6568 | static void |
| 6569 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6570 | uint8_t *buff) |
| 6571 | { |
| 6572 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6573 | struct lpfc_fcoe_params *fcoe_param; |
| 6574 | |
| 6575 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6576 | buff; |
| 6577 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6578 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6579 | |
| 6580 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6581 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6582 | return; |
| 6583 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6584 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6585 | phba->valid_vlan = 1; |
| 6586 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6587 | 0xFFF; |
| 6588 | } |
| 6589 | |
| 6590 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6591 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6592 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6593 | return; |
| 6594 | } |
| 6595 | |
| 6596 | /** |
| 6597 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6598 | * @buff: Buffer containing config region 23 data. |
| 6599 | * @size: Size of the data buffer. |
| 6600 | * @rec_type: Record type to be searched. |
| 6601 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6602 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6603 | * of the record specified by record_type. If record found, this |
| 6604 | * function return pointer to the record else return NULL. |
| 6605 | */ |
| 6606 | static uint8_t * |
| 6607 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6608 | { |
| 6609 | uint32_t offset = 0, rec_length; |
| 6610 | |
| 6611 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6612 | (size < sizeof(uint32_t))) |
| 6613 | return NULL; |
| 6614 | |
| 6615 | rec_length = buff[offset + 1]; |
| 6616 | |
| 6617 | /* |
| 6618 | * One TLV record has one word header and number of data words |
| 6619 | * specified in the rec_length field of the record header. |
| 6620 | */ |
| 6621 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6622 | <= size) { |
| 6623 | if (buff[offset] == rec_type) |
| 6624 | return &buff[offset]; |
| 6625 | |
| 6626 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6627 | return NULL; |
| 6628 | |
| 6629 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6630 | rec_length = buff[offset + 1]; |
| 6631 | } |
| 6632 | return NULL; |
| 6633 | } |
| 6634 | |
| 6635 | /** |
| 6636 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6637 | * @phba: Pointer to lpfc_hba data structure. |
| 6638 | * @buff: Buffer containing config region 23 data. |
| 6639 | * @size: Size of the data buffer. |
| 6640 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6641 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6642 | * populate driver data structure with the parameters. |
| 6643 | */ |
| 6644 | void |
| 6645 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6646 | uint8_t *buff, |
| 6647 | uint32_t size) |
| 6648 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6649 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6650 | uint8_t *rec_ptr; |
| 6651 | |
| 6652 | /* |
| 6653 | * If data size is less than 2 words signature and version cannot be |
| 6654 | * verified. |
| 6655 | */ |
| 6656 | if (size < 2*sizeof(uint32_t)) |
| 6657 | return; |
| 6658 | |
| 6659 | /* Check the region signature first */ |
| 6660 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6662 | "2567 Config region 23 has bad signature\n"); |
| 6663 | return; |
| 6664 | } |
| 6665 | |
| 6666 | offset += 4; |
| 6667 | |
| 6668 | /* Check the data structure version */ |
| 6669 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6671 | "2568 Config region 23 has bad version\n"); |
| 6672 | return; |
| 6673 | } |
| 6674 | offset += 4; |
| 6675 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6676 | /* Read FCoE param record */ |
| 6677 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6678 | size - offset, FCOE_PARAM_TYPE); |
| 6679 | if (rec_ptr) |
| 6680 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6681 | |
| 6682 | /* Read FCF connection table */ |
| 6683 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6684 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6685 | if (rec_ptr) |
| 6686 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6687 | |
| 6688 | } |