| 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 | 0c9c6a7 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 696 | if (pring && (status & HA_RXMASK || |
| 697 | pring->flag & LPFC_DEFERRED_RING_EVENT || |
| 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 | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 704 | if (phba->link_state >= LPFC_LINK_UP || |
| 705 | phba->link_flag & LS_MDS_LOOPBACK) { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 706 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 707 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 708 | (status & |
| 709 | HA_RXMASK)); |
| 710 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 711 | } |
Sebastian Herbszt | b103918 | 2015-07-22 10:53:22 +0200 | [diff] [blame] | 712 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 713 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 714 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 715 | /* |
| 716 | * Turn on Ring interrupts |
| 717 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 718 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 719 | spin_lock_irq(&phba->hbalock); |
| 720 | control = readl(phba->HCregaddr); |
| 721 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 722 | lpfc_debugfs_slow_ring_trc(phba, |
| 723 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 724 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 725 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 726 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 727 | writel(control, phba->HCregaddr); |
| 728 | readl(phba->HCregaddr); /* flush */ |
| 729 | } else { |
| 730 | lpfc_debugfs_slow_ring_trc(phba, |
| 731 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 732 | control, ha_copy, 0); |
| 733 | } |
| 734 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | } |
| 736 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 737 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | } |
| 739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | int |
| 741 | lpfc_do_work(void *p) |
| 742 | { |
| 743 | struct lpfc_hba *phba = p; |
| 744 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 746 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 747 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 748 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 750 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 751 | /* wait and check worker queue activities */ |
| 752 | rc = wait_event_interruptible(phba->work_waitq, |
| 753 | (test_and_clear_bit(LPFC_DATA_READY, |
| 754 | &phba->data_flags) |
| 755 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 756 | /* Signal wakeup shall terminate the worker thread */ |
| 757 | if (rc) { |
| 758 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 759 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 763 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 766 | phba->worker_thread = NULL; |
| 767 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 768 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * 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] | 774 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | * embedding it in the IOCB. |
| 776 | */ |
| 777 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 778 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | uint32_t evt) |
| 780 | { |
| 781 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 782 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 786 | * be queued to worker thread for processing |
| 787 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | if (!evtp) |
| 790 | return 0; |
| 791 | |
| 792 | evtp->evt_arg1 = arg1; |
| 793 | evtp->evt_arg2 = arg2; |
| 794 | evtp->evt = evt; |
| 795 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 796 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 797 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 798 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 800 | lpfc_worker_wake_up(phba); |
| 801 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 802 | return 1; |
| 803 | } |
| 804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | void |
| 806 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 807 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 808 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | struct lpfc_hba *phba = vport->phba; |
| 810 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 811 | |
| 812 | 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] | 813 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 814 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 815 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 816 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 817 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 818 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 819 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 820 | lpfc_unreg_rpi(vport, ndlp); |
| 821 | |
| 822 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 823 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 824 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 825 | continue; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 826 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 827 | remove |
| 828 | ? NLP_EVT_DEVICE_RM |
| 829 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 830 | } |
| 831 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 832 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 833 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 834 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 835 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 837 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 841 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 842 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 843 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 844 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 845 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 846 | /* Cleanup any outstanding received buffers */ |
| 847 | lpfc_cleanup_rcv_buffers(vport); |
| 848 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 849 | /* Cleanup any outstanding RSCN activity */ |
| 850 | lpfc_els_flush_rscn(vport); |
| 851 | |
| 852 | /* Cleanup any outstanding ELS commands */ |
| 853 | lpfc_els_flush_cmd(vport); |
| 854 | |
| 855 | lpfc_cleanup_rpis(vport, 0); |
| 856 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 857 | /* Turn off discovery timer if its running */ |
| 858 | lpfc_can_disctmo(vport); |
| 859 | } |
| 860 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 861 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 862 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 863 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 864 | struct lpfc_hba *phba = vport->phba; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 865 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 866 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 867 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 868 | fc_host_post_event(shost, fc_get_event_number(), |
| 869 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 870 | |
| 871 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 872 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 873 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 874 | |
| 875 | lpfc_port_link_failure(vport); |
| 876 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 877 | /* Stop delayed Nport discovery */ |
| 878 | spin_lock_irq(shost->host_lock); |
| 879 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 880 | spin_unlock_irq(shost->host_lock); |
| 881 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 882 | } |
| 883 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 885 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 887 | struct lpfc_vport *vport = phba->pport; |
| 888 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 889 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 890 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 891 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 893 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 895 | |
| 896 | /* Block all SCSI stack I/Os */ |
| 897 | lpfc_scsi_dev_block(phba); |
| 898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 900 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 901 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 902 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 903 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 904 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 905 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 906 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 907 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 908 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 909 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 910 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 911 | /* Issue a LINK DOWN event to all nodes */ |
| 912 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 913 | |
| 914 | vports[i]->fc_myDID = 0; |
| 915 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 916 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 917 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 918 | if (phba->nvmet_support) |
| 919 | lpfc_nvmet_update_targetport(phba); |
| 920 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 921 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 922 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 923 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 924 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 925 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 926 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 928 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 929 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 930 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 931 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 932 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 934 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 939 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 940 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 941 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 943 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 944 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 945 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 947 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | } |
| 949 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 951 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 952 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 954 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | } |
| 956 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 957 | static void |
| 958 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 959 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 960 | struct lpfc_nodelist *ndlp; |
| 961 | |
| 962 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 963 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 964 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 966 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 968 | /* On Linkup its safe to clean up the ndlp |
| 969 | * from Fabric connections. |
| 970 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 971 | if (ndlp->nlp_DID != Fabric_DID) |
| 972 | lpfc_unreg_rpi(vport, ndlp); |
| 973 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 974 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 975 | /* Fail outstanding IO now since device is |
| 976 | * marked for PLOGI. |
| 977 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 978 | lpfc_unreg_rpi(vport, ndlp); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | static void |
| 984 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 985 | { |
| 986 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | struct lpfc_hba *phba = vport->phba; |
| 988 | |
| 989 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 990 | return; |
| 991 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 992 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 993 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 994 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 995 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | /* If NPIV is not enabled, only bring the physical port up */ |
| 997 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 998 | (vport != phba->pport)) |
| 999 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1001 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 1002 | fc_host_post_event(shost, fc_get_event_number(), |
| 1003 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1005 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1006 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1007 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1008 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1009 | vport->fc_ns_retry = 0; |
| 1010 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1012 | if (vport->fc_flag & FC_LBIT) |
| 1013 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int |
| 1018 | lpfc_linkup(struct lpfc_hba *phba) |
| 1019 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1020 | struct lpfc_vport **vports; |
| 1021 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1022 | |
| 1023 | phba->link_state = LPFC_LINK_UP; |
| 1024 | |
| 1025 | /* Unblock fabric iocbs if they are blocked */ |
| 1026 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1027 | del_timer_sync(&phba->fabric_block_timer); |
| 1028 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1029 | vports = lpfc_create_vport_work_array(phba); |
| 1030 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1031 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1032 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1033 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * This routine handles processing a CLEAR_LA mailbox |
| 1040 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1041 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1042 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1044 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1045 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | struct lpfc_vport *vport = pmb->vport; |
| 1048 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1049 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1050 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | uint32_t control; |
| 1052 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1054 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1055 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | |
| 1057 | /* Check for error */ |
| 1058 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1059 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1060 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1061 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1062 | "state x%x\n", |
| 1063 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1064 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | goto out; |
| 1066 | } |
| 1067 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1068 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1069 | phba->link_state = LPFC_HBA_READY; |
| 1070 | |
| 1071 | spin_lock_irq(&phba->hbalock); |
| 1072 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1073 | control = readl(phba->HCregaddr); |
| 1074 | control |= HC_LAINT_ENA; |
| 1075 | writel(control, phba->HCregaddr); |
| 1076 | readl(phba->HCregaddr); /* flush */ |
| 1077 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1078 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1079 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | out: |
| 1082 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1083 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1084 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1085 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1087 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1088 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1089 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1091 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | |
| 1093 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1094 | |
| 1095 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1097 | control = readl(phba->HCregaddr); |
| 1098 | control |= HC_LAINT_ENA; |
| 1099 | writel(control, phba->HCregaddr); |
| 1100 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | |
| 1103 | return; |
| 1104 | } |
| 1105 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1107 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1108 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1111 | uint8_t bbscn = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1113 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1116 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1117 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1118 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1119 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1120 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1121 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1122 | return; |
| 1123 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1124 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1126 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1127 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1128 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1129 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1130 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1131 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1132 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1133 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1136 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1137 | */ |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1138 | if (vport->port_state != LPFC_FLOGI) { |
| 1139 | if (phba->bbcredit_support && phba->cfg_enable_bbcr) { |
| 1140 | bbscn = bf_get(lpfc_bbscn_def, |
| 1141 | &phba->sli4_hba.bbscn_params); |
| 1142 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; |
| 1143 | vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4); |
| 1144 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1145 | lpfc_initial_flogi(vport); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1146 | } else if (vport->fc_flag & FC_PT2PT) { |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1147 | lpfc_disc_start(vport); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 1148 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1149 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1150 | |
| 1151 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1152 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1153 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1154 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1155 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1156 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1157 | |
| 1158 | lpfc_linkdown(phba); |
| 1159 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1160 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1161 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1162 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1164 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | return; |
| 1166 | } |
| 1167 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1168 | /** |
| 1169 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1170 | * @phba pointer to the struct lpfc_hba for this port. |
| 1171 | * This fucnction resets the round robin bit mask and clears the |
| 1172 | * fcf priority list. The list deletions are done while holding the |
| 1173 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1174 | * from the lpfc_fcf_pri record. |
| 1175 | **/ |
| 1176 | void |
| 1177 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1178 | { |
| 1179 | struct lpfc_fcf_pri *fcf_pri; |
| 1180 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1181 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1182 | spin_lock_irq(&phba->hbalock); |
| 1183 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1184 | &phba->fcf.fcf_pri_list, list) { |
| 1185 | list_del_init(&fcf_pri->list); |
| 1186 | fcf_pri->fcf_rec.flag = 0; |
| 1187 | } |
| 1188 | spin_unlock_irq(&phba->hbalock); |
| 1189 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1191 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1192 | { |
| 1193 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1194 | |
| 1195 | if (mboxq->u.mb.mbxStatus) { |
| 1196 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1197 | "2017 REG_FCFI mbxStatus error x%x " |
| 1198 | "HBA state x%x\n", |
| 1199 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1200 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1204 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1205 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1206 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1207 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1208 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1209 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1210 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1211 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1212 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1213 | goto fail_out; |
| 1214 | |
| 1215 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1216 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1217 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1218 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1219 | if (vport->port_state != LPFC_FLOGI) { |
| 1220 | phba->hba_flag |= FCF_RR_INPROG; |
| 1221 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1222 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1223 | goto out; |
| 1224 | } |
| 1225 | spin_unlock_irq(&phba->hbalock); |
| 1226 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1227 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1228 | fail_out: |
| 1229 | spin_lock_irq(&phba->hbalock); |
| 1230 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1231 | spin_unlock_irq(&phba->hbalock); |
| 1232 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1233 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1238 | * @fab_name: pointer to fabric name. |
| 1239 | * @new_fcf_record: pointer to fcf record. |
| 1240 | * |
| 1241 | * This routine compare the fcf record's fabric name with provided |
| 1242 | * fabric name. If the fabric name are identical this function |
| 1243 | * returns 1 else return 0. |
| 1244 | **/ |
| 1245 | static uint32_t |
| 1246 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1247 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1248 | 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] | 1249 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1250 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1251 | return 0; |
| 1252 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1253 | return 0; |
| 1254 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1255 | return 0; |
| 1256 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1257 | return 0; |
| 1258 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1259 | return 0; |
| 1260 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1261 | return 0; |
| 1262 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1263 | return 0; |
| 1264 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1268 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1269 | * @fab_name: pointer to fabric name. |
| 1270 | * @new_fcf_record: pointer to fcf record. |
| 1271 | * |
| 1272 | * This routine compare the fcf record's switch name with provided |
| 1273 | * switch name. If the switch name are identical this function |
| 1274 | * returns 1 else return 0. |
| 1275 | **/ |
| 1276 | static uint32_t |
| 1277 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1278 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1279 | 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] | 1280 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1281 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1282 | return 0; |
| 1283 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1284 | return 0; |
| 1285 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1286 | return 0; |
| 1287 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1288 | return 0; |
| 1289 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1290 | return 0; |
| 1291 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1292 | return 0; |
| 1293 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1294 | return 0; |
| 1295 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1299 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1300 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1301 | * @new_fcf_record: pointer to fcf record. |
| 1302 | * |
| 1303 | * This routine compare the fcf record's mac address with HBA's |
| 1304 | * FCF mac address. If the mac addresses are identical this function |
| 1305 | * returns 1 else return 0. |
| 1306 | **/ |
| 1307 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1308 | 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] | 1309 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1310 | 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] | 1311 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1312 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1313 | return 0; |
| 1314 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1315 | return 0; |
| 1316 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1317 | return 0; |
| 1318 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1319 | return 0; |
| 1320 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1321 | return 0; |
| 1322 | return 1; |
| 1323 | } |
| 1324 | |
| 1325 | static bool |
| 1326 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1327 | { |
| 1328 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1332 | * lpfc_update_fcf_record - Update driver fcf record |
| 1333 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1334 | * @phba: pointer to lpfc hba data structure. |
| 1335 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1336 | * @new_fcf_record: pointer to hba fcf record. |
| 1337 | * |
| 1338 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1339 | * record. This routine is called with the host lock held. |
| 1340 | **/ |
| 1341 | static void |
| 1342 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1343 | struct fcf_record *new_fcf_record |
| 1344 | ) |
| 1345 | { |
| 1346 | struct lpfc_fcf_pri *fcf_pri; |
| 1347 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1348 | lockdep_assert_held(&phba->hbalock); |
| 1349 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1350 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1351 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1352 | /* FCF record priority */ |
| 1353 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1354 | |
| 1355 | } |
| 1356 | |
| 1357 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1358 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1359 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1360 | * @new_fcf_record: pointer to fcf record. |
| 1361 | * |
| 1362 | * This routine copies the FCF information from the FCF |
| 1363 | * record to lpfc_hba data structure. |
| 1364 | **/ |
| 1365 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1366 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1367 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1368 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | /* Fabric name */ |
| 1370 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1371 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1372 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1373 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1374 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1375 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1376 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1377 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1378 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1379 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1380 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1381 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1382 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1383 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1384 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1385 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1386 | /* Mac address */ |
| 1387 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1388 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1389 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1390 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1391 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1392 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1393 | /* FCF record index */ |
| 1394 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1395 | /* FCF record priority */ |
| 1396 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1397 | /* Switch name */ |
| 1398 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1399 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1400 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1401 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1402 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1403 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1404 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1405 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1406 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1407 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1408 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1409 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1410 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1411 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1412 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1413 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1417 | * lpfc_update_fcf_record - Update driver fcf record |
| 1418 | * @phba: pointer to lpfc hba data structure. |
| 1419 | * @fcf_rec: pointer to driver fcf record. |
| 1420 | * @new_fcf_record: pointer to hba fcf record. |
| 1421 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1422 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1423 | * @flag: flag bits to be set to the driver fcf record. |
| 1424 | * |
| 1425 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1426 | * together with the address mode, vlan_id, and other informations. This |
| 1427 | * routine is called with the host lock held. |
| 1428 | **/ |
| 1429 | static void |
| 1430 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1431 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1432 | uint16_t vlan_id, uint32_t flag) |
| 1433 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1434 | lockdep_assert_held(&phba->hbalock); |
| 1435 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1436 | /* Copy the fields from the HBA's FCF record */ |
| 1437 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1438 | /* Update other fields of driver FCF record */ |
| 1439 | fcf_rec->addr_mode = addr_mode; |
| 1440 | fcf_rec->vlan_id = vlan_id; |
| 1441 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1442 | __lpfc_update_fcf_record_pri(phba, |
| 1443 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1444 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1448 | * lpfc_register_fcf - Register the FCF with hba. |
| 1449 | * @phba: pointer to lpfc hba data structure. |
| 1450 | * |
| 1451 | * This routine issues a register fcfi mailbox command to register |
| 1452 | * the fcf with HBA. |
| 1453 | **/ |
| 1454 | static void |
| 1455 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1456 | { |
| 1457 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1458 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1459 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1460 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1461 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1462 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1463 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1464 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1465 | return; |
| 1466 | } |
| 1467 | |
| 1468 | /* The FCF is already registered, start discovery */ |
| 1469 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1470 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1471 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1472 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1473 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1474 | phba->hba_flag |= FCF_RR_INPROG; |
| 1475 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1476 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1480 | return; |
| 1481 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1482 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1483 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1484 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1485 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1486 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1487 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1488 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1489 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1490 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1491 | |
| 1492 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1493 | fcf_mbxq->vport = phba->pport; |
| 1494 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1495 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1496 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1497 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1498 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1499 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1500 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1501 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1502 | |
| 1503 | return; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
| 1507 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1508 | * @phba: pointer to lpfc hba data structure. |
| 1509 | * @new_fcf_record: pointer to fcf record. |
| 1510 | * @boot_flag: Indicates if this record used by boot bios. |
| 1511 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1512 | * @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] | 1513 | * |
| 1514 | * This routine compare the fcf record with connect list obtained from the |
| 1515 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1516 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1517 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1518 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1519 | * used for this FCF when the function returns. |
| 1520 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1521 | * 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] | 1522 | * 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] | 1523 | **/ |
| 1524 | static int |
| 1525 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1526 | struct fcf_record *new_fcf_record, |
| 1527 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1528 | uint16_t *vlan_id) |
| 1529 | { |
| 1530 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1531 | int i, j, fcf_vlan_id = 0; |
| 1532 | |
| 1533 | /* Find the lowest VLAN id in the FCF record */ |
| 1534 | for (i = 0; i < 512; i++) { |
| 1535 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1536 | fcf_vlan_id = i * 8; |
| 1537 | j = 0; |
| 1538 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1539 | j++; |
| 1540 | fcf_vlan_id++; |
| 1541 | } |
| 1542 | break; |
| 1543 | } |
| 1544 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1545 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1546 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1547 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1548 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1549 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1550 | return 0; |
| 1551 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1552 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1553 | *boot_flag = 0; |
| 1554 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1555 | new_fcf_record); |
| 1556 | if (phba->valid_vlan) |
| 1557 | *vlan_id = phba->vlan_id; |
| 1558 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1559 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1560 | return 1; |
| 1561 | } |
| 1562 | |
| 1563 | /* |
| 1564 | * If there are no FCF connection table entry, driver connect to all |
| 1565 | * FCFs. |
| 1566 | */ |
| 1567 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1568 | *boot_flag = 0; |
| 1569 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1570 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1571 | |
| 1572 | /* |
| 1573 | * When there are no FCF connect entries, use driver's default |
| 1574 | * addressing mode - FPMA. |
| 1575 | */ |
| 1576 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1577 | *addr_mode = LPFC_FCF_FPMA; |
| 1578 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1579 | /* If FCF record report a vlan id use that vlan id */ |
| 1580 | if (fcf_vlan_id) |
| 1581 | *vlan_id = fcf_vlan_id; |
| 1582 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1583 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1584 | return 1; |
| 1585 | } |
| 1586 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1587 | list_for_each_entry(conn_entry, |
| 1588 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1589 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1590 | continue; |
| 1591 | |
| 1592 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1593 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1594 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1595 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1596 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1597 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1598 | new_fcf_record)) |
| 1599 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1600 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1601 | /* |
| 1602 | * If the vlan bit map does not have the bit set for the |
| 1603 | * vlan id to be used, then it is not a match. |
| 1604 | */ |
| 1605 | if (!(new_fcf_record->vlan_bitmap |
| 1606 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1607 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
| 1611 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1612 | * If connection record does not support any addressing mode, |
| 1613 | * skip the FCF record. |
| 1614 | */ |
| 1615 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1616 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1617 | continue; |
| 1618 | |
| 1619 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1620 | * Check if the connection record specifies a required |
| 1621 | * addressing mode. |
| 1622 | */ |
| 1623 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1624 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1625 | |
| 1626 | /* |
| 1627 | * If SPMA required but FCF not support this continue. |
| 1628 | */ |
| 1629 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1630 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1631 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1632 | continue; |
| 1633 | |
| 1634 | /* |
| 1635 | * If FPMA required but FCF not support this continue. |
| 1636 | */ |
| 1637 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1638 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1639 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1640 | continue; |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * This fcf record matches filtering criteria. |
| 1645 | */ |
| 1646 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1647 | *boot_flag = 1; |
| 1648 | else |
| 1649 | *boot_flag = 0; |
| 1650 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1651 | /* |
| 1652 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1653 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1654 | * by FCF, allow fabric to pick the addressing mode. |
| 1655 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1656 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1657 | new_fcf_record); |
| 1658 | /* |
| 1659 | * If the user specified a required address mode, assign that |
| 1660 | * address mode |
| 1661 | */ |
| 1662 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1663 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1664 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1665 | FCFCNCT_AM_SPMA) ? |
| 1666 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1667 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1668 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1669 | * addr mode only if FCF support the addr_mode. |
| 1670 | */ |
| 1671 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1672 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1673 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1674 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1675 | *addr_mode = LPFC_FCF_SPMA; |
| 1676 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1677 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1678 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1679 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1680 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1681 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1682 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1683 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1684 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1685 | /* |
| 1686 | * If no vlan id is specified in connect list, use the vlan id |
| 1687 | * in the FCF record |
| 1688 | */ |
| 1689 | else if (fcf_vlan_id) |
| 1690 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1691 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1692 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1693 | |
| 1694 | return 1; |
| 1695 | } |
| 1696 | |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
| 1700 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1701 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1702 | * @phba: pointer to lpfc hba data structure. |
| 1703 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1704 | * |
| 1705 | * This function check if there is any fcoe event pending while driver |
| 1706 | * scan FCF entries. If there is any pending event, it will restart the |
| 1707 | * FCF saning and return 1 else return 0. |
| 1708 | */ |
| 1709 | int |
| 1710 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1711 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1712 | /* |
| 1713 | * If the Link is up and no FCoE events while in the |
| 1714 | * FCF discovery, no need to restart FCF discovery. |
| 1715 | */ |
| 1716 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1717 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1718 | return 0; |
| 1719 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1720 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1721 | "2768 Pending link or FCF event during current " |
| 1722 | "handling of the previous event: link_state:x%x, " |
| 1723 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1724 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1725 | phba->fcoe_eventtag); |
| 1726 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1727 | spin_lock_irq(&phba->hbalock); |
| 1728 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1729 | spin_unlock_irq(&phba->hbalock); |
| 1730 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1731 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1732 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1733 | "2780 Restart FCF table scan due to " |
| 1734 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1735 | "evt_tag_current:x%x\n", |
| 1736 | phba->fcoe_eventtag_at_fcf_scan, |
| 1737 | phba->fcoe_eventtag); |
| 1738 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1739 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1740 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1741 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1742 | * flag |
| 1743 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1744 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1745 | "2833 Stop FCF discovery process due to link " |
| 1746 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1747 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1748 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1749 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1750 | spin_unlock_irq(&phba->hbalock); |
| 1751 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1752 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1753 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1754 | if (unreg_fcf) { |
| 1755 | spin_lock_irq(&phba->hbalock); |
| 1756 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1757 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1758 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1759 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | |
| 1763 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1764 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1765 | * @phba: pointer to lpfc hba data structure. |
| 1766 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1767 | * |
| 1768 | * This function makes an running random selection decision on FCF record to |
| 1769 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1770 | * probability. To perform integer manunipulation of random numbers with |
| 1771 | * 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] | 1772 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1773 | * |
| 1774 | * Returns true when outcome is for the newly read FCF record should be |
| 1775 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1776 | * chosen FCF record. |
| 1777 | **/ |
| 1778 | static bool |
| 1779 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1780 | { |
| 1781 | uint32_t rand_num; |
| 1782 | |
| 1783 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1784 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1785 | |
| 1786 | /* Decision with probability 1/fcf_cnt */ |
| 1787 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1788 | return true; |
| 1789 | else |
| 1790 | return false; |
| 1791 | } |
| 1792 | |
| 1793 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1794 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1795 | * @phba: pointer to lpfc hba data structure. |
| 1796 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1797 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1798 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1799 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1800 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1801 | * SGE parsing, and endianness swapping. |
| 1802 | * |
| 1803 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1804 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1805 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1806 | static struct fcf_record * |
| 1807 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1808 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1809 | { |
| 1810 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1811 | struct lpfc_mbx_sge sge; |
| 1812 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1813 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1814 | union lpfc_sli4_cfg_shdr *shdr; |
| 1815 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1816 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1817 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1818 | * routine only uses a single SGE. |
| 1819 | */ |
| 1820 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1821 | if (unlikely(!mboxq->sge_array)) { |
| 1822 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1823 | "2524 Failed to get the non-embedded SGE " |
| 1824 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1825 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1826 | } |
| 1827 | virt_addr = mboxq->sge_array->addr[0]; |
| 1828 | |
| 1829 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1830 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1831 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1832 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1833 | 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] | 1834 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1835 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1836 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1837 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1838 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1839 | "2726 READ_FCF_RECORD Indicates empty " |
| 1840 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1841 | else |
| 1842 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1843 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1844 | "with status x%x add_status x%x, " |
| 1845 | "mbx\n", shdr_status, shdr_add_status); |
| 1846 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1847 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1848 | |
| 1849 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1850 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1851 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1852 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1853 | *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] | 1854 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1855 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1856 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1857 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1858 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1859 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1860 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1861 | return new_fcf_record; |
| 1862 | } |
| 1863 | |
| 1864 | /** |
| 1865 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1866 | * @phba: pointer to lpfc hba data structure. |
| 1867 | * @fcf_record: pointer to the fcf record. |
| 1868 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1869 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1870 | * |
| 1871 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1872 | * enabled. |
| 1873 | **/ |
| 1874 | static void |
| 1875 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1876 | struct fcf_record *fcf_record, |
| 1877 | uint16_t vlan_id, |
| 1878 | uint16_t next_fcf_index) |
| 1879 | { |
| 1880 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1881 | "2764 READ_FCF_RECORD:\n" |
| 1882 | "\tFCF_Index : x%x\n" |
| 1883 | "\tFCF_Avail : x%x\n" |
| 1884 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1885 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1886 | "\tFIP_Priority : x%x\n" |
| 1887 | "\tMAC_Provider : x%x\n" |
| 1888 | "\tLowest VLANID : x%x\n" |
| 1889 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1890 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1891 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1892 | "\tNext_FCF_Index: x%x\n", |
| 1893 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1894 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1895 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1896 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1897 | fcf_record->fip_priority, |
| 1898 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1899 | vlan_id, |
| 1900 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1901 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1902 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1903 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1904 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1905 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1906 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1907 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1908 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1909 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1910 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1911 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1912 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1913 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1914 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1915 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1916 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1917 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1918 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1919 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1920 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1921 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1922 | next_fcf_index); |
| 1923 | } |
| 1924 | |
| 1925 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1926 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1927 | * @phba: pointer to lpfc hba data structure. |
| 1928 | * @fcf_rec: pointer to an existing FCF record. |
| 1929 | * @new_fcf_record: pointer to a new FCF record. |
| 1930 | * @new_vlan_id: vlan id from the new FCF record. |
| 1931 | * |
| 1932 | * This function performs matching test of a new FCF record against an existing |
| 1933 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1934 | * will not be used as part of the FCF record matching criteria. |
| 1935 | * |
| 1936 | * Returns true if all the fields matching, otherwise returns false. |
| 1937 | */ |
| 1938 | static bool |
| 1939 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1940 | struct lpfc_fcf_rec *fcf_rec, |
| 1941 | struct fcf_record *new_fcf_record, |
| 1942 | uint16_t new_vlan_id) |
| 1943 | { |
| 1944 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1945 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1946 | return false; |
| 1947 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1948 | return false; |
| 1949 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1950 | return false; |
| 1951 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1952 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1953 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1954 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1955 | return true; |
| 1956 | } |
| 1957 | |
| 1958 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1959 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1960 | * @vport: Pointer to vport object. |
| 1961 | * @fcf_index: index to next fcf. |
| 1962 | * |
| 1963 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1964 | * When this function is invoked, there will be a current fcf registered |
| 1965 | * for flogi. |
| 1966 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1967 | * 1 for stop flogi on currently registered fcf; |
| 1968 | */ |
| 1969 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1970 | { |
| 1971 | struct lpfc_hba *phba = vport->phba; |
| 1972 | int rc; |
| 1973 | |
| 1974 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1975 | spin_lock_irq(&phba->hbalock); |
| 1976 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1977 | spin_unlock_irq(&phba->hbalock); |
| 1978 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1979 | "2872 Devloss tmo with no eligible " |
| 1980 | "FCF, unregister in-use FCF (x%x) " |
| 1981 | "and rescan FCF table\n", |
| 1982 | phba->fcf.current_rec.fcf_indx); |
| 1983 | lpfc_unregister_fcf_rescan(phba); |
| 1984 | goto stop_flogi_current_fcf; |
| 1985 | } |
| 1986 | /* Mark the end to FLOGI roundrobin failover */ |
| 1987 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1988 | /* Allow action to new fcf asynchronous event */ |
| 1989 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1990 | spin_unlock_irq(&phba->hbalock); |
| 1991 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1992 | "2865 No FCF available, stop roundrobin FCF " |
| 1993 | "failover and change port state:x%x/x%x\n", |
| 1994 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1995 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1996 | goto stop_flogi_current_fcf; |
| 1997 | } else { |
| 1998 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1999 | "2794 Try FLOGI roundrobin FCF failover to " |
| 2000 | "(x%x)\n", fcf_index); |
| 2001 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 2002 | if (rc) |
| 2003 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 2004 | "2761 FLOGI roundrobin FCF failover " |
| 2005 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 2006 | rc, phba->fcf.current_rec.fcf_indx); |
| 2007 | else |
| 2008 | goto stop_flogi_current_fcf; |
| 2009 | } |
| 2010 | return 0; |
| 2011 | |
| 2012 | stop_flogi_current_fcf: |
| 2013 | lpfc_can_disctmo(vport); |
| 2014 | return 1; |
| 2015 | } |
| 2016 | |
| 2017 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2018 | * lpfc_sli4_fcf_pri_list_del |
| 2019 | * @phba: pointer to lpfc hba data structure. |
| 2020 | * @fcf_index the index of the fcf record to delete |
| 2021 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2022 | * If it is one the list then it is removed from the list, and the flag |
| 2023 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2024 | * record from the list. |
| 2025 | **/ |
| 2026 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2027 | uint16_t fcf_index) |
| 2028 | { |
| 2029 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2030 | |
| 2031 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2032 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2033 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2034 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2035 | new_fcf_pri->fcf_rec.flag); |
| 2036 | spin_lock_irq(&phba->hbalock); |
| 2037 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2038 | if (phba->fcf.current_rec.priority == |
| 2039 | new_fcf_pri->fcf_rec.priority) |
| 2040 | phba->fcf.eligible_fcf_cnt--; |
| 2041 | list_del_init(&new_fcf_pri->list); |
| 2042 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2043 | } |
| 2044 | spin_unlock_irq(&phba->hbalock); |
| 2045 | } |
| 2046 | |
| 2047 | /** |
| 2048 | * lpfc_sli4_set_fcf_flogi_fail |
| 2049 | * @phba: pointer to lpfc hba data structure. |
| 2050 | * @fcf_index the index of the fcf record to update |
| 2051 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2052 | * flag so the the round robin slection for the particular priority level |
| 2053 | * will try a different fcf record that does not have this bit set. |
| 2054 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2055 | * adding it to the priority list. |
| 2056 | **/ |
| 2057 | void |
| 2058 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2059 | { |
| 2060 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2061 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2062 | spin_lock_irq(&phba->hbalock); |
| 2063 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2064 | spin_unlock_irq(&phba->hbalock); |
| 2065 | } |
| 2066 | |
| 2067 | /** |
| 2068 | * lpfc_sli4_fcf_pri_list_add |
| 2069 | * @phba: pointer to lpfc hba data structure. |
| 2070 | * @fcf_index the index of the fcf record to add |
| 2071 | * This routine checks the priority of the fcf_index to be added. |
| 2072 | * If it is a lower priority than the current head of the fcf_pri list |
| 2073 | * then it is added to the list in the right order. |
| 2074 | * If it is the same priority as the current head of the list then it |
| 2075 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2076 | * If the fcf_index to be added is of a higher priority than the current |
| 2077 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2078 | * rr_bmask and it is added to the head of the list. |
| 2079 | * returns: |
| 2080 | * 0=success 1=failure |
| 2081 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2082 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2083 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2084 | struct fcf_record *new_fcf_record) |
| 2085 | { |
| 2086 | uint16_t current_fcf_pri; |
| 2087 | uint16_t last_index; |
| 2088 | struct lpfc_fcf_pri *fcf_pri; |
| 2089 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2090 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2091 | int ret; |
| 2092 | |
| 2093 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2094 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2095 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2096 | fcf_index, new_fcf_record->fip_priority, |
| 2097 | new_fcf_pri->fcf_rec.flag); |
| 2098 | spin_lock_irq(&phba->hbalock); |
| 2099 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2100 | list_del_init(&new_fcf_pri->list); |
| 2101 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2102 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2103 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2104 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2105 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2106 | new_fcf_pri->fcf_rec.fcf_index); |
| 2107 | goto out; |
| 2108 | } |
| 2109 | |
| 2110 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2111 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2112 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2113 | ret = 0; /* Empty rr list */ |
| 2114 | goto out; |
| 2115 | } |
| 2116 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2117 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2118 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2119 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2120 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2121 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2122 | /* fcfs_at_this_priority_level = 1; */ |
| 2123 | phba->fcf.eligible_fcf_cnt = 1; |
| 2124 | } else |
| 2125 | /* fcfs_at_this_priority_level++; */ |
| 2126 | phba->fcf.eligible_fcf_cnt++; |
| 2127 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2128 | new_fcf_pri->fcf_rec.fcf_index); |
| 2129 | goto out; |
| 2130 | } |
| 2131 | |
| 2132 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2133 | &phba->fcf.fcf_pri_list, list) { |
| 2134 | if (new_fcf_pri->fcf_rec.priority <= |
| 2135 | fcf_pri->fcf_rec.priority) { |
| 2136 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2137 | list_add(&new_fcf_pri->list, |
| 2138 | &phba->fcf.fcf_pri_list); |
| 2139 | else |
| 2140 | list_add(&new_fcf_pri->list, |
| 2141 | &((struct lpfc_fcf_pri *) |
| 2142 | fcf_pri->list.prev)->list); |
| 2143 | ret = 0; |
| 2144 | goto out; |
| 2145 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2146 | || new_fcf_pri->fcf_rec.priority < |
| 2147 | next_fcf_pri->fcf_rec.priority) { |
| 2148 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2149 | ret = 0; |
| 2150 | goto out; |
| 2151 | } |
| 2152 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2153 | continue; |
| 2154 | |
| 2155 | } |
| 2156 | ret = 1; |
| 2157 | out: |
| 2158 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2159 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2160 | spin_unlock_irq(&phba->hbalock); |
| 2161 | return ret; |
| 2162 | } |
| 2163 | |
| 2164 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2165 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2166 | * @phba: pointer to lpfc hba data structure. |
| 2167 | * @mboxq: pointer to mailbox object. |
| 2168 | * |
| 2169 | * This function iterates through all the fcf records available in |
| 2170 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2171 | * the FCF for discovery it registers the FCF record and kicks start |
| 2172 | * discovery. |
| 2173 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2174 | * use an FCF record which matches fabric name and mac address of the |
| 2175 | * currently used FCF record. |
| 2176 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2177 | * used by BOOT_BIOS. |
| 2178 | */ |
| 2179 | void |
| 2180 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2181 | { |
| 2182 | struct fcf_record *new_fcf_record; |
| 2183 | uint32_t boot_flag, addr_mode; |
| 2184 | uint16_t fcf_index, next_fcf_index; |
| 2185 | struct lpfc_fcf_rec *fcf_rec = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 2186 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2187 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2188 | int rc; |
| 2189 | |
| 2190 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2191 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2192 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
| 2196 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2197 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2198 | &next_fcf_index); |
| 2199 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2200 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2201 | "2765 Mailbox command READ_FCF_RECORD " |
| 2202 | "failed to retrieve a FCF record.\n"); |
| 2203 | /* Let next new FCF event trigger fast failover */ |
| 2204 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2205 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2206 | spin_unlock_irq(&phba->hbalock); |
| 2207 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2208 | return; |
| 2209 | } |
| 2210 | |
| 2211 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2212 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2213 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2214 | |
| 2215 | /* Log the FCF record information if turned on */ |
| 2216 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2217 | next_fcf_index); |
| 2218 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2219 | /* |
| 2220 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2221 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2222 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2223 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2224 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2225 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2226 | bf_get(lpfc_fcf_record_fcf_index, |
| 2227 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2228 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2229 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2230 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2231 | bf_get(lpfc_fcf_record_fcf_index, |
| 2232 | new_fcf_record), |
| 2233 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2234 | new_fcf_record), |
| 2235 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2236 | new_fcf_record), |
| 2237 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2238 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2239 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2240 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2241 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2242 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2243 | phba->fcf.current_rec.fcf_indx) { |
| 2244 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2245 | "2862 FCF (x%x) matches property " |
| 2246 | "of in-use FCF (x%x)\n", |
| 2247 | bf_get(lpfc_fcf_record_fcf_index, |
| 2248 | new_fcf_record), |
| 2249 | phba->fcf.current_rec.fcf_indx); |
| 2250 | goto read_next_fcf; |
| 2251 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2252 | /* |
| 2253 | * In case the current in-use FCF record becomes |
| 2254 | * invalid/unavailable during FCF discovery that |
| 2255 | * was not triggered by fast FCF failover process, |
| 2256 | * treat it as fast FCF failover. |
| 2257 | */ |
| 2258 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2259 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2260 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2261 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2262 | "(x%x), enter FCF failover " |
| 2263 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2264 | phba->fcf.current_rec.fcf_indx); |
| 2265 | spin_lock_irq(&phba->hbalock); |
| 2266 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2267 | spin_unlock_irq(&phba->hbalock); |
| 2268 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2269 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2270 | LPFC_FCOE_FCF_GET_FIRST); |
| 2271 | return; |
| 2272 | } |
| 2273 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2274 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2275 | } else { |
| 2276 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2277 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2278 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2279 | if (rc) |
| 2280 | goto read_next_fcf; |
| 2281 | } |
| 2282 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2283 | /* |
| 2284 | * 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] | 2285 | * FCF record for the discovery. The condition that a rescan |
| 2286 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2287 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2288 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2289 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2290 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2291 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2292 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2293 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2294 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2295 | phba->fcf.current_rec.fcf_indx) { |
| 2296 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2297 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2298 | /* Stop FCF redisc wait timer */ |
| 2299 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2300 | phba); |
| 2301 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2302 | /* Fast failover, mark completed */ |
| 2303 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2304 | spin_unlock_irq(&phba->hbalock); |
| 2305 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2306 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2307 | "FCF (x%x), port_state:x%x, " |
| 2308 | "fc_flag:x%x\n", |
| 2309 | phba->fcf.current_rec.fcf_indx, |
| 2310 | phba->pport->port_state, |
| 2311 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2312 | goto out; |
| 2313 | } else |
| 2314 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2315 | "2863 New FCF (x%x) matches " |
| 2316 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2317 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2318 | new_fcf_record), |
| 2319 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2320 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2321 | /* |
| 2322 | * Read next FCF record from HBA searching for the matching |
| 2323 | * with in-use record only if not during the fast failover |
| 2324 | * period. In case of fast failover period, it shall try to |
| 2325 | * determine whether the FCF record just read should be the |
| 2326 | * next candidate. |
| 2327 | */ |
| 2328 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2329 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2330 | goto read_next_fcf; |
| 2331 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2332 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2333 | /* |
| 2334 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2335 | * period; otherwise, update on current FCF record. |
| 2336 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2337 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2338 | fcf_rec = &phba->fcf.failover_rec; |
| 2339 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2340 | fcf_rec = &phba->fcf.current_rec; |
| 2341 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2342 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2343 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2344 | * If the driver FCF record does not have boot flag |
| 2345 | * set and new hba fcf record has boot flag set, use |
| 2346 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2347 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2348 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2349 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2350 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2351 | "2837 Update current FCF record " |
| 2352 | "(x%x) with new FCF record (x%x)\n", |
| 2353 | fcf_rec->fcf_indx, |
| 2354 | bf_get(lpfc_fcf_record_fcf_index, |
| 2355 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2356 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2357 | addr_mode, vlan_id, 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 driver FCF record has boot flag set and the |
| 2363 | * new hba FCF record does not have boot flag, read |
| 2364 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2365 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2366 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2367 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2368 | goto read_next_fcf; |
| 2369 | } |
| 2370 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2371 | * If the new hba FCF record has lower priority value |
| 2372 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2373 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2374 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2375 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2376 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2377 | "2838 Update current FCF record " |
| 2378 | "(x%x) with new FCF record (x%x)\n", |
| 2379 | fcf_rec->fcf_indx, |
| 2380 | bf_get(lpfc_fcf_record_fcf_index, |
| 2381 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2382 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2383 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2384 | /* Reset running random FCF selection count */ |
| 2385 | phba->fcf.eligible_fcf_cnt = 1; |
| 2386 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2387 | /* Update running random FCF selection count */ |
| 2388 | phba->fcf.eligible_fcf_cnt++; |
| 2389 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2390 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2391 | if (select_new_fcf) { |
| 2392 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2393 | "2839 Update current FCF record " |
| 2394 | "(x%x) with new FCF record (x%x)\n", |
| 2395 | fcf_rec->fcf_indx, |
| 2396 | bf_get(lpfc_fcf_record_fcf_index, |
| 2397 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2398 | /* Choose the new FCF by random selection */ |
| 2399 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2400 | new_fcf_record, |
| 2401 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2402 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2403 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2404 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2405 | goto read_next_fcf; |
| 2406 | } |
| 2407 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2408 | * This is the first suitable FCF record, choose this record for |
| 2409 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2410 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2411 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2412 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2413 | "2840 Update initial FCF candidate " |
| 2414 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2415 | bf_get(lpfc_fcf_record_fcf_index, |
| 2416 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2417 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2418 | addr_mode, vlan_id, (boot_flag ? |
| 2419 | BOOT_ENABLE : 0)); |
| 2420 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2421 | /* Setup initial running random FCF selection count */ |
| 2422 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2423 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2424 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2425 | goto read_next_fcf; |
| 2426 | |
| 2427 | read_next_fcf: |
| 2428 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2429 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2430 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2431 | /* |
| 2432 | * Case of FCF fast failover scan |
| 2433 | */ |
| 2434 | |
| 2435 | /* |
| 2436 | * It has not found any suitable FCF record, cancel |
| 2437 | * FCF scan inprogress, and do nothing |
| 2438 | */ |
| 2439 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2440 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2441 | "2782 No suitable FCF found: " |
| 2442 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2443 | phba->fcoe_eventtag_at_fcf_scan, |
| 2444 | bf_get(lpfc_fcf_record_fcf_index, |
| 2445 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2446 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2447 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2448 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2449 | spin_unlock_irq(&phba->hbalock); |
| 2450 | /* Unregister in-use FCF and rescan */ |
| 2451 | lpfc_printf_log(phba, KERN_INFO, |
| 2452 | LOG_FIP, |
| 2453 | "2864 On devloss tmo " |
| 2454 | "unreg in-use FCF and " |
| 2455 | "rescan FCF table\n"); |
| 2456 | lpfc_unregister_fcf_rescan(phba); |
| 2457 | return; |
| 2458 | } |
| 2459 | /* |
| 2460 | * Let next new FCF event trigger fast failover |
| 2461 | */ |
| 2462 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2463 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2464 | return; |
| 2465 | } |
| 2466 | /* |
| 2467 | * It has found a suitable FCF record that is not |
| 2468 | * the same as in-use FCF record, unregister the |
| 2469 | * in-use FCF record, replace the in-use FCF record |
| 2470 | * with the new FCF record, mark FCF fast failover |
| 2471 | * completed, and then start register the new FCF |
| 2472 | * record. |
| 2473 | */ |
| 2474 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2475 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2476 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2477 | |
| 2478 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2479 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2480 | "2842 Replace in-use FCF (x%x) " |
| 2481 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2482 | phba->fcf.current_rec.fcf_indx, |
| 2483 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2484 | memcpy(&phba->fcf.current_rec, |
| 2485 | &phba->fcf.failover_rec, |
| 2486 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2487 | /* |
| 2488 | * Mark the fast FCF failover rediscovery completed |
| 2489 | * and the start of the first round of the roundrobin |
| 2490 | * FCF failover. |
| 2491 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2492 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2493 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2494 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2495 | /* Register to the new FCF record */ |
| 2496 | lpfc_register_fcf(phba); |
| 2497 | } else { |
| 2498 | /* |
| 2499 | * In case of transaction period to fast FCF failover, |
| 2500 | * do nothing when search to the end of the FCF table. |
| 2501 | */ |
| 2502 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2503 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2504 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2505 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2506 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2507 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2508 | /* |
| 2509 | * In case the current in-use FCF record no |
| 2510 | * longer existed during FCF discovery that |
| 2511 | * was not triggered by fast FCF failover |
| 2512 | * process, treat it as fast FCF failover. |
| 2513 | */ |
| 2514 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2515 | "2841 In-use FCF record (x%x) " |
| 2516 | "not reported, entering fast " |
| 2517 | "FCF failover mode scanning.\n", |
| 2518 | phba->fcf.current_rec.fcf_indx); |
| 2519 | spin_lock_irq(&phba->hbalock); |
| 2520 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2521 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2522 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2523 | LPFC_FCOE_FCF_GET_FIRST); |
| 2524 | return; |
| 2525 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2526 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2527 | lpfc_register_fcf(phba); |
| 2528 | } |
| 2529 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2530 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2531 | return; |
| 2532 | |
| 2533 | out: |
| 2534 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2535 | lpfc_register_fcf(phba); |
| 2536 | |
| 2537 | return; |
| 2538 | } |
| 2539 | |
| 2540 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2541 | * 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] | 2542 | * @phba: pointer to lpfc hba data structure. |
| 2543 | * @mboxq: pointer to mailbox object. |
| 2544 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2545 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2546 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2547 | * performing the failover. If the FCF read back is not valid/available, it |
| 2548 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2549 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2550 | * newly read FCF record to the failover FCF record, unregister currently |
| 2551 | * registered FCF record, copy the failover FCF record to the current |
| 2552 | * FCF record, and then register the current FCF record before proceeding |
| 2553 | * to trying FLOGI on the new failover FCF. |
| 2554 | */ |
| 2555 | void |
| 2556 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2557 | { |
| 2558 | struct fcf_record *new_fcf_record; |
| 2559 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2560 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2561 | uint16_t current_fcf_index; |
| 2562 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2563 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2564 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2565 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2566 | if (phba->link_state < LPFC_LINK_UP) { |
| 2567 | spin_lock_irq(&phba->hbalock); |
| 2568 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2569 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2570 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2571 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2575 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2576 | &next_fcf_index); |
| 2577 | if (!new_fcf_record) { |
| 2578 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2579 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2580 | "failed to retrieve a FCF record. " |
| 2581 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2582 | phba->fcf.fcf_flag); |
| 2583 | lpfc_unregister_fcf_rescan(phba); |
| 2584 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2588 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2589 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2590 | |
| 2591 | /* Log the FCF record information if turned on */ |
| 2592 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2593 | next_fcf_index); |
| 2594 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2595 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2596 | if (!rc) { |
| 2597 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2598 | "2848 Remove ineligible FCF (x%x) from " |
| 2599 | "from roundrobin bmask\n", fcf_index); |
| 2600 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2601 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2602 | /* Perform next round of roundrobin FCF failover */ |
| 2603 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2604 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2605 | if (rc) |
| 2606 | goto out; |
| 2607 | goto error_out; |
| 2608 | } |
| 2609 | |
| 2610 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2611 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2612 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2613 | "FCF (x%x) back to FCF (x%x)\n", |
| 2614 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2615 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2616 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2617 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2618 | goto out; |
| 2619 | } |
| 2620 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2621 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2622 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2623 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2624 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2625 | spin_lock_irq(&phba->hbalock); |
| 2626 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2627 | new_fcf_record, addr_mode, vlan_id, |
| 2628 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2629 | spin_unlock_irq(&phba->hbalock); |
| 2630 | |
| 2631 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2632 | |
| 2633 | /* Unregister the current in-use FCF record */ |
| 2634 | lpfc_unregister_fcf(phba); |
| 2635 | |
| 2636 | /* Replace in-use record with the new record */ |
| 2637 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2638 | sizeof(struct lpfc_fcf_rec)); |
| 2639 | |
| 2640 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2641 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2642 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2643 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2644 | error_out: |
| 2645 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2646 | out: |
| 2647 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2652 | * @phba: pointer to lpfc hba data structure. |
| 2653 | * @mboxq: pointer to mailbox object. |
| 2654 | * |
| 2655 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2656 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2657 | * failover when a new FCF event happened. If the FCF read back is |
| 2658 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2659 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2660 | */ |
| 2661 | void |
| 2662 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2663 | { |
| 2664 | struct fcf_record *new_fcf_record; |
| 2665 | uint32_t boot_flag, addr_mode; |
| 2666 | uint16_t fcf_index, next_fcf_index; |
| 2667 | uint16_t vlan_id; |
| 2668 | int rc; |
| 2669 | |
| 2670 | /* If link state is not up, no need to proceed */ |
| 2671 | if (phba->link_state < LPFC_LINK_UP) |
| 2672 | goto out; |
| 2673 | |
| 2674 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2675 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2676 | goto out; |
| 2677 | |
| 2678 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2679 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2680 | &next_fcf_index); |
| 2681 | if (!new_fcf_record) { |
| 2682 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2683 | "2767 Mailbox command READ_FCF_RECORD " |
| 2684 | "failed to retrieve a FCF record.\n"); |
| 2685 | goto out; |
| 2686 | } |
| 2687 | |
| 2688 | /* Check the connection list for eligibility */ |
| 2689 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2690 | &addr_mode, &vlan_id); |
| 2691 | |
| 2692 | /* Log the FCF record information if turned on */ |
| 2693 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2694 | next_fcf_index); |
| 2695 | |
| 2696 | if (!rc) |
| 2697 | goto out; |
| 2698 | |
| 2699 | /* Update the eligible FCF record index bmask */ |
| 2700 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2701 | |
| 2702 | 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] | 2703 | |
| 2704 | out: |
| 2705 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2706 | } |
| 2707 | |
| 2708 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2709 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2710 | * @phba: pointer to lpfc hba data structure. |
| 2711 | * @mboxq: pointer to mailbox data structure. |
| 2712 | * |
| 2713 | * This function handles completion of init vfi mailbox command. |
| 2714 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2715 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2716 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2717 | { |
| 2718 | struct lpfc_vport *vport = mboxq->vport; |
| 2719 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2720 | /* |
| 2721 | * VFI not supported on interface type 0, just do the flogi |
| 2722 | * Also continue if the VFI is in use - just use the same one. |
| 2723 | */ |
| 2724 | if (mboxq->u.mb.mbxStatus && |
| 2725 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2726 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2727 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2728 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2729 | LOG_MBOX, |
| 2730 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2731 | mboxq->u.mb.mbxStatus); |
| 2732 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2733 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2734 | return; |
| 2735 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2736 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2737 | lpfc_initial_flogi(vport); |
| 2738 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2739 | return; |
| 2740 | } |
| 2741 | |
| 2742 | /** |
| 2743 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2744 | * @vport: pointer to lpfc_vport data structure. |
| 2745 | * |
| 2746 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2747 | * VPI for the physical port. |
| 2748 | */ |
| 2749 | void |
| 2750 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2751 | { |
| 2752 | LPFC_MBOXQ_t *mboxq; |
| 2753 | int rc; |
| 2754 | struct lpfc_hba *phba = vport->phba; |
| 2755 | |
| 2756 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2757 | if (!mboxq) { |
| 2758 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2759 | LOG_MBOX, "2892 Failed to allocate " |
| 2760 | "init_vfi mailbox\n"); |
| 2761 | return; |
| 2762 | } |
| 2763 | lpfc_init_vfi(mboxq, vport); |
| 2764 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2765 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2766 | if (rc == MBX_NOT_FINISHED) { |
| 2767 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2768 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2769 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2774 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2775 | * @phba: pointer to lpfc hba data structure. |
| 2776 | * @mboxq: pointer to mailbox data structure. |
| 2777 | * |
| 2778 | * This function handles completion of init vpi mailbox command. |
| 2779 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2780 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2781 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2782 | { |
| 2783 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2784 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2785 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2786 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2787 | if (mboxq->u.mb.mbxStatus) { |
| 2788 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2789 | LOG_MBOX, |
| 2790 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2791 | mboxq->u.mb.mbxStatus); |
| 2792 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2793 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2794 | return; |
| 2795 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2796 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2797 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2798 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2799 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2800 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2801 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2802 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2803 | if (!ndlp) |
| 2804 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2805 | LOG_DISCOVERY, |
| 2806 | "2731 Cannot find fabric " |
| 2807 | "controller node\n"); |
| 2808 | else |
| 2809 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2810 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2811 | return; |
| 2812 | } |
| 2813 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2814 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2815 | lpfc_initial_fdisc(vport); |
| 2816 | else { |
| 2817 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2818 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2819 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2820 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2821 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2822 | return; |
| 2823 | } |
| 2824 | |
| 2825 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2826 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2827 | * @vport: pointer to lpfc_vport data structure. |
| 2828 | * |
| 2829 | * This function issue a init_vpi mailbox command to initialize |
| 2830 | * VPI for the vport. |
| 2831 | */ |
| 2832 | void |
| 2833 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2834 | { |
| 2835 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2836 | int rc, vpi; |
| 2837 | |
| 2838 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2839 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2840 | if (!vpi) { |
| 2841 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2842 | LOG_MBOX, |
| 2843 | "3303 Failed to obtain vport vpi\n"); |
| 2844 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2845 | return; |
| 2846 | } |
| 2847 | vport->vpi = vpi; |
| 2848 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2849 | |
| 2850 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2851 | if (!mboxq) { |
| 2852 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2853 | LOG_MBOX, "2607 Failed to allocate " |
| 2854 | "init_vpi mailbox\n"); |
| 2855 | return; |
| 2856 | } |
| 2857 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2858 | mboxq->vport = vport; |
| 2859 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2860 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2861 | if (rc == MBX_NOT_FINISHED) { |
| 2862 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2863 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2864 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2869 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2870 | * @phba: pointer to lpfc hba data structure. |
| 2871 | * |
| 2872 | * This function loops through the list of vports on the @phba and issues an |
| 2873 | * FDISC if possible. |
| 2874 | */ |
| 2875 | void |
| 2876 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2877 | { |
| 2878 | struct lpfc_vport **vports; |
| 2879 | int i; |
| 2880 | |
| 2881 | vports = lpfc_create_vport_work_array(phba); |
| 2882 | if (vports != NULL) { |
| 2883 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2884 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2885 | continue; |
| 2886 | /* There are no vpi for this vport */ |
| 2887 | if (vports[i]->vpi > phba->max_vpi) { |
| 2888 | lpfc_vport_set_state(vports[i], |
| 2889 | FC_VPORT_FAILED); |
| 2890 | continue; |
| 2891 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2892 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2893 | lpfc_vport_set_state(vports[i], |
| 2894 | FC_VPORT_LINKDOWN); |
| 2895 | continue; |
| 2896 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2897 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2898 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2899 | continue; |
| 2900 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2901 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2902 | lpfc_initial_fdisc(vports[i]); |
| 2903 | else { |
| 2904 | lpfc_vport_set_state(vports[i], |
| 2905 | FC_VPORT_NO_FABRIC_SUPP); |
| 2906 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2907 | LOG_ELS, |
| 2908 | "0259 No NPIV " |
| 2909 | "Fabric support\n"); |
| 2910 | } |
| 2911 | } |
| 2912 | } |
| 2913 | lpfc_destroy_vport_work_array(phba, vports); |
| 2914 | } |
| 2915 | |
| 2916 | void |
| 2917 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2918 | { |
| 2919 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2920 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2921 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2922 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2923 | /* |
| 2924 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2925 | * error (except VFI in use) and continue with the discovery. |
| 2926 | */ |
| 2927 | if (mboxq->u.mb.mbxStatus && |
| 2928 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2929 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2930 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2931 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2932 | "2018 REG_VFI mbxStatus error x%x " |
| 2933 | "HBA state x%x\n", |
| 2934 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2935 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2936 | /* FLOGI failed, use loop map to make discovery list */ |
| 2937 | lpfc_disc_list_loopmap(vport); |
| 2938 | /* Start discovery */ |
| 2939 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2940 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2941 | } |
| 2942 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2943 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2944 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2945 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2946 | /* If the VFI is already registered, there is nothing else to do |
| 2947 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2948 | * we should drop through to set the port state to ready. |
| 2949 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2950 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2951 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2952 | vport->fc_flag & FC_PT2PT)) |
| 2953 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2954 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2955 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2956 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2957 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2958 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2959 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2960 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2961 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2962 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2963 | /* In case SLI4 FC loopback test, we are ready */ |
| 2964 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2965 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2966 | phba->link_state = LPFC_HBA_READY; |
| 2967 | goto out_free_mem; |
| 2968 | } |
| 2969 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2970 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2971 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 2972 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 2973 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 2974 | vport->phba->alpa_map[0], |
| 2975 | phba->link_state, phba->fc_topology); |
| 2976 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2977 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2978 | /* |
| 2979 | * For private loop or for NPort pt2pt, |
| 2980 | * just start discovery and we are done. |
| 2981 | */ |
| 2982 | if ((vport->fc_flag & FC_PT2PT) || |
| 2983 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2984 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2985 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2986 | /* Use loop map to make discovery list */ |
| 2987 | lpfc_disc_list_loopmap(vport); |
| 2988 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2989 | if (vport->fc_flag & FC_PT2PT) |
| 2990 | vport->port_state = LPFC_VPORT_READY; |
| 2991 | else |
| 2992 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2993 | } else { |
| 2994 | lpfc_start_fdiscs(phba); |
| 2995 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2996 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2997 | } |
| 2998 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2999 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3000 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 3001 | if (dmabuf) { |
| 3002 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 3003 | kfree(dmabuf); |
| 3004 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3005 | return; |
| 3006 | } |
| 3007 | |
| 3008 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3009 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3011 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | struct lpfc_vport *vport = pmb->vport; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3014 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3015 | struct serv_parm *sp = &vport->fc_sparam; |
| 3016 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | |
| 3018 | /* Check for error */ |
| 3019 | if (mb->mbxStatus) { |
| 3020 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3021 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3022 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3023 | "hba state x%x>\n", |
| 3024 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | goto out; |
| 3027 | } |
| 3028 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3029 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3031 | |
| 3032 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3033 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3034 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3035 | |
| 3036 | phba->fc_edtov = ed_tov; |
| 3037 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3038 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3039 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3040 | phba->fc_ratov = FF_DEF_RATOV; |
| 3041 | } |
| 3042 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3043 | lpfc_update_vport_wwn(vport); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3044 | 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] | 3045 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3046 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3047 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3048 | } |
| 3049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3051 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | return; |
| 3054 | |
| 3055 | out: |
| 3056 | pmb->context1 = NULL; |
| 3057 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3058 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3059 | lpfc_issue_clear_la(phba, vport); |
| 3060 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | return; |
| 3062 | } |
| 3063 | |
| 3064 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3065 | 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] | 3066 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3068 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3069 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3070 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3071 | struct lpfc_dmabuf *mp; |
| 3072 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3073 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3074 | uint32_t fc_flags = 0; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3075 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3076 | spin_lock_irq(&phba->hbalock); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3077 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3078 | |
| 3079 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3080 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3081 | case LPFC_LINK_SPEED_1GHZ: |
| 3082 | case LPFC_LINK_SPEED_2GHZ: |
| 3083 | case LPFC_LINK_SPEED_4GHZ: |
| 3084 | case LPFC_LINK_SPEED_8GHZ: |
| 3085 | case LPFC_LINK_SPEED_10GHZ: |
| 3086 | case LPFC_LINK_SPEED_16GHZ: |
| 3087 | case LPFC_LINK_SPEED_32GHZ: |
| 3088 | break; |
| 3089 | default: |
| 3090 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3091 | break; |
| 3092 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | } |
| 3094 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3095 | if (phba->fc_topology && |
| 3096 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3097 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3098 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3099 | phba->fc_topology, |
| 3100 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3101 | phba->fc_topology_changed = 1; |
| 3102 | } |
| 3103 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3104 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3105 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3107 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3108 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3109 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3111 | /* if npiv is enabled and this adapter supports npiv log |
| 3112 | * a message that npiv is not supported in this topology |
| 3113 | */ |
| 3114 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3115 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3116 | "1309 Link Up Event npiv not supported in loop " |
| 3117 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3118 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3119 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3120 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3122 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3123 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | |
| 3125 | if (i == 0) { |
| 3126 | phba->alpa_map[0] = 0; |
| 3127 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3128 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3129 | int numalpa, j, k; |
| 3130 | union { |
| 3131 | uint8_t pamap[16]; |
| 3132 | struct { |
| 3133 | uint32_t wd1; |
| 3134 | uint32_t wd2; |
| 3135 | uint32_t wd3; |
| 3136 | uint32_t wd4; |
| 3137 | } pa; |
| 3138 | } un; |
| 3139 | numalpa = phba->alpa_map[0]; |
| 3140 | j = 0; |
| 3141 | while (j < numalpa) { |
| 3142 | memset(un.pamap, 0, 16); |
| 3143 | for (k = 1; j < numalpa; k++) { |
| 3144 | un.pamap[k - 1] = |
| 3145 | phba->alpa_map[j + 1]; |
| 3146 | j++; |
| 3147 | if (k == 16) |
| 3148 | break; |
| 3149 | } |
| 3150 | /* Link Up Event ALPA map */ |
| 3151 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3152 | KERN_WARNING, |
| 3153 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3154 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3155 | "ALPA map Data: x%x " |
| 3156 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3157 | un.pa.wd1, un.pa.wd2, |
| 3158 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3163 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3164 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3165 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3166 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3167 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3168 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3169 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3171 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3173 | if (fc_flags) { |
| 3174 | spin_lock_irq(shost->host_lock); |
| 3175 | vport->fc_flag |= fc_flags; |
| 3176 | spin_unlock_irq(shost->host_lock); |
| 3177 | } |
| 3178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3180 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3181 | if (!sparam_mbox) |
| 3182 | goto out; |
| 3183 | |
| 3184 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3185 | if (rc) { |
| 3186 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3187 | goto out; |
| 3188 | } |
| 3189 | sparam_mbox->vport = vport; |
| 3190 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3191 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3192 | if (rc == MBX_NOT_FINISHED) { |
| 3193 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3194 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3195 | kfree(mp); |
| 3196 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3197 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | } |
| 3199 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3200 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3201 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3202 | if (!cfglink_mbox) |
| 3203 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3204 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3207 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3208 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3209 | if (rc == MBX_NOT_FINISHED) { |
| 3210 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3211 | goto out; |
| 3212 | } |
| 3213 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3214 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3215 | /* |
| 3216 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3217 | * is phase 1 implementation that support FCF index 0 and driver |
| 3218 | * defaults. |
| 3219 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3220 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3221 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3222 | GFP_KERNEL); |
| 3223 | if (unlikely(!fcf_record)) { |
| 3224 | lpfc_printf_log(phba, KERN_ERR, |
| 3225 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3226 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3227 | "fcf record\n"); |
| 3228 | rc = -ENODEV; |
| 3229 | goto out; |
| 3230 | } |
| 3231 | |
| 3232 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3233 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3234 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3235 | if (unlikely(rc)) { |
| 3236 | lpfc_printf_log(phba, KERN_ERR, |
| 3237 | LOG_MBOX | LOG_SLI, |
| 3238 | "2013 Could not manually add FCF " |
| 3239 | "record 0, status %d\n", rc); |
| 3240 | rc = -ENODEV; |
| 3241 | kfree(fcf_record); |
| 3242 | goto out; |
| 3243 | } |
| 3244 | kfree(fcf_record); |
| 3245 | } |
| 3246 | /* |
| 3247 | * The driver is expected to do FIP/FCF. Call the port |
| 3248 | * and get the FCF Table. |
| 3249 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3250 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3251 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3252 | spin_unlock_irq(&phba->hbalock); |
| 3253 | return; |
| 3254 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3255 | /* This is the initial FCF discovery scan */ |
| 3256 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3257 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3258 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3259 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3260 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3261 | LPFC_FCOE_FCF_GET_FIRST); |
| 3262 | if (rc) { |
| 3263 | spin_lock_irq(&phba->hbalock); |
| 3264 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3265 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3266 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3267 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3268 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3269 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3271 | |
| 3272 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3273 | out: |
| 3274 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3275 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3276 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3277 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3278 | lpfc_issue_clear_la(phba, vport); |
| 3279 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3283 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3284 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | uint32_t control; |
| 3286 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3289 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3290 | control = readl(phba->HCregaddr); |
| 3291 | control |= HC_LAINT_ENA; |
| 3292 | writel(control, phba->HCregaddr); |
| 3293 | readl(phba->HCregaddr); /* flush */ |
| 3294 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3295 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | } |
| 3297 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3298 | static void |
| 3299 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3300 | { |
| 3301 | lpfc_linkdown(phba); |
| 3302 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3303 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3304 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3305 | } |
| 3306 | |
| 3307 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3309 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3311 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3312 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | */ |
| 3314 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3315 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3317 | struct lpfc_vport *vport = pmb->vport; |
| 3318 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3319 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3320 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3321 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3323 | uint8_t attn_type; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3325 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3326 | pring = lpfc_phba_elsring(phba); |
| 3327 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | /* Check for error */ |
| 3330 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3331 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3332 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3333 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3336 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | } |
| 3338 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3339 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3340 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | |
| 3342 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3345 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3346 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3347 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3348 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3349 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3350 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3351 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | phba->fc_stat.LinkMultiEvent++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3353 | if (attn_type == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | if (phba->fc_eventTag != 0) |
| 3355 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3356 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3357 | |
| 3358 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3359 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3360 | spin_lock_irq(&phba->hbalock); |
| 3361 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3362 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3363 | else |
| 3364 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| 3365 | spin_unlock_irq(&phba->hbalock); |
| 3366 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3368 | phba->link_events++; |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3369 | if ((attn_type == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3370 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3373 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3374 | "1306 Link Up Event in loop back mode " |
| 3375 | "x%x received Data: x%x x%x x%x x%x\n", |
| 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 | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3380 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3381 | } else { |
| 3382 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3383 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3384 | "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] | 3385 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3386 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3387 | la), |
| 3388 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3389 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3390 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3391 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3392 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3393 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3394 | lpfc_mbx_process_link_up(phba, la); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3395 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
| 3396 | attn_type == LPFC_ATT_UNEXP_WWPN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3398 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3399 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3400 | "1308 Link Down Event in loop back mode " |
| 3401 | "x%x received " |
| 3402 | "Data: x%x x%x x%x\n", |
| 3403 | la->eventTag, phba->fc_eventTag, |
| 3404 | phba->pport->port_state, vport->fc_flag); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3405 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
| 3406 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3407 | "1313 Link Down UNEXP WWPN Event x%x received " |
| 3408 | "Data: x%x x%x x%x x%x x%x\n", |
| 3409 | la->eventTag, phba->fc_eventTag, |
| 3410 | phba->pport->port_state, vport->fc_flag, |
| 3411 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3412 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3413 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3414 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3415 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3416 | "Data: x%x x%x x%x x%x x%x\n", |
| 3417 | la->eventTag, phba->fc_eventTag, |
| 3418 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3419 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3420 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3421 | lpfc_mbx_issue_link_down(phba); |
| 3422 | } |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 3423 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
| 3424 | attn_type == LPFC_ATT_LINK_UP) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3425 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3426 | phba->fc_stat.LinkDown++; |
| 3427 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3428 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3430 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3431 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3432 | lpfc_mbx_issue_link_down(phba); |
| 3433 | } else |
| 3434 | lpfc_enable_la(phba); |
| 3435 | |
| 3436 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3437 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3438 | "Data: x%x x%x x%x\n", |
| 3439 | la->eventTag, phba->fc_eventTag, |
| 3440 | phba->pport->port_state, vport->fc_flag); |
| 3441 | /* |
| 3442 | * The cmnd that triggered this will be waiting for this |
| 3443 | * signal. |
| 3444 | */ |
| 3445 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3446 | if (phba->wait_4_mlo_maint_flg) { |
| 3447 | phba->wait_4_mlo_maint_flg = 0; |
| 3448 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3449 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3450 | } |
| 3451 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3452 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3453 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3454 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3455 | lpfc_issue_clear_la(phba, vport); |
| 3456 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3457 | "1311 fa %d\n", |
| 3458 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | } |
| 3460 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3461 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3463 | kfree(mp); |
| 3464 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3465 | return; |
| 3466 | } |
| 3467 | |
| 3468 | /* |
| 3469 | * This routine handles processing a REG_LOGIN mailbox |
| 3470 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3471 | * as the completion routine when the command is |
| 3472 | * handed off to the SLI layer. |
| 3473 | */ |
| 3474 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3475 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3477 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3479 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3480 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3483 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3485 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3486 | "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 3487 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3488 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3489 | ndlp->nlp_usg_map, ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3490 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3491 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3492 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3493 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3494 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3495 | /* We rcvd a rscn after issuing this |
| 3496 | * mbox reg login, we may have cycled |
| 3497 | * back through the state and be |
| 3498 | * back at reg login state so this |
| 3499 | * mbox needs to be ignored becase |
| 3500 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3501 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3502 | */ |
| 3503 | spin_lock_irq(shost->host_lock); |
| 3504 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3505 | spin_unlock_irq(shost->host_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3506 | |
| 3507 | /* |
| 3508 | * We cannot leave the RPI registered because |
| 3509 | * if we go thru discovery again for this ndlp |
| 3510 | * a subsequent REG_RPI will fail. |
| 3511 | */ |
| 3512 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3513 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | /* Call state machine */ |
| 3517 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3518 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3520 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3521 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3522 | /* decrement the node reference count held for this callback |
| 3523 | * function. |
| 3524 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3525 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | |
| 3527 | return; |
| 3528 | } |
| 3529 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3530 | static void |
| 3531 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3532 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3533 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3534 | struct lpfc_vport *vport = pmb->vport; |
| 3535 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3536 | |
| 3537 | switch (mb->mbxStatus) { |
| 3538 | case 0x0011: |
| 3539 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3540 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3541 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3542 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3543 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3544 | /* If VPI is busy, reset the HBA */ |
| 3545 | case 0x9700: |
| 3546 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3547 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3548 | vport->vpi, mb->mbxStatus); |
| 3549 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3550 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3551 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3552 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3553 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3554 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3555 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3556 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3557 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3558 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3559 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3560 | /* |
| 3561 | * This shost reference might have been taken at the beginning of |
| 3562 | * lpfc_vport_delete() |
| 3563 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3564 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3565 | scsi_host_put(shost); |
| 3566 | } |
| 3567 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3568 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3569 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3570 | { |
| 3571 | struct lpfc_hba *phba = vport->phba; |
| 3572 | LPFC_MBOXQ_t *mbox; |
| 3573 | int rc; |
| 3574 | |
| 3575 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3576 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3577 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3578 | |
| 3579 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3580 | mbox->vport = vport; |
| 3581 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3582 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3584 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3585 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3586 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3587 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3588 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3589 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3590 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static void |
| 3594 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3595 | { |
| 3596 | struct lpfc_vport *vport = pmb->vport; |
| 3597 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3598 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3599 | |
| 3600 | switch (mb->mbxStatus) { |
| 3601 | case 0x0011: |
| 3602 | case 0x9601: |
| 3603 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3604 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3605 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3606 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3607 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3608 | spin_lock_irq(shost->host_lock); |
| 3609 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3610 | spin_unlock_irq(shost->host_lock); |
| 3611 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3612 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3613 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3614 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 3615 | if (phba->nvmet_support) |
| 3616 | lpfc_nvmet_update_targetport(phba); |
| 3617 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3618 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3619 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3620 | goto out; |
| 3621 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3622 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3623 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3624 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3625 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3626 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3627 | vport->num_disc_nodes = 0; |
| 3628 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3629 | if (vport->fc_npr_cnt) |
| 3630 | lpfc_els_disc_plogi(vport); |
| 3631 | |
| 3632 | if (!vport->num_disc_nodes) { |
| 3633 | spin_lock_irq(shost->host_lock); |
| 3634 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3635 | spin_unlock_irq(shost->host_lock); |
| 3636 | lpfc_can_disctmo(vport); |
| 3637 | } |
| 3638 | vport->port_state = LPFC_VPORT_READY; |
| 3639 | |
| 3640 | out: |
| 3641 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3642 | return; |
| 3643 | } |
| 3644 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3645 | /** |
| 3646 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3647 | * @phba: pointer to lpfc hba data structure. |
| 3648 | * |
| 3649 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3650 | * the list of static vports to be created. The function create vports |
| 3651 | * based on the information returned from the HBA. |
| 3652 | **/ |
| 3653 | void |
| 3654 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3655 | { |
| 3656 | LPFC_MBOXQ_t *pmb = NULL; |
| 3657 | MAILBOX_t *mb; |
| 3658 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3659 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3660 | struct fc_vport_identifiers vport_id; |
| 3661 | struct fc_vport *new_fc_vport; |
| 3662 | struct Scsi_Host *shost; |
| 3663 | struct lpfc_vport *vport; |
| 3664 | uint16_t offset = 0; |
| 3665 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3666 | struct lpfc_dmabuf *mp; |
| 3667 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3668 | |
| 3669 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3670 | if (!pmb) { |
| 3671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3672 | "0542 lpfc_create_static_vport failed to" |
| 3673 | " allocate mailbox memory\n"); |
| 3674 | return; |
| 3675 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3676 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3677 | mb = &pmb->u.mb; |
| 3678 | |
| 3679 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3680 | if (!vport_info) { |
| 3681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3682 | "0543 lpfc_create_static_vport failed to" |
| 3683 | " allocate vport_info\n"); |
| 3684 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3685 | return; |
| 3686 | } |
| 3687 | |
| 3688 | vport_buff = (uint8_t *) vport_info; |
| 3689 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3690 | /* free dma buffer from previous round */ |
| 3691 | if (pmb->context1) { |
| 3692 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3693 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3694 | kfree(mp); |
| 3695 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3696 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3697 | goto out; |
| 3698 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3699 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3700 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3701 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3702 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3703 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3704 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3705 | "0544 lpfc_create_static_vport failed to" |
| 3706 | " issue dump mailbox command ret 0x%x " |
| 3707 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3708 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3709 | goto out; |
| 3710 | } |
| 3711 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3712 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3713 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3714 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3715 | if (byte_count > sizeof(struct static_vport_info) - |
| 3716 | offset) |
| 3717 | byte_count = sizeof(struct static_vport_info) |
| 3718 | - offset; |
| 3719 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3720 | offset += byte_count; |
| 3721 | } else { |
| 3722 | if (mb->un.varDmp.word_cnt > |
| 3723 | sizeof(struct static_vport_info) - offset) |
| 3724 | mb->un.varDmp.word_cnt = |
| 3725 | sizeof(struct static_vport_info) |
| 3726 | - offset; |
| 3727 | byte_count = mb->un.varDmp.word_cnt; |
| 3728 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3729 | vport_buff + offset, |
| 3730 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3731 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3732 | offset += byte_count; |
| 3733 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3734 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3735 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3736 | offset < sizeof(struct static_vport_info)); |
| 3737 | |
| 3738 | |
| 3739 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3740 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3741 | != VPORT_INFO_REV)) { |
| 3742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3743 | "0545 lpfc_create_static_vport bad" |
| 3744 | " information header 0x%x 0x%x\n", |
| 3745 | le32_to_cpu(vport_info->signature), |
| 3746 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3747 | |
| 3748 | goto out; |
| 3749 | } |
| 3750 | |
| 3751 | shost = lpfc_shost_from_vport(phba->pport); |
| 3752 | |
| 3753 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3754 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3755 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3756 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3757 | if (!vport_id.port_name || !vport_id.node_name) |
| 3758 | continue; |
| 3759 | |
| 3760 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3761 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3762 | vport_id.disable = false; |
| 3763 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3764 | |
| 3765 | if (!new_fc_vport) { |
| 3766 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3767 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3768 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3769 | continue; |
| 3770 | } |
| 3771 | |
| 3772 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3773 | vport->vport_flag |= STATIC_VPORT; |
| 3774 | } |
| 3775 | |
| 3776 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3777 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3778 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3779 | if (pmb->context1) { |
| 3780 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3781 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3782 | kfree(mp); |
| 3783 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3784 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3785 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3786 | |
| 3787 | return; |
| 3788 | } |
| 3789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | /* |
| 3791 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3792 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3793 | * as the completion routine when the command is |
| 3794 | * handed off to the SLI layer. |
| 3795 | */ |
| 3796 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3797 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3799 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3800 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3802 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3803 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3805 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3806 | pmb->context1 = NULL; |
| 3807 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3810 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3811 | "0258 Register Fabric login error: 0x%x\n", |
| 3812 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3814 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3815 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3817 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3818 | /* FLOGI failed, use loop map to make discovery list */ |
| 3819 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3821 | /* Start discovery */ |
| 3822 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3823 | /* Decrement the reference count to ndlp after the |
| 3824 | * reference to the ndlp are done. |
| 3825 | */ |
| 3826 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3827 | return; |
| 3828 | } |
| 3829 | |
| 3830 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3831 | /* Decrement the reference count to ndlp after the reference |
| 3832 | * to the ndlp are done. |
| 3833 | */ |
| 3834 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | return; |
| 3836 | } |
| 3837 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3838 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3839 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3840 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3842 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3843 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3845 | /* when physical port receive logo donot start |
| 3846 | * vport discovery */ |
| 3847 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3848 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3849 | else { |
| 3850 | shost = lpfc_shost_from_vport(vport); |
| 3851 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3852 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3853 | spin_unlock_irq(shost->host_lock); |
| 3854 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3855 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3859 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3860 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3861 | |
| 3862 | /* Drop the reference count from the mbox at the end after |
| 3863 | * all the current reference to the ndlp have been done. |
| 3864 | */ |
| 3865 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | return; |
| 3867 | } |
| 3868 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3869 | /* |
| 3870 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3871 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3872 | */ |
| 3873 | int |
| 3874 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3875 | { |
| 3876 | struct lpfc_hba *phba = vport->phba; |
| 3877 | |
| 3878 | /* Good status, issue CT Request to NameServer */ |
| 3879 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3880 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
| 3881 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3882 | /* Cannot issue NameServer FCP Query, so finish up |
| 3883 | * discovery |
| 3884 | */ |
| 3885 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3886 | "0604 %s FC TYPE %x %s\n", |
| 3887 | "Failed to issue GID_FT to ", |
| 3888 | FC_TYPE_FCP, |
| 3889 | "Finishing discovery."); |
| 3890 | return 0; |
| 3891 | } |
| 3892 | vport->gidft_inp++; |
| 3893 | } |
| 3894 | |
| 3895 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3896 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
| 3897 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 3898 | /* Cannot issue NameServer NVME Query, so finish up |
| 3899 | * discovery |
| 3900 | */ |
| 3901 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3902 | "0605 %s FC_TYPE %x %s %d\n", |
| 3903 | "Failed to issue GID_FT to ", |
| 3904 | FC_TYPE_NVME, |
| 3905 | "Finishing discovery: gidftinp ", |
| 3906 | vport->gidft_inp); |
| 3907 | if (vport->gidft_inp == 0) |
| 3908 | return 0; |
| 3909 | } else |
| 3910 | vport->gidft_inp++; |
| 3911 | } |
| 3912 | return vport->gidft_inp; |
| 3913 | } |
| 3914 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | /* |
| 3916 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3917 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3918 | * as the completion routine when the command is |
| 3919 | * handed off to the SLI layer. |
| 3920 | */ |
| 3921 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3924 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3925 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3926 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3927 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3929 | pmb->context1 = NULL; |
| 3930 | pmb->context2 = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3931 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3932 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3934 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3935 | "0260 Register NameServer error: 0x%x\n", |
| 3936 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3937 | |
| 3938 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3939 | /* decrement the node reference count held for this |
| 3940 | * callback function. |
| 3941 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3942 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3944 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3945 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3946 | |
| 3947 | /* If no other thread is using the ndlp, free it */ |
| 3948 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3950 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3951 | /* |
| 3952 | * RegLogin failed, use loop map to make discovery |
| 3953 | * list |
| 3954 | */ |
| 3955 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3957 | /* Start discovery */ |
| 3958 | lpfc_disc_start(vport); |
| 3959 | return; |
| 3960 | } |
| 3961 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | return; |
| 3963 | } |
| 3964 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3965 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3966 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3967 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3970 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3971 | "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", |
| 3972 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3973 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3974 | ndlp->nlp_usg_map, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3977 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3978 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3979 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3980 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3981 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3982 | |
| 3983 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3984 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
| 3985 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 3986 | |
| 3987 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3988 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3989 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 3990 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3991 | |
| 3992 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3993 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | } |
| 3995 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3996 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3997 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3998 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4000 | /* |
| 4001 | * At this point in time we may need to wait for multiple |
| 4002 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 4003 | * |
| 4004 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4005 | * callback function. |
| 4006 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4007 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4009 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | |
| 4012 | return; |
| 4013 | } |
| 4014 | |
| 4015 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4019 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | struct lpfc_rport_data *rdata; |
| 4021 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4022 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4024 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4025 | return; |
| 4026 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4028 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4029 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | rport_ids.port_id = ndlp->nlp_DID; |
| 4031 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4033 | /* |
| 4034 | * We leave our node pointer in rport->dd_data when we unregister a |
| 4035 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 4036 | * rport->dd_data points. So, if we're reusing a previously |
| 4037 | * registered port, drop the reference that we took the last time we |
| 4038 | * registered the port. |
| 4039 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4040 | rport = ndlp->rport; |
| 4041 | if (rport) { |
| 4042 | rdata = rport->dd_data; |
| 4043 | /* break the link before dropping the ref */ |
| 4044 | ndlp->rport = NULL; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4045 | if (rdata) { |
| 4046 | if (rdata->pnode == ndlp) |
| 4047 | lpfc_nlp_put(ndlp); |
| 4048 | rdata->pnode = NULL; |
| 4049 | } |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4050 | /* drop reference for earlier registeration */ |
| 4051 | put_device(&rport->dev); |
| 4052 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4053 | |
| 4054 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 4055 | "rport add: did:x%x flg:x%x type x%x", |
| 4056 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4057 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4058 | /* Don't add the remote port if unloading. */ |
| 4059 | if (vport->load_flag & FC_UNLOADING) |
| 4060 | return; |
| 4061 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4062 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4063 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4065 | "Warning: fc_remote_port_add failed\n"); |
| 4066 | return; |
| 4067 | } |
| 4068 | |
| 4069 | /* initialize static port data */ |
| 4070 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4071 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4073 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4074 | |
| 4075 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 4076 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 4077 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 4078 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4079 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4080 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4081 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4082 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4083 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4084 | "3183 rport register x%06x, rport %p role x%x\n", |
| 4085 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 4086 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4087 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4088 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4089 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4090 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4091 | return; |
| 4092 | } |
| 4093 | |
| 4094 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4095 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4096 | { |
| 4097 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4098 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4099 | struct lpfc_hba *phba = vport->phba; |
| 4100 | |
| 4101 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4102 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4103 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4104 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4105 | "rport delete: did:x%x flg:x%x type x%x", |
| 4106 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4107 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4108 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4109 | "3184 rport unregister x%06x, rport %p\n", |
| 4110 | ndlp->nlp_DID, rport); |
| 4111 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4112 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | |
| 4114 | return; |
| 4115 | } |
| 4116 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4117 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4118 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4119 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4121 | |
| 4122 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4123 | switch (state) { |
| 4124 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4126 | break; |
| 4127 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4129 | break; |
| 4130 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4131 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4132 | break; |
| 4133 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4135 | break; |
| 4136 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4138 | break; |
| 4139 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4140 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4141 | break; |
| 4142 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4143 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4144 | break; |
| 4145 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4146 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4147 | vport->fc_npr_cnt = 0; |
| 4148 | else |
| 4149 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4150 | break; |
| 4151 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4153 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4154 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4155 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4156 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4157 | int old_state, int new_state) |
| 4158 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4160 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4161 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4162 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4163 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4164 | } |
| 4165 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4166 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4167 | if (new_state == NLP_STE_NPR_NODE) |
| 4168 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4169 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4170 | /* FCP and NVME Transport interface */ |
| 4171 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4172 | old_state == NLP_STE_UNMAPPED_NODE)) { |
| 4173 | if (ndlp->rport) { |
| 4174 | vport->phba->nport_event_cnt++; |
| 4175 | lpfc_unregister_remote_port(ndlp); |
| 4176 | } |
| 4177 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4178 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4179 | vport->phba->nport_event_cnt++; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4180 | if (vport->phba->nvmet_support == 0) |
James Smart | 6599e12 | 2017-06-01 21:07:00 -0700 | [diff] [blame] | 4181 | /* Start devloss */ |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 4182 | lpfc_nvme_unregister_port(vport, ndlp); |
James Smart | 6599e12 | 2017-06-01 21:07:00 -0700 | [diff] [blame] | 4183 | else |
| 4184 | /* NVMET has no upcall. */ |
| 4185 | lpfc_nlp_put(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4186 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4187 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4189 | /* FCP and NVME Transport interfaces */ |
| 4190 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4191 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4192 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 92721c3 | 2017-06-01 21:06:59 -0700 | [diff] [blame] | 4193 | if (ndlp->nlp_fc4_type & NLP_FC4_FCP || |
| 4194 | ndlp->nlp_DID == Fabric_DID || |
| 4195 | ndlp->nlp_DID == NameServer_DID || |
| 4196 | ndlp->nlp_DID == FDMI_DID) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4197 | vport->phba->nport_event_cnt++; |
| 4198 | /* |
| 4199 | * Tell the fc transport about the port, if we haven't |
| 4200 | * already. If we have, and it's a scsi entity, be |
| 4201 | */ |
| 4202 | lpfc_register_remote_port(vport, ndlp); |
| 4203 | } |
| 4204 | /* Notify the NVME transport of this new rport. */ |
James Smart | 09559e8 | 2017-06-15 22:56:46 -0700 | [diff] [blame] | 4205 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
| 4206 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4207 | if (vport->phba->nvmet_support == 0) { |
| 4208 | /* Register this rport with the transport. |
| 4209 | * Initiators take the NDLP ref count in |
| 4210 | * the register. |
| 4211 | */ |
| 4212 | vport->phba->nport_event_cnt++; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4213 | lpfc_nvme_register_port(vport, ndlp); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4214 | } else { |
| 4215 | /* Just take an NDLP ref count since the |
| 4216 | * target does not register rports. |
| 4217 | */ |
| 4218 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4219 | } |
| 4220 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4221 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4222 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4223 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4224 | (vport->stat_data_enabled)) { |
| 4225 | /* |
| 4226 | * A new target is discovered, if there is no buffer for |
| 4227 | * statistical data collection allocate buffer. |
| 4228 | */ |
| 4229 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4230 | sizeof(struct lpfc_scsicmd_bkt), |
| 4231 | GFP_KERNEL); |
| 4232 | |
| 4233 | if (!ndlp->lat_data) |
| 4234 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4235 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4236 | "allocate statistical data buffer DID " |
| 4237 | "0x%x\n", ndlp->nlp_DID); |
| 4238 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4239 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4240 | * If the node just added to Mapped list was an FCP target, |
| 4241 | * but the remote port registration failed or assigned a target |
| 4242 | * id outside the presentable range - move the node to the |
| 4243 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4244 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4245 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4246 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4247 | (!ndlp->rport || |
| 4248 | ndlp->rport->scsi_target_id == -1 || |
| 4249 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4251 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4252 | spin_unlock_irq(shost->host_lock); |
| 4253 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4255 | } |
| 4256 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4257 | static char * |
| 4258 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4259 | { |
| 4260 | static char *states[] = { |
| 4261 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4262 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4263 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4264 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4265 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4266 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4267 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4268 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4269 | [NLP_STE_NPR_NODE] = "NPR", |
| 4270 | }; |
| 4271 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4272 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4273 | strlcpy(buffer, states[state], size); |
| 4274 | else |
| 4275 | snprintf(buffer, size, "unknown (%d)", state); |
| 4276 | return buffer; |
| 4277 | } |
| 4278 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4279 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4280 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4281 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4282 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4283 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4284 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4285 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4286 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4287 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4288 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4289 | ndlp->nlp_DID, |
| 4290 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4291 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4292 | |
| 4293 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4294 | "node statechg did:x%x old:%d ste:%d", |
| 4295 | ndlp->nlp_DID, old_state, state); |
| 4296 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4297 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4298 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4299 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4300 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4301 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4302 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4303 | } |
| 4304 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4305 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | spin_lock_irq(shost->host_lock); |
| 4307 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4308 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4309 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4311 | |
| 4312 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | lpfc_nlp_counters(vport, state, 1); |
| 4314 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4318 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4319 | { |
| 4320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4321 | |
| 4322 | if (list_empty(&ndlp->nlp_listp)) { |
| 4323 | spin_lock_irq(shost->host_lock); |
| 4324 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4325 | spin_unlock_irq(shost->host_lock); |
| 4326 | } |
| 4327 | } |
| 4328 | |
| 4329 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4331 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4333 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4334 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4335 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4336 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4337 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4338 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4340 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4341 | NLP_STE_UNUSED_NODE); |
| 4342 | } |
| 4343 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4344 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4345 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4346 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4347 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4348 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4349 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4350 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4351 | NLP_STE_UNUSED_NODE); |
| 4352 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4354 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4355 | * @vport: Pointer to Virtual Port object. |
| 4356 | * @ndlp: Pointer to FC node object. |
| 4357 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4358 | * |
| 4359 | * This function is always called when node object need to be initialized. |
| 4360 | * It initializes all the fields of the node object. Although the reference |
| 4361 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4362 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4363 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4364 | * the final release of ndlp is determined by its reference count. And, the |
| 4365 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4366 | **/ |
| 4367 | static inline void |
| 4368 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4369 | uint32_t did) |
| 4370 | { |
| 4371 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4372 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
Tomas Jasek | 33cc559 | 2017-03-03 13:45:48 +0100 | [diff] [blame] | 4373 | setup_timer(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, |
| 4374 | (unsigned long)ndlp); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4375 | ndlp->nlp_DID = did; |
| 4376 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4377 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4378 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4379 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4380 | kref_init(&ndlp->kref); |
| 4381 | NLP_INT_NODE_ACT(ndlp); |
| 4382 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4383 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4384 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4385 | |
| 4386 | struct lpfc_nodelist * |
| 4387 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4388 | int state) |
| 4389 | { |
| 4390 | struct lpfc_hba *phba = vport->phba; |
| 4391 | uint32_t did; |
| 4392 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4393 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4394 | int rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4395 | |
| 4396 | if (!ndlp) |
| 4397 | return NULL; |
| 4398 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4399 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4400 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 4401 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 4402 | return NULL; |
| 4403 | } |
| 4404 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4405 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4406 | /* The ndlp should not be in memory free mode */ |
| 4407 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4408 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4409 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4410 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4411 | "usgmap:x%x refcnt:%d\n", |
| 4412 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4413 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4414 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4415 | } |
| 4416 | /* The ndlp should not already be in active mode */ |
| 4417 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4418 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4419 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4420 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4421 | "usgmap:x%x refcnt:%d\n", |
| 4422 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4423 | kref_read(&ndlp->kref)); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4424 | goto free_rpi; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | /* Keep the original DID */ |
| 4428 | did = ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4429 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4430 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4431 | |
| 4432 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4433 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4434 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4435 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4436 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4437 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4438 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4439 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4440 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4441 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4442 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4443 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4444 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4445 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4446 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4447 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4448 | ndlp->nlp_usg_map, ndlp); |
| 4449 | } |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4450 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4451 | |
| 4452 | if (state != NLP_STE_UNUSED_NODE) |
| 4453 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4454 | |
| 4455 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4456 | "node enable: did:x%x", |
| 4457 | ndlp->nlp_DID, 0, 0); |
| 4458 | return ndlp; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4459 | |
| 4460 | free_rpi: |
| 4461 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4462 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 4463 | return NULL; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4467 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4468 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4469 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4470 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4471 | * 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] | 4472 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4473 | * until ALL other outstanding threads have completed. We check |
| 4474 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4475 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4476 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4477 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4478 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4479 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4480 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4481 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4482 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4483 | |
| 4484 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4485 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | /* |
| 4489 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4490 | */ |
| 4491 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4492 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4495 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4496 | uint32_t tmo; |
| 4497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4499 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4500 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4501 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4502 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4503 | * FC spec states we need 3 * ratov for CT requests |
| 4504 | */ |
| 4505 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4508 | |
| 4509 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4510 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4511 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4512 | tmo, vport->port_state, vport->fc_flag); |
| 4513 | } |
| 4514 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4515 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4516 | spin_lock_irq(shost->host_lock); |
| 4517 | vport->fc_flag |= FC_DISC_TMO; |
| 4518 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | |
| 4520 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4521 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4522 | "0247 Start Discovery Timer state x%x " |
| 4523 | "Data: x%x x%lx x%x x%x\n", |
| 4524 | vport->port_state, tmo, |
| 4525 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4526 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | |
| 4528 | return; |
| 4529 | } |
| 4530 | |
| 4531 | /* |
| 4532 | * Cancel rescue timer for Discovery / RSCN handling |
| 4533 | */ |
| 4534 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | unsigned long iflags; |
| 4539 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4541 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4542 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4546 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4547 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4548 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4549 | del_timer_sync(&vport->fc_disctmo); |
| 4550 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4551 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4552 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4556 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4557 | "0248 Cancel Discovery Timer state x%x " |
| 4558 | "Data: x%x x%x x%x\n", |
| 4559 | vport->port_state, vport->fc_flag, |
| 4560 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4561 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | /* |
| 4565 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4566 | * Return true if iocb matches the specified nport |
| 4567 | */ |
| 4568 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4569 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4570 | struct lpfc_sli_ring *pring, |
| 4571 | struct lpfc_iocbq *iocb, |
| 4572 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4574 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4575 | struct lpfc_vport *vport = ndlp->vport; |
| 4576 | |
| 4577 | if (iocb->vport != vport) |
| 4578 | return 0; |
| 4579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4580 | if (pring->ringno == LPFC_ELS_RING) { |
| 4581 | switch (icmd->ulpCommand) { |
| 4582 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4583 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4584 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4585 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4586 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | case CMD_XMIT_ELS_RSP64_CX: |
| 4589 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4590 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4592 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | /* Skip match check if waiting to relogin to FCP target */ |
| 4594 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4595 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4596 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4597 | } |
| 4598 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4599 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4600 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4602 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4603 | } |
| 4604 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4605 | static void |
| 4606 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4607 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4608 | struct list_head *dequeue_list) |
| 4609 | { |
| 4610 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4611 | |
| 4612 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4613 | /* Check to see if iocb matches the nport */ |
| 4614 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4615 | /* match, dequeue */ |
| 4616 | list_move_tail(&iocb->list, dequeue_list); |
| 4617 | } |
| 4618 | } |
| 4619 | |
| 4620 | static void |
| 4621 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4622 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4623 | { |
| 4624 | struct lpfc_sli *psli = &phba->sli; |
| 4625 | uint32_t i; |
| 4626 | |
| 4627 | spin_lock_irq(&phba->hbalock); |
| 4628 | for (i = 0; i < psli->num_rings; i++) |
| 4629 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4630 | dequeue_list); |
| 4631 | spin_unlock_irq(&phba->hbalock); |
| 4632 | } |
| 4633 | |
| 4634 | static void |
| 4635 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4636 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4637 | { |
| 4638 | struct lpfc_sli_ring *pring; |
| 4639 | struct lpfc_queue *qp = NULL; |
| 4640 | |
| 4641 | spin_lock_irq(&phba->hbalock); |
| 4642 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4643 | pring = qp->pring; |
| 4644 | if (!pring) |
| 4645 | continue; |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4646 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4647 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
James Smart | 2ade92a | 2017-03-04 09:30:38 -0800 | [diff] [blame] | 4648 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4649 | } |
| 4650 | spin_unlock_irq(&phba->hbalock); |
| 4651 | } |
| 4652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4653 | /* |
| 4654 | * Free resources / clean up outstanding I/Os |
| 4655 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4656 | */ |
| 4657 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4658 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4660 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4661 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4662 | lpfc_fabric_abort_nport(ndlp); |
| 4663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | /* |
| 4665 | * Everything that matches on txcmplq will be returned |
| 4666 | * by firmware with a no rpi error. |
| 4667 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4668 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4669 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4670 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4671 | else |
| 4672 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4674 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4675 | /* Cancel all the IOCBs from the completions list */ |
| 4676 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4677 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4678 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4679 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | } |
| 4681 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4682 | /** |
| 4683 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4684 | * @phba: Pointer to HBA context object. |
| 4685 | * @pmb: Pointer to mailbox object. |
| 4686 | * |
| 4687 | * This function will issue an ELS LOGO command after completing |
| 4688 | * the UNREG_RPI. |
| 4689 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4690 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4691 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4692 | { |
| 4693 | struct lpfc_vport *vport = pmb->vport; |
| 4694 | struct lpfc_nodelist *ndlp; |
| 4695 | |
| 4696 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4697 | if (!ndlp) |
| 4698 | return; |
| 4699 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4700 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4701 | } |
| 4702 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | /* |
| 4704 | * Free rpi associated with LPFC_NODELIST entry. |
| 4705 | * This routine is called from lpfc_freenode(), when we are removing |
| 4706 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4707 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4708 | * to the remote NPort. In addition, it is called after we receive |
| 4709 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4710 | * we are waiting to PLOGI back to the remote NPort. |
| 4711 | */ |
| 4712 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4713 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4715 | struct lpfc_hba *phba = vport->phba; |
| 4716 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4717 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4718 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4719 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4720 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4721 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4722 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 4723 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4724 | "3366 RPI x%x needs to be " |
| 4725 | "unregistered nlp_flag x%x " |
| 4726 | "did x%x\n", |
| 4727 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4728 | ndlp->nlp_DID); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4729 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4730 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4731 | /* SLI4 ports require the physical rpi value. */ |
| 4732 | rpi = ndlp->nlp_rpi; |
| 4733 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4734 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4735 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4736 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4737 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4738 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4739 | mbox->context1 = ndlp; |
| 4740 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4741 | } else { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4742 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4743 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4744 | (bf_get(lpfc_sli_intf_if_type, |
| 4745 | &phba->sli4_hba.sli_intf) == |
James Smart | a6517db | 2016-03-31 14:12:29 -0700 | [diff] [blame] | 4746 | LPFC_SLI_INTF_IF_TYPE_2) && |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4747 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4748 | mbox->context1 = lpfc_nlp_get(ndlp); |
| 4749 | mbox->mbox_cmpl = |
| 4750 | lpfc_sli4_unreg_rpi_cmpl_clr; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4751 | /* |
| 4752 | * accept PLOGIs after unreg_rpi_cmpl |
| 4753 | */ |
| 4754 | acc_plogi = 0; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4755 | } else |
| 4756 | mbox->mbox_cmpl = |
| 4757 | lpfc_sli_def_mbox_cmpl; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4758 | } |
| 4759 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4760 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4761 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4762 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4763 | acc_plogi = 1; |
| 4764 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4767 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4768 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4769 | ndlp->nlp_rpi = 0; |
| 4770 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4771 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4772 | if (acc_plogi) |
| 4773 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | return 1; |
| 4775 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4776 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | return 0; |
| 4778 | } |
| 4779 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4780 | /** |
| 4781 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4782 | * @phba: pointer to lpfc hba data structure. |
| 4783 | * |
| 4784 | * This routine is invoked to unregister all the currently registered RPIs |
| 4785 | * to the HBA. |
| 4786 | **/ |
| 4787 | void |
| 4788 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4789 | { |
| 4790 | struct lpfc_vport **vports; |
| 4791 | struct lpfc_nodelist *ndlp; |
| 4792 | struct Scsi_Host *shost; |
| 4793 | int i; |
| 4794 | |
| 4795 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4796 | if (!vports) { |
| 4797 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4798 | "2884 Vport array allocation failed \n"); |
| 4799 | return; |
| 4800 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4801 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4802 | shost = lpfc_shost_from_vport(vports[i]); |
| 4803 | spin_lock_irq(shost->host_lock); |
| 4804 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4805 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4806 | /* The mempool_alloc might sleep */ |
| 4807 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4808 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4809 | spin_lock_irq(shost->host_lock); |
| 4810 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4811 | } |
| 4812 | spin_unlock_irq(shost->host_lock); |
| 4813 | } |
| 4814 | lpfc_destroy_vport_work_array(phba, vports); |
| 4815 | } |
| 4816 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4817 | void |
| 4818 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4819 | { |
| 4820 | struct lpfc_hba *phba = vport->phba; |
| 4821 | LPFC_MBOXQ_t *mbox; |
| 4822 | int rc; |
| 4823 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4824 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4825 | lpfc_sli4_unreg_all_rpis(vport); |
| 4826 | return; |
| 4827 | } |
| 4828 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4829 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4830 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4831 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4832 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4833 | mbox->vport = vport; |
| 4834 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4835 | mbox->context1 = NULL; |
| 4836 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4837 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4838 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4839 | |
| 4840 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4841 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4842 | "1836 Could not issue " |
| 4843 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | void |
| 4848 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4849 | { |
| 4850 | struct lpfc_hba *phba = vport->phba; |
| 4851 | LPFC_MBOXQ_t *mbox; |
| 4852 | int rc; |
| 4853 | |
| 4854 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4855 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4856 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4857 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4858 | mbox->vport = vport; |
| 4859 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4860 | mbox->context1 = NULL; |
| 4861 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4862 | if (rc != MBX_TIMEOUT) |
| 4863 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4864 | |
| 4865 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4866 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4867 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4868 | "unreg_did (default rpis) status %d\n", |
| 4869 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | /* |
| 4874 | * Free resources associated with LPFC_NODELIST entry |
| 4875 | * so it can be freed. |
| 4876 | */ |
| 4877 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4878 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4880 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4881 | struct lpfc_hba *phba = vport->phba; |
| 4882 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | |
| 4885 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4886 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4887 | "0900 Cleanup node for NPort x%x " |
| 4888 | "Data: x%x x%x x%x\n", |
| 4889 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4890 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4891 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4892 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4893 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4894 | "usgmap:x%x refcnt:%d\n", |
| 4895 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4896 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4897 | lpfc_dequeue_node(vport, ndlp); |
| 4898 | } else { |
| 4899 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4900 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4901 | "usgmap:x%x refcnt:%d\n", |
| 4902 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4903 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4904 | lpfc_disable_node(vport, ndlp); |
| 4905 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4907 | |
| 4908 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4909 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4911 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4912 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4913 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4914 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4915 | mb->context2 = NULL; |
| 4916 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4917 | } |
| 4918 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4919 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4920 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4921 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4922 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4923 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4924 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4925 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4926 | continue; |
| 4927 | |
| 4928 | mb->context2 = NULL; |
| 4929 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4930 | } |
| 4931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4933 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4934 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4935 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4936 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4937 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4938 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4939 | kfree(mp); |
| 4940 | } |
| 4941 | list_del(&mb->list); |
| 4942 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4943 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4944 | * the ndlp reference count as we are in the process |
| 4945 | * of lpfc_nlp_release. |
| 4946 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | } |
| 4948 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4949 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4950 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4951 | lpfc_els_abort(phba, ndlp); |
| 4952 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4953 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4954 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4955 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4957 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4959 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4960 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4961 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4962 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4963 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4964 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4965 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | /* |
| 4969 | * Check to see if we can free the nlp back to the freelist. |
| 4970 | * If we are in the middle of using the nlp in the discovery state |
| 4971 | * machine, defer the free till we reach the end of the state machine. |
| 4972 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4973 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4974 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4975 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4976 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4977 | struct lpfc_rport_data *rdata; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4978 | struct fc_rport *rport; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4979 | LPFC_MBOXQ_t *mbox; |
| 4980 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4981 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4982 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4983 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4984 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4985 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4986 | /* For this case we need to cleanup the default rpi |
| 4987 | * allocated by the firmware. |
| 4988 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4989 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4990 | "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 4991 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4992 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4993 | ndlp->nlp_usg_map, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4994 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4995 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4996 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4997 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4998 | if (rc) { |
| 4999 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5000 | } |
| 5001 | else { |
| 5002 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 5003 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 5004 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 5005 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 5006 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5007 | if (rc == MBX_NOT_FINISHED) { |
| 5008 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5009 | } |
| 5010 | } |
| 5011 | } |
| 5012 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5013 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5015 | /* |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5016 | * ndlp->rport must be set to NULL before it reaches here |
| 5017 | * i.e. break rport/node link before doing lpfc_nlp_put for |
| 5018 | * registered rport and then drop the reference of rport. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5019 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5020 | if (ndlp->rport) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5021 | /* |
| 5022 | * extra lpfc_nlp_put dropped the reference of ndlp |
| 5023 | * for registered rport so need to cleanup rport |
| 5024 | */ |
| 5025 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 5026 | "0940 removed node x%p DID x%x " |
| 5027 | " rport not null %p\n", |
| 5028 | ndlp, ndlp->nlp_DID, ndlp->rport); |
| 5029 | rport = ndlp->rport; |
| 5030 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5031 | rdata->pnode = NULL; |
| 5032 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 5033 | put_device(&rport->dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5034 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5038 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5039 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5041 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | |
| 5043 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5044 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | /* First check for Direct match */ |
| 5047 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5048 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5049 | |
| 5050 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5051 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5052 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5053 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | matchdid.un.word = did; |
| 5057 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5058 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5059 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5060 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5061 | /* This code is supposed to match the ID |
| 5062 | * for a private loop device that is |
| 5063 | * connect to fl_port. But we need to |
| 5064 | * check that the port did not just go |
| 5065 | * from pt2pt to fabric or we could end |
| 5066 | * up matching ndlp->nlp_DID 000001 to |
| 5067 | * fabric DID 0x20101 |
| 5068 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5069 | if ((ndlpdid.un.b.domain == 0) && |
| 5070 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5071 | if (ndlpdid.un.b.id && |
| 5072 | vport->phba->fc_topology == |
| 5073 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5074 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5075 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5076 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | matchdid.un.word = ndlp->nlp_DID; |
| 5080 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5081 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5082 | if ((matchdid.un.b.domain == 0) && |
| 5083 | (matchdid.un.b.area == 0)) { |
| 5084 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5085 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | } |
| 5087 | } |
| 5088 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5089 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | } |
| 5091 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5092 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5093 | static struct lpfc_nodelist * |
| 5094 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5095 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5096 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | uint32_t data1; |
| 5098 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5099 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5100 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5101 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 5102 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 5103 | ((uint32_t) ndlp->nlp_type << 8) | |
| 5104 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5106 | "0929 FIND node DID " |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5107 | "Data: x%p x%x x%x x%x %p\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5108 | ndlp, ndlp->nlp_DID, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5109 | ndlp->nlp_flag, data1, |
| 5110 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5111 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | } |
| 5113 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5115 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5116 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5117 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | return NULL; |
| 5119 | } |
| 5120 | |
| 5121 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5122 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5123 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5124 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5125 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5126 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5127 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5128 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5129 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5130 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5131 | return ndlp; |
| 5132 | } |
| 5133 | |
| 5134 | struct lpfc_nodelist * |
| 5135 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5136 | { |
| 5137 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5138 | struct lpfc_nodelist *ndlp; |
| 5139 | |
| 5140 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5141 | if (!ndlp) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5142 | if (vport->phba->nvmet_support) |
| 5143 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5144 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5145 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5146 | return NULL; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5147 | ndlp = lpfc_nlp_init(vport, did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | if (!ndlp) |
| 5149 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5150 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5151 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5153 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5154 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5155 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5156 | if (vport->phba->nvmet_support) |
| 5157 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5158 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 5159 | if (!ndlp) |
| 5160 | return NULL; |
| 5161 | spin_lock_irq(shost->host_lock); |
| 5162 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5163 | spin_unlock_irq(shost->host_lock); |
| 5164 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5166 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5167 | /* The NVME Target does not want to actively manage an rport. |
| 5168 | * The goal is to allow the target to reset its state and clear |
| 5169 | * pending IO in preparation for the initiator to recover. |
| 5170 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5171 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5172 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5173 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5174 | |
| 5175 | /* Since this node is marked for discovery, |
| 5176 | * delay timeout is not needed. |
| 5177 | */ |
| 5178 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 5179 | |
| 5180 | /* NVME Target mode waits until rport is known to be |
| 5181 | * impacted by the RSCN before it transitions. No |
| 5182 | * active management - just go to NPR provided the |
| 5183 | * node had a valid login. |
| 5184 | */ |
| 5185 | if (vport->phba->nvmet_support) |
| 5186 | return ndlp; |
| 5187 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5188 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5189 | * we don't need to try to discover it again. |
| 5190 | */ |
| 5191 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 5192 | return NULL; |
| 5193 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5194 | spin_lock_irq(shost->host_lock); |
| 5195 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5196 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 5197 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5199 | } else { |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5200 | /* If the initiator received a PLOGI from this NPort or if the |
| 5201 | * initiator is already in the process of discovery on it, |
| 5202 | * there's no need to try to discover it again. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5203 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5204 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5205 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5206 | (!vport->phba->nvmet_support && |
| 5207 | ndlp->nlp_flag & NLP_RCV_PLOGI)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | return NULL; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5209 | |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5210 | if (vport->phba->nvmet_support) |
| 5211 | return ndlp; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 5212 | |
| 5213 | /* Moving to NPR state clears unsolicited flags and |
| 5214 | * allows for rediscovery |
| 5215 | */ |
| 5216 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5217 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5218 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5219 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5220 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | } |
| 5222 | return ndlp; |
| 5223 | } |
| 5224 | |
| 5225 | /* Build a list of nodes to discover based on the loopmap */ |
| 5226 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5227 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | int j; |
| 5231 | uint32_t alpa, index; |
| 5232 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5235 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5236 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5237 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | |
| 5239 | /* Check for loop map present or not */ |
| 5240 | if (phba->alpa_map[0]) { |
| 5241 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5242 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5245 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5246 | } |
| 5247 | } else { |
| 5248 | /* No alpamap, so try all alpa's */ |
| 5249 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5250 | /* If cfg_scan_down is set, start from highest |
| 5251 | * ALPA (0xef) to lowest (0x1). |
| 5252 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5253 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | index = j; |
| 5255 | else |
| 5256 | index = FC_MAXLOOP - j - 1; |
| 5257 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5258 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5259 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5260 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | } |
| 5262 | } |
| 5263 | return; |
| 5264 | } |
| 5265 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5266 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5268 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5270 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5271 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5272 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5273 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5274 | int rc; |
| 5275 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5276 | /* |
| 5277 | * if it's not a physical port or if we already send |
| 5278 | * clear_la then don't send it. |
| 5279 | */ |
| 5280 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5281 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5282 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5283 | return; |
| 5284 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5285 | /* Link up discovery */ |
| 5286 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5287 | phba->link_state = LPFC_CLEAR_LA; |
| 5288 | lpfc_clear_la(phba, mbox); |
| 5289 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5290 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5291 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5292 | if (rc == MBX_NOT_FINISHED) { |
| 5293 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5294 | lpfc_disc_flush_list(vport); |
| 5295 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5296 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5297 | phba->link_state = LPFC_HBA_ERROR; |
| 5298 | } |
| 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5303 | void |
| 5304 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5305 | { |
| 5306 | LPFC_MBOXQ_t *regvpimbox; |
| 5307 | |
| 5308 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5309 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5310 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5311 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5312 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5313 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5314 | == MBX_NOT_FINISHED) { |
| 5315 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5321 | void |
| 5322 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5323 | { |
| 5324 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5325 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5326 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5327 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5329 | if (!lpfc_is_link_up(phba)) { |
| 5330 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5331 | "3315 Link is not up %x\n", |
| 5332 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5334 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5335 | |
| 5336 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5337 | clear_la_pending = 1; |
| 5338 | else |
| 5339 | clear_la_pending = 0; |
| 5340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5341 | if (vport->port_state < LPFC_VPORT_READY) |
| 5342 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5344 | lpfc_set_disctmo(vport); |
| 5345 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5346 | vport->fc_prevDID = vport->fc_myDID; |
| 5347 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5348 | |
| 5349 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5351 | "0202 Start Discovery hba state x%x " |
| 5352 | "Data: x%x x%x x%x\n", |
| 5353 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 5354 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5355 | |
| 5356 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5357 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5358 | |
| 5359 | if (num_sent) |
| 5360 | return; |
| 5361 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5362 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5363 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5364 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5365 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5366 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5367 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5368 | lpfc_issue_reg_vpi(phba, vport); |
| 5369 | return; |
| 5370 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5372 | /* |
| 5373 | * For SLI2, we need to set port_state to READY and continue |
| 5374 | * discovery. |
| 5375 | */ |
| 5376 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5377 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5378 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5379 | |
| 5380 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5381 | vport->num_disc_nodes = 0; |
| 5382 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5383 | if (vport->fc_npr_cnt) |
| 5384 | lpfc_els_disc_plogi(vport); |
| 5385 | |
| 5386 | if (!vport->num_disc_nodes) { |
| 5387 | spin_lock_irq(shost->host_lock); |
| 5388 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5389 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5390 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5391 | } |
| 5392 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5393 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | } else { |
| 5395 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | |
| 5398 | if (num_sent) |
| 5399 | return; |
| 5400 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5401 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5402 | /* Check to see if more RSCNs came in while we |
| 5403 | * were processing this one. |
| 5404 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5405 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5406 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5407 | spin_lock_irq(shost->host_lock); |
| 5408 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5409 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5410 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5411 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5412 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | return; |
| 5416 | } |
| 5417 | |
| 5418 | /* |
| 5419 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5420 | * ring the match the sppecified nodelist. |
| 5421 | */ |
| 5422 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5423 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5425 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | struct lpfc_sli *psli; |
| 5427 | IOCB_t *icmd; |
| 5428 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5429 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5430 | |
| 5431 | psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5432 | pring = lpfc_phba_elsring(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | |
| 5434 | /* Error matching iocb on txq or txcmplq |
| 5435 | * First check the txq. |
| 5436 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5437 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5439 | if (iocb->context1 != ndlp) { |
| 5440 | continue; |
| 5441 | } |
| 5442 | icmd = &iocb->iocb; |
| 5443 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5444 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5445 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5446 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | } |
| 5448 | } |
| 5449 | |
| 5450 | /* Next check the txcmplq */ |
| 5451 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5452 | if (iocb->context1 != ndlp) { |
| 5453 | continue; |
| 5454 | } |
| 5455 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5456 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5457 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5458 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | } |
| 5460 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5461 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5462 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5463 | /* Cancel all the IOCBs from the completions list */ |
| 5464 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5465 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | } |
| 5467 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5468 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5469 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5470 | { |
| 5471 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5474 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5475 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5476 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5477 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5478 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5479 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5480 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5481 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5483 | } |
| 5484 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | } |
| 5486 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5487 | void |
| 5488 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5489 | { |
| 5490 | lpfc_els_flush_rscn(vport); |
| 5491 | lpfc_els_flush_cmd(vport); |
| 5492 | lpfc_disc_flush_list(vport); |
| 5493 | } |
| 5494 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5495 | /*****************************************************************************/ |
| 5496 | /* |
| 5497 | * NAME: lpfc_disc_timeout |
| 5498 | * |
| 5499 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5500 | * |
| 5501 | * EXECUTION ENVIRONMENT: interrupt only |
| 5502 | * |
| 5503 | * CALLED FROM: |
| 5504 | * Timer function |
| 5505 | * |
| 5506 | * RETURNS: |
| 5507 | * none |
| 5508 | */ |
| 5509 | /*****************************************************************************/ |
| 5510 | void |
| 5511 | lpfc_disc_timeout(unsigned long ptr) |
| 5512 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5514 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5515 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | unsigned long flags = 0; |
| 5517 | |
| 5518 | if (unlikely(!phba)) |
| 5519 | return; |
| 5520 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5521 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5522 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5523 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5524 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5525 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5526 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5527 | if (!tmo_posted) |
| 5528 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5529 | return; |
| 5530 | } |
| 5531 | |
| 5532 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5535 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5536 | struct lpfc_hba *phba = vport->phba; |
| 5537 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5538 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5539 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | int rc, clrlaerr = 0; |
| 5541 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5543 | return; |
| 5544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5545 | spin_lock_irq(shost->host_lock); |
| 5546 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5547 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5549 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5550 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5551 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5553 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | |
| 5555 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5556 | /* |
| 5557 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5558 | * waiting for FAN timeout |
| 5559 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5560 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5561 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5562 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5563 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5565 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5566 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5567 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5568 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5569 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5570 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5571 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5573 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5574 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5575 | /* Fail outstanding IO now since device |
| 5576 | * is marked for PLOGI. |
| 5577 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5579 | } |
| 5580 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5581 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5582 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5583 | lpfc_initial_flogi(vport); |
| 5584 | else |
| 5585 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5586 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5587 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5588 | break; |
| 5589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5590 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5591 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5592 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5594 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5595 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5596 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | |
| 5598 | /* Assume no Fabric and go on with discovery. |
| 5599 | * Check for outstanding ELS FLOGI to abort. |
| 5600 | */ |
| 5601 | |
| 5602 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5603 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5604 | |
| 5605 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5606 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | break; |
| 5608 | |
| 5609 | case LPFC_FABRIC_CFG_LINK: |
| 5610 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5611 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5612 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5613 | "0223 Timeout while waiting for " |
| 5614 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5615 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5616 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5617 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5618 | lpfc_els_abort(phba, ndlp); |
| 5619 | |
| 5620 | /* ReStart discovery */ |
| 5621 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5622 | |
| 5623 | case LPFC_NS_QRY: |
| 5624 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5625 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5626 | "0224 NameServer Query timeout " |
| 5627 | "Data: x%x x%x\n", |
| 5628 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5629 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5630 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5631 | /* Try it one more time */ |
| 5632 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5633 | vport->gidft_inp = 0; |
| 5634 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5635 | if (rc == 0) |
| 5636 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5638 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5639 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5640 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5641 | /* |
| 5642 | * Discovery is over. |
| 5643 | * set port_state to PORT_READY if SLI2. |
| 5644 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5645 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5646 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5647 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5648 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5649 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5650 | lpfc_issue_clear_la(phba, vport); |
| 5651 | vport->port_state = LPFC_VPORT_READY; |
| 5652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5656 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5657 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5658 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5659 | "0206 Device Discovery " |
| 5660 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5661 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5662 | break; |
| 5663 | } |
| 5664 | |
| 5665 | lpfc_linkdown(phba); |
| 5666 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5667 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5668 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5669 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5670 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5671 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5672 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | if (rc == MBX_NOT_FINISHED) |
| 5674 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5675 | |
| 5676 | break; |
| 5677 | |
| 5678 | case LPFC_DISC_AUTH: |
| 5679 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5680 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5681 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5682 | lpfc_disc_flush_list(vport); |
| 5683 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5684 | /* |
| 5685 | * set port_state to PORT_READY if SLI2. |
| 5686 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5687 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5688 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5689 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5690 | lpfc_issue_reg_vpi(phba, vport); |
| 5691 | else { /* NPIV Not enabled */ |
| 5692 | lpfc_issue_clear_la(phba, vport); |
| 5693 | vport->port_state = LPFC_VPORT_READY; |
| 5694 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | } |
| 5696 | break; |
| 5697 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5698 | case LPFC_VPORT_READY: |
| 5699 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5700 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5701 | "0231 RSCN timeout Data: x%x " |
| 5702 | "x%x\n", |
| 5703 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5704 | |
| 5705 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5706 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5707 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5708 | lpfc_els_flush_rscn(vport); |
| 5709 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5710 | } |
| 5711 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5712 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5713 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5714 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5715 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5716 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5717 | break; |
| 5718 | } |
| 5719 | |
| 5720 | switch (phba->link_state) { |
| 5721 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5722 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5723 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5724 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5725 | clrlaerr = 1; |
| 5726 | break; |
| 5727 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5728 | case LPFC_LINK_UP: |
| 5729 | lpfc_issue_clear_la(phba, vport); |
| 5730 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5731 | case LPFC_LINK_UNKNOWN: |
| 5732 | case LPFC_WARM_START: |
| 5733 | case LPFC_INIT_START: |
| 5734 | case LPFC_INIT_MBX_CMDS: |
| 5735 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5736 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5737 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5738 | "0230 Unexpected timeout, hba link " |
| 5739 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5740 | clrlaerr = 1; |
| 5741 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5742 | |
| 5743 | case LPFC_HBA_READY: |
| 5744 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5748 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5749 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 5750 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 5751 | ~LPFC_STOP_IOCB_EVENT; |
| 5752 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 5753 | ~LPFC_STOP_IOCB_EVENT; |
| 5754 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5755 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5756 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5757 | return; |
| 5758 | } |
| 5759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5760 | /* |
| 5761 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5762 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5763 | * as the completion routine when the command is |
| 5764 | * handed off to the SLI layer. |
| 5765 | */ |
| 5766 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5767 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5769 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5770 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5771 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5772 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5773 | |
| 5774 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5775 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5776 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5777 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5778 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5779 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5780 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5781 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5782 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5783 | "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 5784 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5785 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5786 | ndlp->nlp_usg_map, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5787 | /* |
| 5788 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5789 | * 0xfffffa (FDMI well known port). |
| 5790 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 5791 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5792 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5793 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5794 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 5795 | else |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5796 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| 5797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5798 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5799 | /* decrement the node reference count held for this callback |
| 5800 | * function. |
| 5801 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5802 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5803 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5804 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5805 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5806 | |
| 5807 | return; |
| 5808 | } |
| 5809 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5810 | static int |
| 5811 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5812 | { |
| 5813 | uint16_t *rpi = param; |
| 5814 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5815 | /* check for active node */ |
| 5816 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5817 | return 0; |
| 5818 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5819 | return ndlp->nlp_rpi == *rpi; |
| 5820 | } |
| 5821 | |
| 5822 | static int |
| 5823 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5824 | { |
| 5825 | return memcmp(&ndlp->nlp_portname, param, |
| 5826 | sizeof(ndlp->nlp_portname)) == 0; |
| 5827 | } |
| 5828 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5829 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5830 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5831 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5832 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5833 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5834 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5835 | if (filter(ndlp, param)) { |
| 5836 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5837 | "3185 FIND node filter %p DID " |
| 5838 | "Data: x%p x%x x%x\n", |
| 5839 | filter, ndlp, ndlp->nlp_DID, |
| 5840 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5841 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5842 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5843 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5844 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5845 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5846 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5847 | } |
| 5848 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5849 | /* |
| 5850 | * 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] | 5851 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5852 | */ |
| 5853 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5854 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5855 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5856 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5857 | } |
| 5858 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5859 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5860 | * 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] | 5861 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5862 | */ |
| 5863 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5864 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5865 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5867 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5868 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5869 | spin_lock_irq(shost->host_lock); |
| 5870 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5871 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5872 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5873 | } |
| 5874 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5875 | /* |
| 5876 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5877 | * is found, the routine returns the node element list pointer else |
| 5878 | * return NULL. |
| 5879 | */ |
| 5880 | struct lpfc_nodelist * |
| 5881 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5882 | { |
| 5883 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5884 | struct lpfc_nodelist *ndlp; |
| 5885 | |
| 5886 | spin_lock_irq(shost->host_lock); |
| 5887 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5888 | spin_unlock_irq(shost->host_lock); |
| 5889 | return ndlp; |
| 5890 | } |
| 5891 | |
| 5892 | /** |
| 5893 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5894 | * @phba: pointer to lpfc hba data structure. |
| 5895 | * @vpi: the physical host virtual N_Port identifier. |
| 5896 | * |
| 5897 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5898 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5899 | * of the vport with the matching @vpi. |
| 5900 | * |
| 5901 | * Return code |
| 5902 | * NULL - No vport with the matching @vpi found |
| 5903 | * Otherwise - Address to the vport with the matching @vpi. |
| 5904 | **/ |
| 5905 | struct lpfc_vport * |
| 5906 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5907 | { |
| 5908 | struct lpfc_vport *vport; |
| 5909 | unsigned long flags; |
| 5910 | int i = 0; |
| 5911 | |
| 5912 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5913 | if (vpi > 0) { |
| 5914 | /* |
| 5915 | * Translate the physical vpi to the logical vpi. The |
| 5916 | * vport stores the logical vpi. |
| 5917 | */ |
| 5918 | for (i = 0; i < phba->max_vpi; i++) { |
| 5919 | if (vpi == phba->vpi_ids[i]) |
| 5920 | break; |
| 5921 | } |
| 5922 | |
| 5923 | if (i >= phba->max_vpi) { |
| 5924 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5925 | "2936 Could not find Vport mapped " |
| 5926 | "to vpi %d\n", vpi); |
| 5927 | return NULL; |
| 5928 | } |
| 5929 | } |
| 5930 | |
| 5931 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5932 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5933 | if (vport->vpi == i) { |
| 5934 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5935 | return vport; |
| 5936 | } |
| 5937 | } |
| 5938 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5939 | return NULL; |
| 5940 | } |
| 5941 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5942 | struct lpfc_nodelist * |
| 5943 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5944 | { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5945 | struct lpfc_nodelist *ndlp; |
| 5946 | int rpi = LPFC_RPI_ALLOC_ERROR; |
| 5947 | |
| 5948 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 5949 | rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 5950 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 5951 | return NULL; |
| 5952 | } |
| 5953 | |
| 5954 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| 5955 | if (!ndlp) { |
| 5956 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5957 | lpfc_sli4_free_rpi(vport->phba, rpi); |
| 5958 | return NULL; |
| 5959 | } |
| 5960 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5961 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5962 | |
| 5963 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5964 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5965 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5966 | ndlp->nlp_rpi = rpi; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5967 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5968 | "0007 rpi:%x DID:%x flg:%x refcnt:%d " |
| 5969 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5970 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5971 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5972 | ndlp->nlp_usg_map, ndlp); |
| 5973 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5974 | ndlp->active_rrqs_xri_bitmap = |
| 5975 | mempool_alloc(vport->phba->active_rrq_pool, |
| 5976 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 5977 | if (ndlp->active_rrqs_xri_bitmap) |
| 5978 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 5979 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5980 | } |
| 5981 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5982 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5983 | |
| 5984 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5985 | "node init: did:x%x", |
| 5986 | ndlp->nlp_DID, 0, 0); |
| 5987 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5988 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5990 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5991 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5992 | * and mempool_free's the nodelist. |
| 5993 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5994 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5995 | lpfc_nlp_release(struct kref *kref) |
| 5996 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5997 | struct lpfc_hba *phba; |
| 5998 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5999 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 6000 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6001 | |
| 6002 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6003 | "node release: did:x%x flg:x%x type:x%x", |
| 6004 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 6005 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6006 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6007 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 6008 | "usgmap:x%x refcnt:%d rpi:%x\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 6009 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6010 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6011 | |
| 6012 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6013 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6014 | |
| 6015 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6016 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6017 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6018 | NLP_CLR_NODE_ACT(ndlp); |
| 6019 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 6020 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6021 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6022 | |
| 6023 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6024 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 6025 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6026 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6027 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 6028 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6029 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6030 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6031 | } |
| 6032 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6033 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 6034 | * that one discovery thread won't free a ndlp while another discovery thread |
| 6035 | * is using it. |
| 6036 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6037 | struct lpfc_nodelist * |
| 6038 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 6039 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6040 | struct lpfc_hba *phba; |
| 6041 | unsigned long flags; |
| 6042 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6043 | if (ndlp) { |
| 6044 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6045 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 6046 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6047 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6048 | /* The check of ndlp usage to prevent incrementing the |
| 6049 | * ndlp reference count that is in the process of being |
| 6050 | * released. |
| 6051 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6052 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6053 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6054 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 6055 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6056 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6057 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 6058 | "usgmap:x%x refcnt:%d\n", |
| 6059 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6060 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6061 | return NULL; |
| 6062 | } else |
| 6063 | kref_get(&ndlp->kref); |
| 6064 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6065 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6066 | return ndlp; |
| 6067 | } |
| 6068 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6069 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6070 | * count goes to 0, this indicates the the associated nodelist should be |
| 6071 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 6072 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 6073 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6074 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6075 | int |
| 6076 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6077 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6078 | struct lpfc_hba *phba; |
| 6079 | unsigned long flags; |
| 6080 | |
| 6081 | if (!ndlp) |
| 6082 | return 1; |
| 6083 | |
| 6084 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6085 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6086 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6087 | kref_read(&ndlp->kref)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6088 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6089 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6090 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 6091 | * possible race condition that kref_put got invoked again |
| 6092 | * after previous one has done ndlp memory free. |
| 6093 | */ |
| 6094 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 6095 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6096 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6097 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 6098 | "usgmap:x%x refcnt:%d\n", |
| 6099 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6100 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6101 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6102 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6103 | /* Check the ndlp inactivate log flag to avoid the possible |
| 6104 | * race condition that kref_put got invoked again after ndlp |
| 6105 | * is already in inactivating state. |
| 6106 | */ |
| 6107 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 6108 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6109 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6110 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 6111 | "usgmap:x%x refcnt:%d\n", |
| 6112 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6113 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6114 | return 1; |
| 6115 | } |
| 6116 | /* For last put, mark the ndlp usage flags to make sure no |
| 6117 | * other kref_get and kref_put on the same ndlp shall get |
| 6118 | * in between the process when the final kref_put has been |
| 6119 | * invoked on this ndlp. |
| 6120 | */ |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6121 | if (kref_read(&ndlp->kref) == 1) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6122 | /* Indicate ndlp is put to inactive state. */ |
| 6123 | NLP_SET_IACT_REQ(ndlp); |
| 6124 | /* Acknowledge ndlp memory free has been seen. */ |
| 6125 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 6126 | NLP_SET_FREE_ACK(ndlp); |
| 6127 | } |
| 6128 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6129 | /* Note, the kref_put returns 1 when decrementing a reference |
| 6130 | * count that was 1, it invokes the release callback function, |
| 6131 | * but it still left the reference count as 1 (not actually |
| 6132 | * performs the last decrementation). Otherwise, it actually |
| 6133 | * decrements the reference count and returns 0. |
| 6134 | */ |
| 6135 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6136 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6137 | |
| 6138 | /* 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] | 6139 | * by any other discovery thread. This routine returns 1 if the |
| 6140 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6141 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6142 | */ |
| 6143 | int |
| 6144 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6145 | { |
| 6146 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6147 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6148 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6149 | kref_read(&ndlp->kref)); |
| 6150 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6151 | if (lpfc_nlp_put(ndlp)) |
| 6152 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6153 | return 0; |
| 6154 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6155 | |
| 6156 | /** |
| 6157 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6158 | * @phba: Pointer to hba context object. |
| 6159 | * |
| 6160 | * This function iterate through all FC nodes associated |
| 6161 | * will all vports to check if there is any node with |
| 6162 | * fc_rports associated with it. If there is an fc_rport |
| 6163 | * associated with the node, then the node is either in |
| 6164 | * discovered state or its devloss_timer is pending. |
| 6165 | */ |
| 6166 | static int |
| 6167 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6168 | { |
| 6169 | struct lpfc_vport **vports; |
| 6170 | int i, ret = 0; |
| 6171 | struct lpfc_nodelist *ndlp; |
| 6172 | struct Scsi_Host *shost; |
| 6173 | |
| 6174 | vports = lpfc_create_vport_work_array(phba); |
| 6175 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6176 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6177 | if (!vports) |
| 6178 | return 1; |
| 6179 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6180 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6181 | shost = lpfc_shost_from_vport(vports[i]); |
| 6182 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6183 | /* |
| 6184 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6185 | * flogi. |
| 6186 | * If dev_loss fires while we are waiting we do not want to |
| 6187 | * unreg the fcf. |
| 6188 | */ |
| 6189 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6190 | spin_unlock_irq(shost->host_lock); |
| 6191 | ret = 1; |
| 6192 | goto out; |
| 6193 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6194 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 6195 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 6196 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6197 | ret = 1; |
| 6198 | spin_unlock_irq(shost->host_lock); |
| 6199 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6200 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6201 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6202 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6203 | "2624 RPI %x DID %x flag %x " |
| 6204 | "still logged in\n", |
| 6205 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6206 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6207 | } |
| 6208 | } |
| 6209 | spin_unlock_irq(shost->host_lock); |
| 6210 | } |
| 6211 | out: |
| 6212 | lpfc_destroy_vport_work_array(phba, vports); |
| 6213 | return ret; |
| 6214 | } |
| 6215 | |
| 6216 | /** |
| 6217 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6218 | * @phba: Pointer to hba context object. |
| 6219 | * @mboxq: Pointer to mailbox object. |
| 6220 | * |
| 6221 | * This function frees memory associated with the mailbox command. |
| 6222 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6223 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6224 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6225 | { |
| 6226 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6227 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6228 | |
| 6229 | if (mboxq->u.mb.mbxStatus) { |
| 6230 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6231 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6232 | "HBA state x%x\n", |
| 6233 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6234 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6235 | spin_lock_irq(shost->host_lock); |
| 6236 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6237 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6238 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6239 | return; |
| 6240 | } |
| 6241 | |
| 6242 | /** |
| 6243 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6244 | * @phba: Pointer to hba context object. |
| 6245 | * @mboxq: Pointer to mailbox object. |
| 6246 | * |
| 6247 | * This function frees memory associated with the mailbox command. |
| 6248 | */ |
| 6249 | static void |
| 6250 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6251 | { |
| 6252 | struct lpfc_vport *vport = mboxq->vport; |
| 6253 | |
| 6254 | if (mboxq->u.mb.mbxStatus) { |
| 6255 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6256 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6257 | "HBA state x%x\n", |
| 6258 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6259 | } |
| 6260 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6261 | return; |
| 6262 | } |
| 6263 | |
| 6264 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6265 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6266 | * @phba: Pointer to hba context object. |
| 6267 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6268 | * This function prepare the HBA for unregistering the currently registered |
| 6269 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6270 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6271 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6272 | int |
| 6273 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6274 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6275 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6276 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6277 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6278 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6279 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6280 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6281 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6282 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6283 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6284 | /* At this point, all discovery is aborted */ |
| 6285 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6286 | |
| 6287 | /* Unregister VPIs */ |
| 6288 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6289 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6290 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6291 | /* Stop FLOGI/FDISC retries */ |
| 6292 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6293 | if (ndlp) |
| 6294 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6295 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6296 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6297 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6298 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6299 | shost = lpfc_shost_from_vport(vports[i]); |
| 6300 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6301 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6302 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6303 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6304 | } |
| 6305 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6306 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6307 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6308 | if (ndlp) |
| 6309 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6310 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6311 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6312 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6313 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6314 | shost = lpfc_shost_from_vport(phba->pport); |
| 6315 | spin_lock_irq(shost->host_lock); |
| 6316 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6317 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6318 | spin_unlock_irq(shost->host_lock); |
| 6319 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6320 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6321 | /* Cleanup any outstanding ELS commands */ |
| 6322 | lpfc_els_flush_all_cmd(phba); |
| 6323 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6324 | /* Unregister the physical port VFI */ |
| 6325 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6326 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | /** |
| 6330 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6331 | * @phba: Pointer to hba context object. |
| 6332 | * |
| 6333 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6334 | * unregister the currently registered FCF record. The driver does not reset |
| 6335 | * the driver FCF usage state flags. |
| 6336 | * |
| 6337 | * Return 0 if successfully issued, none-zero otherwise. |
| 6338 | */ |
| 6339 | int |
| 6340 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6341 | { |
| 6342 | LPFC_MBOXQ_t *mbox; |
| 6343 | int rc; |
| 6344 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6345 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6346 | if (!mbox) { |
| 6347 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6348 | "2551 UNREG_FCFI mbox allocation failed" |
| 6349 | "HBA state x%x\n", phba->pport->port_state); |
| 6350 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6351 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6352 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6353 | mbox->vport = phba->pport; |
| 6354 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6355 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6356 | |
| 6357 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6358 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6359 | "2552 Unregister FCFI command failed rc x%x " |
| 6360 | "HBA state x%x\n", |
| 6361 | rc, phba->pport->port_state); |
| 6362 | return -EINVAL; |
| 6363 | } |
| 6364 | return 0; |
| 6365 | } |
| 6366 | |
| 6367 | /** |
| 6368 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6369 | * @phba: Pointer to hba context object. |
| 6370 | * |
| 6371 | * This function unregisters the currently reigstered FCF. This function |
| 6372 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6373 | */ |
| 6374 | void |
| 6375 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6376 | { |
| 6377 | int rc; |
| 6378 | |
| 6379 | /* Preparation for unregistering fcf */ |
| 6380 | rc = lpfc_unregister_fcf_prep(phba); |
| 6381 | if (rc) { |
| 6382 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6383 | "2748 Failed to prepare for unregistering " |
| 6384 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6385 | return; |
| 6386 | } |
| 6387 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6388 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6389 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6390 | if (rc) |
| 6391 | return; |
| 6392 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6393 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6394 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6395 | |
| 6396 | /* |
| 6397 | * If driver is not unloading, check if there is any other |
| 6398 | * FCF record that can be used for discovery. |
| 6399 | */ |
| 6400 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6401 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6402 | return; |
| 6403 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6404 | /* This is considered as the initial FCF discovery scan */ |
| 6405 | spin_lock_irq(&phba->hbalock); |
| 6406 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6407 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6408 | |
| 6409 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6410 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6411 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6412 | 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] | 6413 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6414 | if (rc) { |
| 6415 | spin_lock_irq(&phba->hbalock); |
| 6416 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6417 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6418 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6419 | "2553 lpfc_unregister_unused_fcf failed " |
| 6420 | "to read FCF record HBA state x%x\n", |
| 6421 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6422 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6427 | * @phba: Pointer to hba context object. |
| 6428 | * |
| 6429 | * This function just unregisters the currently reigstered FCF. It does not |
| 6430 | * try to find another FCF for discovery. |
| 6431 | */ |
| 6432 | void |
| 6433 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6434 | { |
| 6435 | int rc; |
| 6436 | |
| 6437 | /* Preparation for unregistering fcf */ |
| 6438 | rc = lpfc_unregister_fcf_prep(phba); |
| 6439 | if (rc) { |
| 6440 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6441 | "2749 Failed to prepare for unregistering " |
| 6442 | "HBA's FCF record: rc=%d\n", rc); |
| 6443 | return; |
| 6444 | } |
| 6445 | |
| 6446 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6447 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6448 | if (rc) |
| 6449 | return; |
| 6450 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6451 | spin_lock_irq(&phba->hbalock); |
| 6452 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6453 | spin_unlock_irq(&phba->hbalock); |
| 6454 | } |
| 6455 | |
| 6456 | /** |
| 6457 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6458 | * @phba: Pointer to hba context object. |
| 6459 | * |
| 6460 | * This function check if there are any connected remote port for the FCF and |
| 6461 | * if all the devices are disconnected, this function unregister FCFI. |
| 6462 | * This function also tries to use another FCF for discovery. |
| 6463 | */ |
| 6464 | void |
| 6465 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6466 | { |
| 6467 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6468 | * If HBA is not running in FIP mode, if HBA does not support |
| 6469 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6470 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6471 | */ |
| 6472 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6473 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6474 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6475 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6476 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6477 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6478 | spin_unlock_irq(&phba->hbalock); |
| 6479 | return; |
| 6480 | } |
| 6481 | spin_unlock_irq(&phba->hbalock); |
| 6482 | |
| 6483 | if (lpfc_fcf_inuse(phba)) |
| 6484 | return; |
| 6485 | |
| 6486 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | /** |
| 6490 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6491 | * @phba: Pointer to hba context object. |
| 6492 | * @buff: Buffer containing the FCF connection table as in the config |
| 6493 | * region. |
| 6494 | * This function create driver data structure for the FCF connection |
| 6495 | * record table read from config region 23. |
| 6496 | */ |
| 6497 | static void |
| 6498 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6499 | uint8_t *buff) |
| 6500 | { |
| 6501 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6502 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6503 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6504 | uint32_t record_count; |
| 6505 | int i; |
| 6506 | |
| 6507 | /* Free the current connect table */ |
| 6508 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6509 | &phba->fcf_conn_rec_list, list) { |
| 6510 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6511 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6512 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6513 | |
| 6514 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6515 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6516 | sizeof(struct lpfc_fcf_conn_rec); |
| 6517 | |
| 6518 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6519 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6520 | |
| 6521 | for (i = 0; i < record_count; i++) { |
| 6522 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6523 | continue; |
| 6524 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6525 | GFP_KERNEL); |
| 6526 | if (!conn_entry) { |
| 6527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6528 | "2566 Failed to allocate connection" |
| 6529 | " table entry\n"); |
| 6530 | return; |
| 6531 | } |
| 6532 | |
| 6533 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6534 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6535 | list_add_tail(&conn_entry->list, |
| 6536 | &phba->fcf_conn_rec_list); |
| 6537 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6538 | |
| 6539 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6540 | i = 0; |
| 6541 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6542 | list) { |
| 6543 | conn_rec = &conn_entry->conn_rec; |
| 6544 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6545 | "3345 FCF connection list rec[%02d]: " |
| 6546 | "flags:x%04x, vtag:x%04x, " |
| 6547 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6548 | "%02x:%02x:%02x:%02x, " |
| 6549 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6550 | "%02x:%02x:%02x:%02x\n", i++, |
| 6551 | conn_rec->flags, conn_rec->vlan_tag, |
| 6552 | conn_rec->fabric_name[0], |
| 6553 | conn_rec->fabric_name[1], |
| 6554 | conn_rec->fabric_name[2], |
| 6555 | conn_rec->fabric_name[3], |
| 6556 | conn_rec->fabric_name[4], |
| 6557 | conn_rec->fabric_name[5], |
| 6558 | conn_rec->fabric_name[6], |
| 6559 | conn_rec->fabric_name[7], |
| 6560 | conn_rec->switch_name[0], |
| 6561 | conn_rec->switch_name[1], |
| 6562 | conn_rec->switch_name[2], |
| 6563 | conn_rec->switch_name[3], |
| 6564 | conn_rec->switch_name[4], |
| 6565 | conn_rec->switch_name[5], |
| 6566 | conn_rec->switch_name[6], |
| 6567 | conn_rec->switch_name[7]); |
| 6568 | } |
| 6569 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | /** |
| 6573 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6574 | * @phba: Pointer to hba context object. |
| 6575 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6576 | * |
| 6577 | * This function update driver data structure with config |
| 6578 | * parameters read from config region 23. |
| 6579 | */ |
| 6580 | static void |
| 6581 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6582 | uint8_t *buff) |
| 6583 | { |
| 6584 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6585 | struct lpfc_fcoe_params *fcoe_param; |
| 6586 | |
| 6587 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6588 | buff; |
| 6589 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6590 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6591 | |
| 6592 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6593 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6594 | return; |
| 6595 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6596 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6597 | phba->valid_vlan = 1; |
| 6598 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6599 | 0xFFF; |
| 6600 | } |
| 6601 | |
| 6602 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6603 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6604 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6605 | return; |
| 6606 | } |
| 6607 | |
| 6608 | /** |
| 6609 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6610 | * @buff: Buffer containing config region 23 data. |
| 6611 | * @size: Size of the data buffer. |
| 6612 | * @rec_type: Record type to be searched. |
| 6613 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6614 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6615 | * of the record specified by record_type. If record found, this |
| 6616 | * function return pointer to the record else return NULL. |
| 6617 | */ |
| 6618 | static uint8_t * |
| 6619 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6620 | { |
| 6621 | uint32_t offset = 0, rec_length; |
| 6622 | |
| 6623 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6624 | (size < sizeof(uint32_t))) |
| 6625 | return NULL; |
| 6626 | |
| 6627 | rec_length = buff[offset + 1]; |
| 6628 | |
| 6629 | /* |
| 6630 | * One TLV record has one word header and number of data words |
| 6631 | * specified in the rec_length field of the record header. |
| 6632 | */ |
| 6633 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6634 | <= size) { |
| 6635 | if (buff[offset] == rec_type) |
| 6636 | return &buff[offset]; |
| 6637 | |
| 6638 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6639 | return NULL; |
| 6640 | |
| 6641 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6642 | rec_length = buff[offset + 1]; |
| 6643 | } |
| 6644 | return NULL; |
| 6645 | } |
| 6646 | |
| 6647 | /** |
| 6648 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6649 | * @phba: Pointer to lpfc_hba data structure. |
| 6650 | * @buff: Buffer containing config region 23 data. |
| 6651 | * @size: Size of the data buffer. |
| 6652 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6653 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6654 | * populate driver data structure with the parameters. |
| 6655 | */ |
| 6656 | void |
| 6657 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6658 | uint8_t *buff, |
| 6659 | uint32_t size) |
| 6660 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6661 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6662 | uint8_t *rec_ptr; |
| 6663 | |
| 6664 | /* |
| 6665 | * If data size is less than 2 words signature and version cannot be |
| 6666 | * verified. |
| 6667 | */ |
| 6668 | if (size < 2*sizeof(uint32_t)) |
| 6669 | return; |
| 6670 | |
| 6671 | /* Check the region signature first */ |
| 6672 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6673 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6674 | "2567 Config region 23 has bad signature\n"); |
| 6675 | return; |
| 6676 | } |
| 6677 | |
| 6678 | offset += 4; |
| 6679 | |
| 6680 | /* Check the data structure version */ |
| 6681 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6683 | "2568 Config region 23 has bad version\n"); |
| 6684 | return; |
| 6685 | } |
| 6686 | offset += 4; |
| 6687 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6688 | /* Read FCoE param record */ |
| 6689 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6690 | size - offset, FCOE_PARAM_TYPE); |
| 6691 | if (rec_ptr) |
| 6692 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6693 | |
| 6694 | /* Read FCF connection table */ |
| 6695 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6696 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6697 | if (rec_ptr) |
| 6698 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6699 | |
| 6700 | } |