| 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 | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * 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] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/pci.h> |
| 26 | #include <linux/kthread.h> |
| 27 | #include <linux/interrupt.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 28 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 30 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_host.h> |
| 33 | #include <scsi/scsi_transport_fc.h> |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 34 | #include <scsi/fc/fc_fs.h> |
| 35 | |
| 36 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 43 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 45 | #include "lpfc_scsi.h" |
| 46 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc_logmsg.h" |
| 48 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 50 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 51 | |
| 52 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 53 | static uint8_t lpfcAlpaArray[] = { |
| 54 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 55 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 56 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 57 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 58 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 59 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 60 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 61 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 62 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 63 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 64 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 65 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 66 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 67 | }; |
| 68 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 69 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 70 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 71 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 72 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 73 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 74 | void |
| 75 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 76 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 77 | struct lpfc_rport_data *rdata; |
| 78 | struct lpfc_nodelist * ndlp; |
| 79 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 80 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 81 | rdata = rport->dd_data; |
| 82 | ndlp = rdata->pnode; |
| 83 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 84 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 85 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 86 | printk(KERN_ERR "Cannot find remote node" |
| 87 | " to terminate I/O Data x%x\n", |
| 88 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 92 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 93 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 94 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 95 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 96 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 97 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 98 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 99 | lpfc_sli_abort_iocb(ndlp->vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 100 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 101 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 102 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * This function will be called when dev_loss_tmo fire. |
| 107 | */ |
| 108 | void |
| 109 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 110 | { |
| 111 | struct lpfc_rport_data *rdata; |
| 112 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 113 | struct lpfc_vport *vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 114 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 115 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 116 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 117 | int put_node; |
| 118 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 119 | |
| 120 | rdata = rport->dd_data; |
| 121 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 122 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 123 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 124 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 125 | vport = ndlp->vport; |
| 126 | phba = vport->phba; |
| 127 | |
| 128 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 129 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 130 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 131 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 132 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 133 | "3181 dev_loss_callbk x%06x, rport %p flg x%x\n", |
| 134 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 135 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 136 | /* Don't defer this if we are in the process of deleting the vport |
| 137 | * or unloading the driver. The unload will cleanup the node |
| 138 | * appropriately we just need to cleanup the ndlp rport info here. |
| 139 | */ |
| 140 | if (vport->load_flag & FC_UNLOADING) { |
| 141 | put_node = rdata->pnode != NULL; |
| 142 | put_rport = ndlp->rport != NULL; |
| 143 | rdata->pnode = NULL; |
| 144 | ndlp->rport = NULL; |
| 145 | if (put_node) |
| 146 | lpfc_nlp_put(ndlp); |
| 147 | if (put_rport) |
| 148 | put_device(&rport->dev); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 153 | return; |
| 154 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 155 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
| 156 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 157 | "6789 rport name %llx != node port name %llx", |
| 158 | rport->port_name, |
| 159 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 160 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 161 | evtp = &ndlp->dev_loss_evt; |
| 162 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 163 | if (!list_empty(&evtp->evt_listp)) { |
| 164 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 165 | "6790 rport name %llx dev_loss_evt pending", |
| 166 | rport->port_name); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 167 | return; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 168 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 169 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 170 | shost = lpfc_shost_from_vport(vport); |
| 171 | spin_lock_irq(shost->host_lock); |
| 172 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
| 173 | spin_unlock_irq(shost->host_lock); |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 174 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 175 | /* We need to hold the node by incrementing the reference |
| 176 | * count until this queued work is done |
| 177 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 178 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 179 | |
| 180 | spin_lock_irq(&phba->hbalock); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 181 | if (evtp->evt_arg1) { |
| 182 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 183 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 184 | lpfc_worker_wake_up(phba); |
| 185 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 186 | spin_unlock_irq(&phba->hbalock); |
| 187 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 191 | /** |
| 192 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 193 | * @ndlp: Pointer to remote node object. |
| 194 | * |
| 195 | * This function is called from the worker thread when devloss timeout timer |
| 196 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 197 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 198 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 199 | * when devloss timeout happened to this @ndlp. |
| 200 | **/ |
| 201 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 202 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 203 | { |
| 204 | struct lpfc_rport_data *rdata; |
| 205 | struct fc_rport *rport; |
| 206 | struct lpfc_vport *vport; |
| 207 | struct lpfc_hba *phba; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 208 | struct Scsi_Host *shost; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 209 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 210 | int put_node; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 211 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 212 | int fcf_inuse = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 213 | |
| 214 | rport = ndlp->rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 215 | vport = ndlp->vport; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 216 | shost = lpfc_shost_from_vport(vport); |
| 217 | |
| 218 | spin_lock_irq(shost->host_lock); |
| 219 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
| 220 | spin_unlock_irq(shost->host_lock); |
| 221 | |
| 222 | if (!rport) |
| 223 | return fcf_inuse; |
| 224 | |
| 225 | name = (uint8_t *) &ndlp->nlp_portname; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 226 | phba = vport->phba; |
| 227 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 228 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 229 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 230 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 231 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 232 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 233 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 234 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 235 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 236 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", |
| 237 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 238 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 239 | /* |
| 240 | * lpfc_nlp_remove if reached with dangling rport drops the |
| 241 | * reference. To make sure that does not happen clear rport |
| 242 | * pointer in ndlp before lpfc_nlp_put. |
| 243 | */ |
| 244 | rdata = rport->dd_data; |
| 245 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 246 | /* Don't defer this if we are in the process of deleting the vport |
| 247 | * or unloading the driver. The unload will cleanup the node |
| 248 | * appropriately we just need to cleanup the ndlp rport info here. |
| 249 | */ |
| 250 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 251 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 252 | /* flush the target */ |
| 253 | lpfc_sli_abort_iocb(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 254 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
| 255 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 256 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 257 | put_node = rdata->pnode != NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 258 | rdata->pnode = NULL; |
| 259 | ndlp->rport = NULL; |
| 260 | if (put_node) |
| 261 | lpfc_nlp_put(ndlp); |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 262 | put_device(&rport->dev); |
| 263 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 264 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 265 | } |
| 266 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 267 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 268 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 269 | "0284 Devloss timeout Ignored on " |
| 270 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 271 | "NPort x%x\n", |
| 272 | *name, *(name+1), *(name+2), *(name+3), |
| 273 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 274 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 275 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 276 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 277 | |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 278 | put_node = rdata->pnode != NULL; |
| 279 | rdata->pnode = NULL; |
| 280 | ndlp->rport = NULL; |
| 281 | if (put_node) |
| 282 | lpfc_nlp_put(ndlp); |
| 283 | put_device(&rport->dev); |
| 284 | |
| 285 | if (ndlp->nlp_type & NLP_FABRIC) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 286 | return fcf_inuse; |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 288 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 289 | warn_on = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 290 | lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 291 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 293 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 294 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 296 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 297 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 298 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 299 | *name, *(name+1), *(name+2), *(name+3), |
| 300 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 301 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 302 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 303 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 304 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 305 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 306 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 307 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 308 | *name, *(name+1), *(name+2), *(name+3), |
| 309 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 310 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 311 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 312 | } |
| 313 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 314 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 315 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 316 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 317 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 318 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 319 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 320 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 321 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 322 | return fcf_inuse; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 327 | * @phba: Pointer to hba context object. |
| 328 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 329 | * @nlp_did: remote node identifer with devloss timeout. |
| 330 | * |
| 331 | * This function is called from the worker thread after invoking devloss |
| 332 | * timeout handler and releasing the reference count for the ndlp with |
| 333 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 334 | * timeout of the last remote node which had been in use of FCF, when this |
| 335 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 336 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 337 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 338 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 339 | * engine is in FCF discovery process, the devloss timeout state shall |
| 340 | * be set for either the FCF table scan process or roundrobin failover |
| 341 | * process to unregister the in-use FCF. |
| 342 | **/ |
| 343 | static void |
| 344 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 345 | uint32_t nlp_did) |
| 346 | { |
| 347 | /* If devloss timeout happened to a remote node when FCF had no |
| 348 | * longer been in-use, do nothing. |
| 349 | */ |
| 350 | if (!fcf_inuse) |
| 351 | return; |
| 352 | |
| 353 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 354 | spin_lock_irq(&phba->hbalock); |
| 355 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 356 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 357 | spin_unlock_irq(&phba->hbalock); |
| 358 | return; |
| 359 | } |
| 360 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 361 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 362 | "2847 Last remote node (x%x) using " |
| 363 | "FCF devloss tmo\n", nlp_did); |
| 364 | } |
| 365 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 366 | spin_unlock_irq(&phba->hbalock); |
| 367 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 368 | "2868 Devloss tmo to FCF rediscovery " |
| 369 | "in progress\n"); |
| 370 | return; |
| 371 | } |
| 372 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 373 | spin_unlock_irq(&phba->hbalock); |
| 374 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 375 | "2869 Devloss tmo to idle FIP engine, " |
| 376 | "unreg in-use FCF and rescan.\n"); |
| 377 | /* Unregister in-use FCF and rescan */ |
| 378 | lpfc_unregister_fcf_rescan(phba); |
| 379 | return; |
| 380 | } |
| 381 | spin_unlock_irq(&phba->hbalock); |
| 382 | if (phba->hba_flag & FCF_TS_INPROG) |
| 383 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 384 | "2870 FCF table scan in progress\n"); |
| 385 | if (phba->hba_flag & FCF_RR_INPROG) |
| 386 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 387 | "2871 FLOGI roundrobin FCF failover " |
| 388 | "in progress\n"); |
| 389 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 390 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 392 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 393 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 394 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 395 | * @phba: Pointer to hba context object. |
| 396 | * |
| 397 | * This function is called from the functions which need to post |
| 398 | * events from interrupt context. This function allocates data |
| 399 | * structure required for posting event. It also keeps track of |
| 400 | * number of events pending and prevent event storm when there are |
| 401 | * too many events. |
| 402 | **/ |
| 403 | struct lpfc_fast_path_event * |
| 404 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 405 | struct lpfc_fast_path_event *ret; |
| 406 | |
| 407 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 408 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 409 | return NULL; |
| 410 | |
| 411 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 412 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 413 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 414 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 415 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 416 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 417 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 422 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 423 | * @phba: Pointer to hba context object. |
| 424 | * @evt: Event object which need to be freed. |
| 425 | * |
| 426 | * This function frees the data structure required for posting |
| 427 | * events. |
| 428 | **/ |
| 429 | void |
| 430 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 431 | struct lpfc_fast_path_event *evt) { |
| 432 | |
| 433 | atomic_dec(&phba->fast_event_count); |
| 434 | kfree(evt); |
| 435 | } |
| 436 | |
| 437 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 438 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 439 | * @phba: Pointer to hba context object. |
| 440 | * @evtp: Event data structure. |
| 441 | * |
| 442 | * This function is called from worker thread, when the interrupt |
| 443 | * context need to post an event. This function posts the event |
| 444 | * to fc transport netlink interface. |
| 445 | **/ |
| 446 | static void |
| 447 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 448 | struct lpfc_work_evt *evtp) |
| 449 | { |
| 450 | unsigned long evt_category, evt_sub_category; |
| 451 | struct lpfc_fast_path_event *fast_evt_data; |
| 452 | char *evt_data; |
| 453 | uint32_t evt_data_size; |
| 454 | struct Scsi_Host *shost; |
| 455 | |
| 456 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 457 | work_evt); |
| 458 | |
| 459 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 460 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 461 | fabric_evt.subcategory; |
| 462 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 463 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 464 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 465 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 466 | evt_data_size = sizeof(fast_evt_data->un. |
| 467 | read_check_error); |
| 468 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 469 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 470 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 471 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 472 | } else { |
| 473 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 474 | return; |
| 475 | } |
| 476 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 477 | switch (evt_sub_category) { |
| 478 | case LPFC_EVENT_QFULL: |
| 479 | case LPFC_EVENT_DEVBSY: |
| 480 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 481 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 482 | break; |
| 483 | case LPFC_EVENT_CHECK_COND: |
| 484 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 485 | evt_data_size = sizeof(fast_evt_data->un. |
| 486 | check_cond_evt); |
| 487 | break; |
| 488 | case LPFC_EVENT_VARQUEDEPTH: |
| 489 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 490 | evt_data_size = sizeof(fast_evt_data->un. |
| 491 | queue_depth_evt); |
| 492 | break; |
| 493 | default: |
| 494 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 495 | return; |
| 496 | } |
| 497 | } else { |
| 498 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 499 | return; |
| 500 | } |
| 501 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 502 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 503 | fc_host_post_vendor_event(shost, |
| 504 | fc_get_event_number(), |
| 505 | evt_data_size, |
| 506 | evt_data, |
| 507 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 508 | |
| 509 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 510 | return; |
| 511 | } |
| 512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 514 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | { |
| 516 | struct lpfc_work_evt *evtp = NULL; |
| 517 | struct lpfc_nodelist *ndlp; |
| 518 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 519 | int fcf_inuse; |
| 520 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 522 | spin_lock_irq(&phba->hbalock); |
| 523 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 525 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 526 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 528 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 529 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 530 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 532 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 533 | /* decrement the node reference count held |
| 534 | * for this queued work |
| 535 | */ |
| 536 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 538 | case LPFC_EVT_DEV_LOSS: |
| 539 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 540 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 541 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 542 | /* decrement the node reference count held for |
| 543 | * this queued work |
| 544 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 545 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 546 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 547 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 548 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 549 | fcf_inuse, |
| 550 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 551 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 553 | if (phba->link_state < LPFC_LINK_DOWN) |
| 554 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 555 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 556 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 557 | complete((struct completion *)(evtp->evt_arg2)); |
| 558 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 559 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 560 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 561 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 562 | *(int *)(evtp->evt_arg1) = 0; |
| 563 | complete((struct completion *)(evtp->evt_arg2)); |
| 564 | break; |
| 565 | case LPFC_EVT_OFFLINE: |
| 566 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 567 | lpfc_sli_brdrestart(phba); |
| 568 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 569 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 570 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 571 | complete((struct completion *)(evtp->evt_arg2)); |
| 572 | break; |
| 573 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 574 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 575 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 576 | lpfc_sli_brdreset(phba); |
| 577 | lpfc_hba_down_post(phba); |
| 578 | *(int *)(evtp->evt_arg1) = |
| 579 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 580 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 581 | complete((struct completion *)(evtp->evt_arg2)); |
| 582 | break; |
| 583 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 584 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 585 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 586 | = (phba->pport->stopped) |
| 587 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 588 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | complete((struct completion *)(evtp->evt_arg2)); |
| 590 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 591 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 592 | lpfc_send_fastpath_evt(phba, evtp); |
| 593 | free_evt = 0; |
| 594 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 595 | case LPFC_EVT_RESET_HBA: |
| 596 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 597 | lpfc_reset_hba(phba); |
| 598 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | } |
| 600 | if (free_evt) |
| 601 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 602 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 604 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | |
| 606 | } |
| 607 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 608 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 609 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 610 | { |
| 611 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 612 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 613 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 614 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 615 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 617 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 618 | ha_copy = phba->work_ha; |
| 619 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 620 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 622 | /* First, try to post the next mailbox command to SLI4 device */ |
| 623 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 624 | lpfc_sli4_post_async_mbox(phba); |
| 625 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 626 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 627 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | lpfc_handle_eratt(phba); |
| 629 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 630 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | lpfc_sli_handle_mb_event(phba); |
| 632 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 633 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 635 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 636 | /* Process SLI4 events */ |
| 637 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 638 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 639 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 640 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 641 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 642 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 643 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 644 | if (phba->hba_flag & ASYNC_EVENT) |
| 645 | lpfc_sli4_async_event_proc(phba); |
| 646 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 647 | spin_lock_irq(&phba->hbalock); |
| 648 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 649 | spin_unlock_irq(&phba->hbalock); |
| 650 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 651 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 652 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 653 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 654 | } |
| 655 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 656 | vports = lpfc_create_vport_work_array(phba); |
| 657 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 658 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 659 | /* |
| 660 | * We could have no vports in array if unloading, so if |
| 661 | * this happens then just use the pport |
| 662 | */ |
| 663 | if (vports[i] == NULL && i == 0) |
| 664 | vport = phba->pport; |
| 665 | else |
| 666 | vport = vports[i]; |
| 667 | if (vport == NULL) |
| 668 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 669 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 670 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 671 | vport->work_port_events &= ~work_port_events; |
| 672 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 673 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 674 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 675 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 676 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 677 | if (work_port_events & WORKER_HB_TMO) |
| 678 | lpfc_hb_timeout_handler(phba); |
| 679 | if (work_port_events & WORKER_MBOX_TMO) |
| 680 | lpfc_mbox_timeout_handler(phba); |
| 681 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 682 | lpfc_unblock_fabric_iocbs(phba); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 683 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 684 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 685 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 686 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 688 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 689 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 690 | pring = lpfc_phba_elsring(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 691 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 692 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 693 | if ((status & HA_RXMASK) || |
| 694 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 695 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 696 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 697 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 698 | /* Set the lpfc data pending flag */ |
| 699 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 700 | } else { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 701 | if (phba->link_state >= LPFC_LINK_UP) { |
| 702 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 703 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 704 | (status & |
| 705 | HA_RXMASK)); |
| 706 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 707 | } |
Sebastian Herbszt | b103918 | 2015-07-22 10:53:22 +0200 | [diff] [blame] | 708 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 709 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 710 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 711 | /* |
| 712 | * Turn on Ring interrupts |
| 713 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 714 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 715 | spin_lock_irq(&phba->hbalock); |
| 716 | control = readl(phba->HCregaddr); |
| 717 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 718 | lpfc_debugfs_slow_ring_trc(phba, |
| 719 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 720 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 721 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 722 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 723 | writel(control, phba->HCregaddr); |
| 724 | readl(phba->HCregaddr); /* flush */ |
| 725 | } else { |
| 726 | lpfc_debugfs_slow_ring_trc(phba, |
| 727 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 728 | control, ha_copy, 0); |
| 729 | } |
| 730 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | } |
| 732 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | } |
| 735 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | int |
| 737 | lpfc_do_work(void *p) |
| 738 | { |
| 739 | struct lpfc_hba *phba = p; |
| 740 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 741 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 742 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 743 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 744 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 746 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 747 | /* wait and check worker queue activities */ |
| 748 | rc = wait_event_interruptible(phba->work_waitq, |
| 749 | (test_and_clear_bit(LPFC_DATA_READY, |
| 750 | &phba->data_flags) |
| 751 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 752 | /* Signal wakeup shall terminate the worker thread */ |
| 753 | if (rc) { |
| 754 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 755 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 759 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 762 | phba->worker_thread = NULL; |
| 763 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 764 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | /* |
| 769 | * 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] | 770 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | * embedding it in the IOCB. |
| 772 | */ |
| 773 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | uint32_t evt) |
| 776 | { |
| 777 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 778 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | |
| 780 | /* |
| 781 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 782 | * be queued to worker thread for processing |
| 783 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 784 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | if (!evtp) |
| 786 | return 0; |
| 787 | |
| 788 | evtp->evt_arg1 = arg1; |
| 789 | evtp->evt_arg2 = arg2; |
| 790 | evtp->evt = evt; |
| 791 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 792 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 793 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 794 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 796 | lpfc_worker_wake_up(phba); |
| 797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | return 1; |
| 799 | } |
| 800 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 801 | void |
| 802 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 803 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 804 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | struct lpfc_hba *phba = vport->phba; |
| 806 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 807 | |
| 808 | 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] | 809 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 810 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 811 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 812 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 813 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 814 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 815 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 816 | lpfc_unreg_rpi(vport, ndlp); |
| 817 | |
| 818 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 819 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 820 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 821 | continue; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 822 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 823 | remove |
| 824 | ? NLP_EVT_DEVICE_RM |
| 825 | : NLP_EVT_DEVICE_RECOVERY); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 826 | } |
| 827 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 828 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 829 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 830 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 831 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 833 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 837 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 838 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 839 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 840 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 841 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 842 | /* Cleanup any outstanding received buffers */ |
| 843 | lpfc_cleanup_rcv_buffers(vport); |
| 844 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | /* Cleanup any outstanding RSCN activity */ |
| 846 | lpfc_els_flush_rscn(vport); |
| 847 | |
| 848 | /* Cleanup any outstanding ELS commands */ |
| 849 | lpfc_els_flush_cmd(vport); |
| 850 | |
| 851 | lpfc_cleanup_rpis(vport, 0); |
| 852 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 853 | /* Turn off discovery timer if its running */ |
| 854 | lpfc_can_disctmo(vport); |
| 855 | } |
| 856 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 857 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 858 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 859 | { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 860 | struct lpfc_hba *phba = vport->phba; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 861 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 862 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 863 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 864 | fc_host_post_event(shost, fc_get_event_number(), |
| 865 | FCH_EVT_LINKDOWN, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 866 | |
| 867 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 868 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 869 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 870 | |
| 871 | lpfc_port_link_failure(vport); |
| 872 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 873 | /* Stop delayed Nport discovery */ |
| 874 | spin_lock_irq(shost->host_lock); |
| 875 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 876 | spin_unlock_irq(shost->host_lock); |
| 877 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 878 | } |
| 879 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 881 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 882 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | struct lpfc_vport *vport = phba->pport; |
| 884 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 885 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 886 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 887 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 889 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 891 | |
| 892 | /* Block all SCSI stack I/Os */ |
| 893 | lpfc_scsi_dev_block(phba); |
| 894 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 895 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 896 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 897 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 900 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 901 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 902 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 903 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 904 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 905 | if (vports != NULL) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 906 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 907 | /* Issue a LINK DOWN event to all nodes */ |
| 908 | lpfc_linkdown_port(vports[i]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 909 | |
| 910 | vports[i]->fc_myDID = 0; |
| 911 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 912 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 913 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame^] | 914 | if (phba->nvmet_support) |
| 915 | lpfc_nvmet_update_targetport(phba); |
| 916 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 917 | lpfc_nvme_update_localport(vports[i]); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 918 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 919 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 920 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 921 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 923 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 924 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 925 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 926 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 928 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 935 | if (phba->pport->fc_flag & FC_PT2PT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 936 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 937 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 939 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 940 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 941 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 943 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | } |
| 945 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 948 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 950 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | } |
| 952 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 953 | static void |
| 954 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 956 | struct lpfc_nodelist *ndlp; |
| 957 | |
| 958 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 959 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 960 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 962 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 964 | /* On Linkup its safe to clean up the ndlp |
| 965 | * from Fabric connections. |
| 966 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | if (ndlp->nlp_DID != Fabric_DID) |
| 968 | lpfc_unreg_rpi(vport, ndlp); |
| 969 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 970 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 971 | /* Fail outstanding IO now since device is |
| 972 | * marked for PLOGI. |
| 973 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 974 | lpfc_unreg_rpi(vport, ndlp); |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | static void |
| 980 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 981 | { |
| 982 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | struct lpfc_hba *phba = vport->phba; |
| 984 | |
| 985 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 986 | return; |
| 987 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 988 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 989 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 990 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 991 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 992 | /* If NPIV is not enabled, only bring the physical port up */ |
| 993 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 994 | (vport != phba->pport)) |
| 995 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 997 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
| 998 | fc_host_post_event(shost, fc_get_event_number(), |
| 999 | FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1000 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1001 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1002 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 1003 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 1004 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 1005 | vport->fc_ns_retry = 0; |
| 1006 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1008 | if (vport->fc_flag & FC_LBIT) |
| 1009 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static int |
| 1014 | lpfc_linkup(struct lpfc_hba *phba) |
| 1015 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1016 | struct lpfc_vport **vports; |
| 1017 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1018 | |
| 1019 | phba->link_state = LPFC_LINK_UP; |
| 1020 | |
| 1021 | /* Unblock fabric iocbs if they are blocked */ |
| 1022 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1023 | del_timer_sync(&phba->fabric_block_timer); |
| 1024 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1025 | vports = lpfc_create_vport_work_array(phba); |
| 1026 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1027 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1028 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1029 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * This routine handles processing a CLEAR_LA mailbox |
| 1036 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1037 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1038 | * handed off to the SLI layer. SLI3 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1040 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1042 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1043 | struct lpfc_vport *vport = pmb->vport; |
| 1044 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1045 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1046 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | uint32_t control; |
| 1048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1050 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1051 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | |
| 1053 | /* Check for error */ |
| 1054 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1055 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1056 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1057 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1058 | "state x%x\n", |
| 1059 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1060 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1061 | goto out; |
| 1062 | } |
| 1063 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1064 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1065 | phba->link_state = LPFC_HBA_READY; |
| 1066 | |
| 1067 | spin_lock_irq(&phba->hbalock); |
| 1068 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1069 | control = readl(phba->HCregaddr); |
| 1070 | control |= HC_LAINT_ENA; |
| 1071 | writel(control, phba->HCregaddr); |
| 1072 | readl(phba->HCregaddr); /* flush */ |
| 1073 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1074 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1075 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | out: |
| 1078 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1079 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1080 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1081 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1083 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1084 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1085 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1087 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | |
| 1089 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1090 | |
| 1091 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1093 | control = readl(phba->HCregaddr); |
| 1094 | control |= HC_LAINT_ENA; |
| 1095 | writel(control, phba->HCregaddr); |
| 1096 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1097 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | |
| 1099 | return; |
| 1100 | } |
| 1101 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1102 | |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1103 | void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1104 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1107 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1108 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1111 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1112 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1113 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1114 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1115 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1116 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1117 | return; |
| 1118 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1119 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1120 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1121 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1122 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1124 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1125 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1127 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1128 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1129 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1130 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1131 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1132 | */ |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1133 | if (vport->port_state != LPFC_FLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1134 | lpfc_initial_flogi(vport); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 1135 | else if (vport->fc_flag & FC_PT2PT) |
| 1136 | lpfc_disc_start(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1137 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1138 | |
| 1139 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1140 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1141 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1142 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1143 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1144 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1145 | |
| 1146 | lpfc_linkdown(phba); |
| 1147 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1148 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1149 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1150 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1152 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1156 | /** |
| 1157 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1158 | * @phba pointer to the struct lpfc_hba for this port. |
| 1159 | * This fucnction resets the round robin bit mask and clears the |
| 1160 | * fcf priority list. The list deletions are done while holding the |
| 1161 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1162 | * from the lpfc_fcf_pri record. |
| 1163 | **/ |
| 1164 | void |
| 1165 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1166 | { |
| 1167 | struct lpfc_fcf_pri *fcf_pri; |
| 1168 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1169 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1170 | spin_lock_irq(&phba->hbalock); |
| 1171 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1172 | &phba->fcf.fcf_pri_list, list) { |
| 1173 | list_del_init(&fcf_pri->list); |
| 1174 | fcf_pri->fcf_rec.flag = 0; |
| 1175 | } |
| 1176 | spin_unlock_irq(&phba->hbalock); |
| 1177 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1179 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1180 | { |
| 1181 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1182 | |
| 1183 | if (mboxq->u.mb.mbxStatus) { |
| 1184 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1185 | "2017 REG_FCFI mbxStatus error x%x " |
| 1186 | "HBA state x%x\n", |
| 1187 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1188 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1192 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1193 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1194 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1195 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1196 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1197 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1198 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1199 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1200 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1201 | goto fail_out; |
| 1202 | |
| 1203 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1204 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1205 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1206 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1207 | if (vport->port_state != LPFC_FLOGI) { |
| 1208 | phba->hba_flag |= FCF_RR_INPROG; |
| 1209 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1210 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1211 | goto out; |
| 1212 | } |
| 1213 | spin_unlock_irq(&phba->hbalock); |
| 1214 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1215 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1216 | fail_out: |
| 1217 | spin_lock_irq(&phba->hbalock); |
| 1218 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1219 | spin_unlock_irq(&phba->hbalock); |
| 1220 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1221 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1226 | * @fab_name: pointer to fabric name. |
| 1227 | * @new_fcf_record: pointer to fcf record. |
| 1228 | * |
| 1229 | * This routine compare the fcf record's fabric name with provided |
| 1230 | * fabric name. If the fabric name are identical this function |
| 1231 | * returns 1 else return 0. |
| 1232 | **/ |
| 1233 | static uint32_t |
| 1234 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1235 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1236 | 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] | 1237 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1238 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1239 | return 0; |
| 1240 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1241 | return 0; |
| 1242 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1243 | return 0; |
| 1244 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1245 | return 0; |
| 1246 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1247 | return 0; |
| 1248 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1249 | return 0; |
| 1250 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1251 | return 0; |
| 1252 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1256 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1257 | * @fab_name: pointer to fabric name. |
| 1258 | * @new_fcf_record: pointer to fcf record. |
| 1259 | * |
| 1260 | * This routine compare the fcf record's switch name with provided |
| 1261 | * switch name. If the switch name are identical this function |
| 1262 | * returns 1 else return 0. |
| 1263 | **/ |
| 1264 | static uint32_t |
| 1265 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1266 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1267 | 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] | 1268 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1269 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1270 | return 0; |
| 1271 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1272 | return 0; |
| 1273 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1274 | return 0; |
| 1275 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1276 | return 0; |
| 1277 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1278 | return 0; |
| 1279 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1280 | return 0; |
| 1281 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1282 | return 0; |
| 1283 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1287 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1288 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1289 | * @new_fcf_record: pointer to fcf record. |
| 1290 | * |
| 1291 | * This routine compare the fcf record's mac address with HBA's |
| 1292 | * FCF mac address. If the mac addresses are identical this function |
| 1293 | * returns 1 else return 0. |
| 1294 | **/ |
| 1295 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1296 | 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] | 1297 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1298 | 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] | 1299 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1300 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1301 | return 0; |
| 1302 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1303 | return 0; |
| 1304 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1305 | return 0; |
| 1306 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1307 | return 0; |
| 1308 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1309 | return 0; |
| 1310 | return 1; |
| 1311 | } |
| 1312 | |
| 1313 | static bool |
| 1314 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1315 | { |
| 1316 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1320 | * lpfc_update_fcf_record - Update driver fcf record |
| 1321 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1322 | * @phba: pointer to lpfc hba data structure. |
| 1323 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1324 | * @new_fcf_record: pointer to hba fcf record. |
| 1325 | * |
| 1326 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1327 | * record. This routine is called with the host lock held. |
| 1328 | **/ |
| 1329 | static void |
| 1330 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1331 | struct fcf_record *new_fcf_record |
| 1332 | ) |
| 1333 | { |
| 1334 | struct lpfc_fcf_pri *fcf_pri; |
| 1335 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1336 | lockdep_assert_held(&phba->hbalock); |
| 1337 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1338 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1339 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1340 | /* FCF record priority */ |
| 1341 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1342 | |
| 1343 | } |
| 1344 | |
| 1345 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1346 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1347 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1348 | * @new_fcf_record: pointer to fcf record. |
| 1349 | * |
| 1350 | * This routine copies the FCF information from the FCF |
| 1351 | * record to lpfc_hba data structure. |
| 1352 | **/ |
| 1353 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1354 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1355 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1356 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1357 | /* Fabric name */ |
| 1358 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1359 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1360 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1361 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1362 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1363 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1364 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1365 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1366 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1367 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1368 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1369 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1370 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1371 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1372 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1373 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1374 | /* Mac address */ |
| 1375 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1376 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1377 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1378 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1379 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1380 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1381 | /* FCF record index */ |
| 1382 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1383 | /* FCF record priority */ |
| 1384 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1385 | /* Switch name */ |
| 1386 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1387 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1388 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1389 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1390 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1391 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1392 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1393 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1394 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1395 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1396 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1397 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1398 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1399 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1400 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1401 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1405 | * lpfc_update_fcf_record - Update driver fcf record |
| 1406 | * @phba: pointer to lpfc hba data structure. |
| 1407 | * @fcf_rec: pointer to driver fcf record. |
| 1408 | * @new_fcf_record: pointer to hba fcf record. |
| 1409 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1410 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1411 | * @flag: flag bits to be set to the driver fcf record. |
| 1412 | * |
| 1413 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1414 | * together with the address mode, vlan_id, and other informations. This |
| 1415 | * routine is called with the host lock held. |
| 1416 | **/ |
| 1417 | static void |
| 1418 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1419 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1420 | uint16_t vlan_id, uint32_t flag) |
| 1421 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1422 | lockdep_assert_held(&phba->hbalock); |
| 1423 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1424 | /* Copy the fields from the HBA's FCF record */ |
| 1425 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1426 | /* Update other fields of driver FCF record */ |
| 1427 | fcf_rec->addr_mode = addr_mode; |
| 1428 | fcf_rec->vlan_id = vlan_id; |
| 1429 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1430 | __lpfc_update_fcf_record_pri(phba, |
| 1431 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1432 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1436 | * lpfc_register_fcf - Register the FCF with hba. |
| 1437 | * @phba: pointer to lpfc hba data structure. |
| 1438 | * |
| 1439 | * This routine issues a register fcfi mailbox command to register |
| 1440 | * the fcf with HBA. |
| 1441 | **/ |
| 1442 | static void |
| 1443 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1444 | { |
| 1445 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1446 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1447 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1448 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1449 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1450 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1451 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1452 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | |
| 1456 | /* The FCF is already registered, start discovery */ |
| 1457 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1458 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1459 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1460 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1461 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1462 | phba->hba_flag |= FCF_RR_INPROG; |
| 1463 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1464 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1465 | return; |
| 1466 | } |
| 1467 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1468 | return; |
| 1469 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1470 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1471 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1472 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1473 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1474 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1475 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1476 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1477 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1478 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1479 | |
| 1480 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1481 | fcf_mbxq->vport = phba->pport; |
| 1482 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1483 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1484 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1485 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1486 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1487 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1488 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1489 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1490 | |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1496 | * @phba: pointer to lpfc hba data structure. |
| 1497 | * @new_fcf_record: pointer to fcf record. |
| 1498 | * @boot_flag: Indicates if this record used by boot bios. |
| 1499 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1500 | * @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] | 1501 | * |
| 1502 | * This routine compare the fcf record with connect list obtained from the |
| 1503 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1504 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1505 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1506 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1507 | * used for this FCF when the function returns. |
| 1508 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1509 | * 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] | 1510 | * 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] | 1511 | **/ |
| 1512 | static int |
| 1513 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1514 | struct fcf_record *new_fcf_record, |
| 1515 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1516 | uint16_t *vlan_id) |
| 1517 | { |
| 1518 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1519 | int i, j, fcf_vlan_id = 0; |
| 1520 | |
| 1521 | /* Find the lowest VLAN id in the FCF record */ |
| 1522 | for (i = 0; i < 512; i++) { |
| 1523 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1524 | fcf_vlan_id = i * 8; |
| 1525 | j = 0; |
| 1526 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1527 | j++; |
| 1528 | fcf_vlan_id++; |
| 1529 | } |
| 1530 | break; |
| 1531 | } |
| 1532 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1533 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1534 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1535 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1536 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1537 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1538 | return 0; |
| 1539 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1540 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1541 | *boot_flag = 0; |
| 1542 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1543 | new_fcf_record); |
| 1544 | if (phba->valid_vlan) |
| 1545 | *vlan_id = phba->vlan_id; |
| 1546 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1547 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1548 | return 1; |
| 1549 | } |
| 1550 | |
| 1551 | /* |
| 1552 | * If there are no FCF connection table entry, driver connect to all |
| 1553 | * FCFs. |
| 1554 | */ |
| 1555 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1556 | *boot_flag = 0; |
| 1557 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1558 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1559 | |
| 1560 | /* |
| 1561 | * When there are no FCF connect entries, use driver's default |
| 1562 | * addressing mode - FPMA. |
| 1563 | */ |
| 1564 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1565 | *addr_mode = LPFC_FCF_FPMA; |
| 1566 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1567 | /* If FCF record report a vlan id use that vlan id */ |
| 1568 | if (fcf_vlan_id) |
| 1569 | *vlan_id = fcf_vlan_id; |
| 1570 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1571 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1572 | return 1; |
| 1573 | } |
| 1574 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1575 | list_for_each_entry(conn_entry, |
| 1576 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1577 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1578 | continue; |
| 1579 | |
| 1580 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1581 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1582 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1583 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1584 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1585 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1586 | new_fcf_record)) |
| 1587 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1588 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1589 | /* |
| 1590 | * If the vlan bit map does not have the bit set for the |
| 1591 | * vlan id to be used, then it is not a match. |
| 1592 | */ |
| 1593 | if (!(new_fcf_record->vlan_bitmap |
| 1594 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1595 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1596 | continue; |
| 1597 | } |
| 1598 | |
| 1599 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1600 | * If connection record does not support any addressing mode, |
| 1601 | * skip the FCF record. |
| 1602 | */ |
| 1603 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1604 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1605 | continue; |
| 1606 | |
| 1607 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1608 | * Check if the connection record specifies a required |
| 1609 | * addressing mode. |
| 1610 | */ |
| 1611 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1612 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1613 | |
| 1614 | /* |
| 1615 | * If SPMA required but FCF not support this continue. |
| 1616 | */ |
| 1617 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1618 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1619 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1620 | continue; |
| 1621 | |
| 1622 | /* |
| 1623 | * If FPMA required but FCF not support this continue. |
| 1624 | */ |
| 1625 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1626 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1627 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1628 | continue; |
| 1629 | } |
| 1630 | |
| 1631 | /* |
| 1632 | * This fcf record matches filtering criteria. |
| 1633 | */ |
| 1634 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1635 | *boot_flag = 1; |
| 1636 | else |
| 1637 | *boot_flag = 0; |
| 1638 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1639 | /* |
| 1640 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1641 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1642 | * by FCF, allow fabric to pick the addressing mode. |
| 1643 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1644 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1645 | new_fcf_record); |
| 1646 | /* |
| 1647 | * If the user specified a required address mode, assign that |
| 1648 | * address mode |
| 1649 | */ |
| 1650 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1651 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1652 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1653 | FCFCNCT_AM_SPMA) ? |
| 1654 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1655 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1656 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1657 | * addr mode only if FCF support the addr_mode. |
| 1658 | */ |
| 1659 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1660 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1661 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1662 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1663 | *addr_mode = LPFC_FCF_SPMA; |
| 1664 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1665 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1666 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1667 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1668 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1669 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1670 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1671 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1672 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1673 | /* |
| 1674 | * If no vlan id is specified in connect list, use the vlan id |
| 1675 | * in the FCF record |
| 1676 | */ |
| 1677 | else if (fcf_vlan_id) |
| 1678 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1679 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1680 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1681 | |
| 1682 | return 1; |
| 1683 | } |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
| 1688 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1689 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1690 | * @phba: pointer to lpfc hba data structure. |
| 1691 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1692 | * |
| 1693 | * This function check if there is any fcoe event pending while driver |
| 1694 | * scan FCF entries. If there is any pending event, it will restart the |
| 1695 | * FCF saning and return 1 else return 0. |
| 1696 | */ |
| 1697 | int |
| 1698 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1699 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1700 | /* |
| 1701 | * If the Link is up and no FCoE events while in the |
| 1702 | * FCF discovery, no need to restart FCF discovery. |
| 1703 | */ |
| 1704 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1705 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1706 | return 0; |
| 1707 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1708 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1709 | "2768 Pending link or FCF event during current " |
| 1710 | "handling of the previous event: link_state:x%x, " |
| 1711 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1712 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1713 | phba->fcoe_eventtag); |
| 1714 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1715 | spin_lock_irq(&phba->hbalock); |
| 1716 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1717 | spin_unlock_irq(&phba->hbalock); |
| 1718 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1719 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1720 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1721 | "2780 Restart FCF table scan due to " |
| 1722 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1723 | "evt_tag_current:x%x\n", |
| 1724 | phba->fcoe_eventtag_at_fcf_scan, |
| 1725 | phba->fcoe_eventtag); |
| 1726 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1727 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1728 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1729 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1730 | * flag |
| 1731 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1732 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1733 | "2833 Stop FCF discovery process due to link " |
| 1734 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1735 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1736 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1737 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1738 | spin_unlock_irq(&phba->hbalock); |
| 1739 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1740 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1741 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1742 | if (unreg_fcf) { |
| 1743 | spin_lock_irq(&phba->hbalock); |
| 1744 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1745 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1746 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1747 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1748 | return 1; |
| 1749 | } |
| 1750 | |
| 1751 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1752 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1753 | * @phba: pointer to lpfc hba data structure. |
| 1754 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1755 | * |
| 1756 | * This function makes an running random selection decision on FCF record to |
| 1757 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1758 | * probability. To perform integer manunipulation of random numbers with |
| 1759 | * 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] | 1760 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1761 | * |
| 1762 | * Returns true when outcome is for the newly read FCF record should be |
| 1763 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1764 | * chosen FCF record. |
| 1765 | **/ |
| 1766 | static bool |
| 1767 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1768 | { |
| 1769 | uint32_t rand_num; |
| 1770 | |
| 1771 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1772 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1773 | |
| 1774 | /* Decision with probability 1/fcf_cnt */ |
| 1775 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1776 | return true; |
| 1777 | else |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1782 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1783 | * @phba: pointer to lpfc hba data structure. |
| 1784 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1785 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1786 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1787 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1788 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1789 | * SGE parsing, and endianness swapping. |
| 1790 | * |
| 1791 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1792 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1793 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1794 | static struct fcf_record * |
| 1795 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1796 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1797 | { |
| 1798 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1799 | struct lpfc_mbx_sge sge; |
| 1800 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1801 | uint32_t shdr_status, shdr_add_status, if_type; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1802 | union lpfc_sli4_cfg_shdr *shdr; |
| 1803 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1804 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1805 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1806 | * routine only uses a single SGE. |
| 1807 | */ |
| 1808 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1809 | if (unlikely(!mboxq->sge_array)) { |
| 1810 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1811 | "2524 Failed to get the non-embedded SGE " |
| 1812 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1813 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1814 | } |
| 1815 | virt_addr = mboxq->sge_array->addr[0]; |
| 1816 | |
| 1817 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1818 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1819 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1820 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1821 | 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] | 1822 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1823 | if (shdr_status || shdr_add_status) { |
James Smart | f818ea7 | 2015-05-21 13:55:29 -0400 | [diff] [blame] | 1824 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
| 1825 | if_type == LPFC_SLI_INTF_IF_TYPE_2) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1826 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1827 | "2726 READ_FCF_RECORD Indicates empty " |
| 1828 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1829 | else |
| 1830 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1831 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1832 | "with status x%x add_status x%x, " |
| 1833 | "mbx\n", shdr_status, shdr_add_status); |
| 1834 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1835 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1836 | |
| 1837 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1838 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1839 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1840 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1841 | *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] | 1842 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1843 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1844 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1845 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1846 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1847 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1848 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1849 | return new_fcf_record; |
| 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1854 | * @phba: pointer to lpfc hba data structure. |
| 1855 | * @fcf_record: pointer to the fcf record. |
| 1856 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1857 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1858 | * |
| 1859 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1860 | * enabled. |
| 1861 | **/ |
| 1862 | static void |
| 1863 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1864 | struct fcf_record *fcf_record, |
| 1865 | uint16_t vlan_id, |
| 1866 | uint16_t next_fcf_index) |
| 1867 | { |
| 1868 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1869 | "2764 READ_FCF_RECORD:\n" |
| 1870 | "\tFCF_Index : x%x\n" |
| 1871 | "\tFCF_Avail : x%x\n" |
| 1872 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1873 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1874 | "\tFIP_Priority : x%x\n" |
| 1875 | "\tMAC_Provider : x%x\n" |
| 1876 | "\tLowest VLANID : x%x\n" |
| 1877 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1878 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1879 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1880 | "\tNext_FCF_Index: x%x\n", |
| 1881 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1882 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1883 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1884 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1885 | fcf_record->fip_priority, |
| 1886 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1887 | vlan_id, |
| 1888 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1889 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1890 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1891 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1892 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1893 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1894 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1895 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1896 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1897 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1898 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1899 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1900 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1901 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1902 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1903 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1904 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1905 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1906 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1907 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1908 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1909 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1910 | next_fcf_index); |
| 1911 | } |
| 1912 | |
| 1913 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1914 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1915 | * @phba: pointer to lpfc hba data structure. |
| 1916 | * @fcf_rec: pointer to an existing FCF record. |
| 1917 | * @new_fcf_record: pointer to a new FCF record. |
| 1918 | * @new_vlan_id: vlan id from the new FCF record. |
| 1919 | * |
| 1920 | * This function performs matching test of a new FCF record against an existing |
| 1921 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1922 | * will not be used as part of the FCF record matching criteria. |
| 1923 | * |
| 1924 | * Returns true if all the fields matching, otherwise returns false. |
| 1925 | */ |
| 1926 | static bool |
| 1927 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1928 | struct lpfc_fcf_rec *fcf_rec, |
| 1929 | struct fcf_record *new_fcf_record, |
| 1930 | uint16_t new_vlan_id) |
| 1931 | { |
| 1932 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1933 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1934 | return false; |
| 1935 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1936 | return false; |
| 1937 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1938 | return false; |
| 1939 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1940 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1941 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1942 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1943 | return true; |
| 1944 | } |
| 1945 | |
| 1946 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1947 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1948 | * @vport: Pointer to vport object. |
| 1949 | * @fcf_index: index to next fcf. |
| 1950 | * |
| 1951 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1952 | * When this function is invoked, there will be a current fcf registered |
| 1953 | * for flogi. |
| 1954 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1955 | * 1 for stop flogi on currently registered fcf; |
| 1956 | */ |
| 1957 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1958 | { |
| 1959 | struct lpfc_hba *phba = vport->phba; |
| 1960 | int rc; |
| 1961 | |
| 1962 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1963 | spin_lock_irq(&phba->hbalock); |
| 1964 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1965 | spin_unlock_irq(&phba->hbalock); |
| 1966 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1967 | "2872 Devloss tmo with no eligible " |
| 1968 | "FCF, unregister in-use FCF (x%x) " |
| 1969 | "and rescan FCF table\n", |
| 1970 | phba->fcf.current_rec.fcf_indx); |
| 1971 | lpfc_unregister_fcf_rescan(phba); |
| 1972 | goto stop_flogi_current_fcf; |
| 1973 | } |
| 1974 | /* Mark the end to FLOGI roundrobin failover */ |
| 1975 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1976 | /* Allow action to new fcf asynchronous event */ |
| 1977 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1978 | spin_unlock_irq(&phba->hbalock); |
| 1979 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1980 | "2865 No FCF available, stop roundrobin FCF " |
| 1981 | "failover and change port state:x%x/x%x\n", |
| 1982 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1983 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1984 | goto stop_flogi_current_fcf; |
| 1985 | } else { |
| 1986 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1987 | "2794 Try FLOGI roundrobin FCF failover to " |
| 1988 | "(x%x)\n", fcf_index); |
| 1989 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 1990 | if (rc) |
| 1991 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 1992 | "2761 FLOGI roundrobin FCF failover " |
| 1993 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 1994 | rc, phba->fcf.current_rec.fcf_indx); |
| 1995 | else |
| 1996 | goto stop_flogi_current_fcf; |
| 1997 | } |
| 1998 | return 0; |
| 1999 | |
| 2000 | stop_flogi_current_fcf: |
| 2001 | lpfc_can_disctmo(vport); |
| 2002 | return 1; |
| 2003 | } |
| 2004 | |
| 2005 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2006 | * lpfc_sli4_fcf_pri_list_del |
| 2007 | * @phba: pointer to lpfc hba data structure. |
| 2008 | * @fcf_index the index of the fcf record to delete |
| 2009 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 2010 | * If it is one the list then it is removed from the list, and the flag |
| 2011 | * is cleared. This routine grab the hbalock before removing the fcf |
| 2012 | * record from the list. |
| 2013 | **/ |
| 2014 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 2015 | uint16_t fcf_index) |
| 2016 | { |
| 2017 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2018 | |
| 2019 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2020 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2021 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2022 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2023 | new_fcf_pri->fcf_rec.flag); |
| 2024 | spin_lock_irq(&phba->hbalock); |
| 2025 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2026 | if (phba->fcf.current_rec.priority == |
| 2027 | new_fcf_pri->fcf_rec.priority) |
| 2028 | phba->fcf.eligible_fcf_cnt--; |
| 2029 | list_del_init(&new_fcf_pri->list); |
| 2030 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2031 | } |
| 2032 | spin_unlock_irq(&phba->hbalock); |
| 2033 | } |
| 2034 | |
| 2035 | /** |
| 2036 | * lpfc_sli4_set_fcf_flogi_fail |
| 2037 | * @phba: pointer to lpfc hba data structure. |
| 2038 | * @fcf_index the index of the fcf record to update |
| 2039 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2040 | * flag so the the round robin slection for the particular priority level |
| 2041 | * will try a different fcf record that does not have this bit set. |
| 2042 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2043 | * adding it to the priority list. |
| 2044 | **/ |
| 2045 | void |
| 2046 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2047 | { |
| 2048 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2049 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2050 | spin_lock_irq(&phba->hbalock); |
| 2051 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2052 | spin_unlock_irq(&phba->hbalock); |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * lpfc_sli4_fcf_pri_list_add |
| 2057 | * @phba: pointer to lpfc hba data structure. |
| 2058 | * @fcf_index the index of the fcf record to add |
| 2059 | * This routine checks the priority of the fcf_index to be added. |
| 2060 | * If it is a lower priority than the current head of the fcf_pri list |
| 2061 | * then it is added to the list in the right order. |
| 2062 | * If it is the same priority as the current head of the list then it |
| 2063 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2064 | * If the fcf_index to be added is of a higher priority than the current |
| 2065 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2066 | * rr_bmask and it is added to the head of the list. |
| 2067 | * returns: |
| 2068 | * 0=success 1=failure |
| 2069 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2070 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2071 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2072 | struct fcf_record *new_fcf_record) |
| 2073 | { |
| 2074 | uint16_t current_fcf_pri; |
| 2075 | uint16_t last_index; |
| 2076 | struct lpfc_fcf_pri *fcf_pri; |
| 2077 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2078 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2079 | int ret; |
| 2080 | |
| 2081 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2082 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2083 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2084 | fcf_index, new_fcf_record->fip_priority, |
| 2085 | new_fcf_pri->fcf_rec.flag); |
| 2086 | spin_lock_irq(&phba->hbalock); |
| 2087 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2088 | list_del_init(&new_fcf_pri->list); |
| 2089 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2090 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2091 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2092 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2093 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2094 | new_fcf_pri->fcf_rec.fcf_index); |
| 2095 | goto out; |
| 2096 | } |
| 2097 | |
| 2098 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2099 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2100 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2101 | ret = 0; /* Empty rr list */ |
| 2102 | goto out; |
| 2103 | } |
| 2104 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2105 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2106 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2107 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2108 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2109 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2110 | /* fcfs_at_this_priority_level = 1; */ |
| 2111 | phba->fcf.eligible_fcf_cnt = 1; |
| 2112 | } else |
| 2113 | /* fcfs_at_this_priority_level++; */ |
| 2114 | phba->fcf.eligible_fcf_cnt++; |
| 2115 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2116 | new_fcf_pri->fcf_rec.fcf_index); |
| 2117 | goto out; |
| 2118 | } |
| 2119 | |
| 2120 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2121 | &phba->fcf.fcf_pri_list, list) { |
| 2122 | if (new_fcf_pri->fcf_rec.priority <= |
| 2123 | fcf_pri->fcf_rec.priority) { |
| 2124 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2125 | list_add(&new_fcf_pri->list, |
| 2126 | &phba->fcf.fcf_pri_list); |
| 2127 | else |
| 2128 | list_add(&new_fcf_pri->list, |
| 2129 | &((struct lpfc_fcf_pri *) |
| 2130 | fcf_pri->list.prev)->list); |
| 2131 | ret = 0; |
| 2132 | goto out; |
| 2133 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2134 | || new_fcf_pri->fcf_rec.priority < |
| 2135 | next_fcf_pri->fcf_rec.priority) { |
| 2136 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2137 | ret = 0; |
| 2138 | goto out; |
| 2139 | } |
| 2140 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2141 | continue; |
| 2142 | |
| 2143 | } |
| 2144 | ret = 1; |
| 2145 | out: |
| 2146 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2147 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2148 | spin_unlock_irq(&phba->hbalock); |
| 2149 | return ret; |
| 2150 | } |
| 2151 | |
| 2152 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2153 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2154 | * @phba: pointer to lpfc hba data structure. |
| 2155 | * @mboxq: pointer to mailbox object. |
| 2156 | * |
| 2157 | * This function iterates through all the fcf records available in |
| 2158 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2159 | * the FCF for discovery it registers the FCF record and kicks start |
| 2160 | * discovery. |
| 2161 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2162 | * use an FCF record which matches fabric name and mac address of the |
| 2163 | * currently used FCF record. |
| 2164 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2165 | * used by BOOT_BIOS. |
| 2166 | */ |
| 2167 | void |
| 2168 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2169 | { |
| 2170 | struct fcf_record *new_fcf_record; |
| 2171 | uint32_t boot_flag, addr_mode; |
| 2172 | uint16_t fcf_index, next_fcf_index; |
| 2173 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 2174 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2175 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2176 | int rc; |
| 2177 | |
| 2178 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2179 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2180 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2181 | return; |
| 2182 | } |
| 2183 | |
| 2184 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2185 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2186 | &next_fcf_index); |
| 2187 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2188 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2189 | "2765 Mailbox command READ_FCF_RECORD " |
| 2190 | "failed to retrieve a FCF record.\n"); |
| 2191 | /* Let next new FCF event trigger fast failover */ |
| 2192 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2193 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2194 | spin_unlock_irq(&phba->hbalock); |
| 2195 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2200 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2201 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2202 | |
| 2203 | /* Log the FCF record information if turned on */ |
| 2204 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2205 | next_fcf_index); |
| 2206 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2207 | /* |
| 2208 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2209 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2210 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2211 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2212 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2213 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2214 | bf_get(lpfc_fcf_record_fcf_index, |
| 2215 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2216 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2217 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2218 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2219 | bf_get(lpfc_fcf_record_fcf_index, |
| 2220 | new_fcf_record), |
| 2221 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2222 | new_fcf_record), |
| 2223 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2224 | new_fcf_record), |
| 2225 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2226 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2227 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2228 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2229 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2230 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2231 | phba->fcf.current_rec.fcf_indx) { |
| 2232 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2233 | "2862 FCF (x%x) matches property " |
| 2234 | "of in-use FCF (x%x)\n", |
| 2235 | bf_get(lpfc_fcf_record_fcf_index, |
| 2236 | new_fcf_record), |
| 2237 | phba->fcf.current_rec.fcf_indx); |
| 2238 | goto read_next_fcf; |
| 2239 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2240 | /* |
| 2241 | * In case the current in-use FCF record becomes |
| 2242 | * invalid/unavailable during FCF discovery that |
| 2243 | * was not triggered by fast FCF failover process, |
| 2244 | * treat it as fast FCF failover. |
| 2245 | */ |
| 2246 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2247 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2248 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2249 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2250 | "(x%x), enter FCF failover " |
| 2251 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2252 | phba->fcf.current_rec.fcf_indx); |
| 2253 | spin_lock_irq(&phba->hbalock); |
| 2254 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2255 | spin_unlock_irq(&phba->hbalock); |
| 2256 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2257 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2258 | LPFC_FCOE_FCF_GET_FIRST); |
| 2259 | return; |
| 2260 | } |
| 2261 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2262 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2263 | } else { |
| 2264 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2265 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2266 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2267 | if (rc) |
| 2268 | goto read_next_fcf; |
| 2269 | } |
| 2270 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2271 | /* |
| 2272 | * 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] | 2273 | * FCF record for the discovery. The condition that a rescan |
| 2274 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2275 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2276 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2277 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2278 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2279 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2280 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2281 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2282 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2283 | phba->fcf.current_rec.fcf_indx) { |
| 2284 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2285 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2286 | /* Stop FCF redisc wait timer */ |
| 2287 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2288 | phba); |
| 2289 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2290 | /* Fast failover, mark completed */ |
| 2291 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2292 | spin_unlock_irq(&phba->hbalock); |
| 2293 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2294 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2295 | "FCF (x%x), port_state:x%x, " |
| 2296 | "fc_flag:x%x\n", |
| 2297 | phba->fcf.current_rec.fcf_indx, |
| 2298 | phba->pport->port_state, |
| 2299 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2300 | goto out; |
| 2301 | } else |
| 2302 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2303 | "2863 New FCF (x%x) matches " |
| 2304 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2305 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2306 | new_fcf_record), |
| 2307 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2308 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2309 | /* |
| 2310 | * Read next FCF record from HBA searching for the matching |
| 2311 | * with in-use record only if not during the fast failover |
| 2312 | * period. In case of fast failover period, it shall try to |
| 2313 | * determine whether the FCF record just read should be the |
| 2314 | * next candidate. |
| 2315 | */ |
| 2316 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2317 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2318 | goto read_next_fcf; |
| 2319 | } |
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 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2323 | * period; otherwise, update on current FCF record. |
| 2324 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2325 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2326 | fcf_rec = &phba->fcf.failover_rec; |
| 2327 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2328 | fcf_rec = &phba->fcf.current_rec; |
| 2329 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2330 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2331 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2332 | * If the driver FCF record does not have boot flag |
| 2333 | * set and new hba fcf record has boot flag set, use |
| 2334 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2335 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2336 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2337 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2338 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2339 | "2837 Update current FCF record " |
| 2340 | "(x%x) with new FCF record (x%x)\n", |
| 2341 | fcf_rec->fcf_indx, |
| 2342 | bf_get(lpfc_fcf_record_fcf_index, |
| 2343 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2344 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2345 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2346 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2347 | goto read_next_fcf; |
| 2348 | } |
| 2349 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2350 | * If the driver FCF record has boot flag set and the |
| 2351 | * new hba FCF record does not have boot flag, read |
| 2352 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2353 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2354 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2355 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2356 | goto read_next_fcf; |
| 2357 | } |
| 2358 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2359 | * If the new hba FCF record has lower priority value |
| 2360 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2361 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2362 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2363 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2364 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2365 | "2838 Update current FCF record " |
| 2366 | "(x%x) with new FCF record (x%x)\n", |
| 2367 | fcf_rec->fcf_indx, |
| 2368 | bf_get(lpfc_fcf_record_fcf_index, |
| 2369 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2370 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2371 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2372 | /* Reset running random FCF selection count */ |
| 2373 | phba->fcf.eligible_fcf_cnt = 1; |
| 2374 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2375 | /* Update running random FCF selection count */ |
| 2376 | phba->fcf.eligible_fcf_cnt++; |
| 2377 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2378 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2379 | if (select_new_fcf) { |
| 2380 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2381 | "2839 Update current FCF record " |
| 2382 | "(x%x) with new FCF record (x%x)\n", |
| 2383 | fcf_rec->fcf_indx, |
| 2384 | bf_get(lpfc_fcf_record_fcf_index, |
| 2385 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2386 | /* Choose the new FCF by random selection */ |
| 2387 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2388 | new_fcf_record, |
| 2389 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2390 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2391 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2392 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2393 | goto read_next_fcf; |
| 2394 | } |
| 2395 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2396 | * This is the first suitable FCF record, choose this record for |
| 2397 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2398 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2399 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2400 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2401 | "2840 Update initial FCF candidate " |
| 2402 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2403 | bf_get(lpfc_fcf_record_fcf_index, |
| 2404 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2405 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2406 | addr_mode, vlan_id, (boot_flag ? |
| 2407 | BOOT_ENABLE : 0)); |
| 2408 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2409 | /* Setup initial running random FCF selection count */ |
| 2410 | phba->fcf.eligible_fcf_cnt = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2411 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2412 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2413 | goto read_next_fcf; |
| 2414 | |
| 2415 | read_next_fcf: |
| 2416 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2417 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2418 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2419 | /* |
| 2420 | * Case of FCF fast failover scan |
| 2421 | */ |
| 2422 | |
| 2423 | /* |
| 2424 | * It has not found any suitable FCF record, cancel |
| 2425 | * FCF scan inprogress, and do nothing |
| 2426 | */ |
| 2427 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2428 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2429 | "2782 No suitable FCF found: " |
| 2430 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2431 | phba->fcoe_eventtag_at_fcf_scan, |
| 2432 | bf_get(lpfc_fcf_record_fcf_index, |
| 2433 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2434 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2435 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2436 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2437 | spin_unlock_irq(&phba->hbalock); |
| 2438 | /* Unregister in-use FCF and rescan */ |
| 2439 | lpfc_printf_log(phba, KERN_INFO, |
| 2440 | LOG_FIP, |
| 2441 | "2864 On devloss tmo " |
| 2442 | "unreg in-use FCF and " |
| 2443 | "rescan FCF table\n"); |
| 2444 | lpfc_unregister_fcf_rescan(phba); |
| 2445 | return; |
| 2446 | } |
| 2447 | /* |
| 2448 | * Let next new FCF event trigger fast failover |
| 2449 | */ |
| 2450 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2451 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2452 | return; |
| 2453 | } |
| 2454 | /* |
| 2455 | * It has found a suitable FCF record that is not |
| 2456 | * the same as in-use FCF record, unregister the |
| 2457 | * in-use FCF record, replace the in-use FCF record |
| 2458 | * with the new FCF record, mark FCF fast failover |
| 2459 | * completed, and then start register the new FCF |
| 2460 | * record. |
| 2461 | */ |
| 2462 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2463 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2464 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2465 | |
| 2466 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2467 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2468 | "2842 Replace in-use FCF (x%x) " |
| 2469 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2470 | phba->fcf.current_rec.fcf_indx, |
| 2471 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2472 | memcpy(&phba->fcf.current_rec, |
| 2473 | &phba->fcf.failover_rec, |
| 2474 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2475 | /* |
| 2476 | * Mark the fast FCF failover rediscovery completed |
| 2477 | * and the start of the first round of the roundrobin |
| 2478 | * FCF failover. |
| 2479 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2480 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2481 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2482 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2483 | /* Register to the new FCF record */ |
| 2484 | lpfc_register_fcf(phba); |
| 2485 | } else { |
| 2486 | /* |
| 2487 | * In case of transaction period to fast FCF failover, |
| 2488 | * do nothing when search to the end of the FCF table. |
| 2489 | */ |
| 2490 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2491 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2492 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2493 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2494 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2495 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2496 | /* |
| 2497 | * In case the current in-use FCF record no |
| 2498 | * longer existed during FCF discovery that |
| 2499 | * was not triggered by fast FCF failover |
| 2500 | * process, treat it as fast FCF failover. |
| 2501 | */ |
| 2502 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2503 | "2841 In-use FCF record (x%x) " |
| 2504 | "not reported, entering fast " |
| 2505 | "FCF failover mode scanning.\n", |
| 2506 | phba->fcf.current_rec.fcf_indx); |
| 2507 | spin_lock_irq(&phba->hbalock); |
| 2508 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2509 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2510 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2511 | LPFC_FCOE_FCF_GET_FIRST); |
| 2512 | return; |
| 2513 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2514 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2515 | lpfc_register_fcf(phba); |
| 2516 | } |
| 2517 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2518 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2519 | return; |
| 2520 | |
| 2521 | out: |
| 2522 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2523 | lpfc_register_fcf(phba); |
| 2524 | |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2529 | * 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] | 2530 | * @phba: pointer to lpfc hba data structure. |
| 2531 | * @mboxq: pointer to mailbox object. |
| 2532 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2533 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2534 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2535 | * performing the failover. If the FCF read back is not valid/available, it |
| 2536 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2537 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2538 | * newly read FCF record to the failover FCF record, unregister currently |
| 2539 | * registered FCF record, copy the failover FCF record to the current |
| 2540 | * FCF record, and then register the current FCF record before proceeding |
| 2541 | * to trying FLOGI on the new failover FCF. |
| 2542 | */ |
| 2543 | void |
| 2544 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2545 | { |
| 2546 | struct fcf_record *new_fcf_record; |
| 2547 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2548 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2549 | uint16_t current_fcf_index; |
| 2550 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2551 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2552 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2553 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2554 | if (phba->link_state < LPFC_LINK_UP) { |
| 2555 | spin_lock_irq(&phba->hbalock); |
| 2556 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2557 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2558 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2559 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2563 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2564 | &next_fcf_index); |
| 2565 | if (!new_fcf_record) { |
| 2566 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2567 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2568 | "failed to retrieve a FCF record. " |
| 2569 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2570 | phba->fcf.fcf_flag); |
| 2571 | lpfc_unregister_fcf_rescan(phba); |
| 2572 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2576 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2577 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2578 | |
| 2579 | /* Log the FCF record information if turned on */ |
| 2580 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2581 | next_fcf_index); |
| 2582 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2583 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2584 | if (!rc) { |
| 2585 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2586 | "2848 Remove ineligible FCF (x%x) from " |
| 2587 | "from roundrobin bmask\n", fcf_index); |
| 2588 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2589 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2590 | /* Perform next round of roundrobin FCF failover */ |
| 2591 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2592 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2593 | if (rc) |
| 2594 | goto out; |
| 2595 | goto error_out; |
| 2596 | } |
| 2597 | |
| 2598 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2599 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2600 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2601 | "FCF (x%x) back to FCF (x%x)\n", |
| 2602 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2603 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2604 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2605 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2606 | goto out; |
| 2607 | } |
| 2608 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2609 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2610 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2611 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2612 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2613 | spin_lock_irq(&phba->hbalock); |
| 2614 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2615 | new_fcf_record, addr_mode, vlan_id, |
| 2616 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2617 | spin_unlock_irq(&phba->hbalock); |
| 2618 | |
| 2619 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2620 | |
| 2621 | /* Unregister the current in-use FCF record */ |
| 2622 | lpfc_unregister_fcf(phba); |
| 2623 | |
| 2624 | /* Replace in-use record with the new record */ |
| 2625 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2626 | sizeof(struct lpfc_fcf_rec)); |
| 2627 | |
| 2628 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2629 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2630 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2631 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2632 | error_out: |
| 2633 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2634 | out: |
| 2635 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | /** |
| 2639 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2640 | * @phba: pointer to lpfc hba data structure. |
| 2641 | * @mboxq: pointer to mailbox object. |
| 2642 | * |
| 2643 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2644 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2645 | * failover when a new FCF event happened. If the FCF read back is |
| 2646 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2647 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2648 | */ |
| 2649 | void |
| 2650 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2651 | { |
| 2652 | struct fcf_record *new_fcf_record; |
| 2653 | uint32_t boot_flag, addr_mode; |
| 2654 | uint16_t fcf_index, next_fcf_index; |
| 2655 | uint16_t vlan_id; |
| 2656 | int rc; |
| 2657 | |
| 2658 | /* If link state is not up, no need to proceed */ |
| 2659 | if (phba->link_state < LPFC_LINK_UP) |
| 2660 | goto out; |
| 2661 | |
| 2662 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2663 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2664 | goto out; |
| 2665 | |
| 2666 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2667 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2668 | &next_fcf_index); |
| 2669 | if (!new_fcf_record) { |
| 2670 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2671 | "2767 Mailbox command READ_FCF_RECORD " |
| 2672 | "failed to retrieve a FCF record.\n"); |
| 2673 | goto out; |
| 2674 | } |
| 2675 | |
| 2676 | /* Check the connection list for eligibility */ |
| 2677 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2678 | &addr_mode, &vlan_id); |
| 2679 | |
| 2680 | /* Log the FCF record information if turned on */ |
| 2681 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2682 | next_fcf_index); |
| 2683 | |
| 2684 | if (!rc) |
| 2685 | goto out; |
| 2686 | |
| 2687 | /* Update the eligible FCF record index bmask */ |
| 2688 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2689 | |
| 2690 | 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] | 2691 | |
| 2692 | out: |
| 2693 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2694 | } |
| 2695 | |
| 2696 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2697 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2698 | * @phba: pointer to lpfc hba data structure. |
| 2699 | * @mboxq: pointer to mailbox data structure. |
| 2700 | * |
| 2701 | * This function handles completion of init vfi mailbox command. |
| 2702 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 2703 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2704 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2705 | { |
| 2706 | struct lpfc_vport *vport = mboxq->vport; |
| 2707 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2708 | /* |
| 2709 | * VFI not supported on interface type 0, just do the flogi |
| 2710 | * Also continue if the VFI is in use - just use the same one. |
| 2711 | */ |
| 2712 | if (mboxq->u.mb.mbxStatus && |
| 2713 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2714 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2715 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2716 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2717 | LOG_MBOX, |
| 2718 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2719 | mboxq->u.mb.mbxStatus); |
| 2720 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2721 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2722 | return; |
| 2723 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2724 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2725 | lpfc_initial_flogi(vport); |
| 2726 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2727 | return; |
| 2728 | } |
| 2729 | |
| 2730 | /** |
| 2731 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2732 | * @vport: pointer to lpfc_vport data structure. |
| 2733 | * |
| 2734 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2735 | * VPI for the physical port. |
| 2736 | */ |
| 2737 | void |
| 2738 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2739 | { |
| 2740 | LPFC_MBOXQ_t *mboxq; |
| 2741 | int rc; |
| 2742 | struct lpfc_hba *phba = vport->phba; |
| 2743 | |
| 2744 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2745 | if (!mboxq) { |
| 2746 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2747 | LOG_MBOX, "2892 Failed to allocate " |
| 2748 | "init_vfi mailbox\n"); |
| 2749 | return; |
| 2750 | } |
| 2751 | lpfc_init_vfi(mboxq, vport); |
| 2752 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2753 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2754 | if (rc == MBX_NOT_FINISHED) { |
| 2755 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2756 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2757 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2762 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2763 | * @phba: pointer to lpfc hba data structure. |
| 2764 | * @mboxq: pointer to mailbox data structure. |
| 2765 | * |
| 2766 | * This function handles completion of init vpi mailbox command. |
| 2767 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2768 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2769 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2770 | { |
| 2771 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2772 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2773 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2774 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2775 | if (mboxq->u.mb.mbxStatus) { |
| 2776 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2777 | LOG_MBOX, |
| 2778 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2779 | mboxq->u.mb.mbxStatus); |
| 2780 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2781 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2782 | return; |
| 2783 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2784 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2785 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2786 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2787 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2788 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2789 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2790 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2791 | if (!ndlp) |
| 2792 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2793 | LOG_DISCOVERY, |
| 2794 | "2731 Cannot find fabric " |
| 2795 | "controller node\n"); |
| 2796 | else |
| 2797 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2798 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2799 | return; |
| 2800 | } |
| 2801 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2802 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2803 | lpfc_initial_fdisc(vport); |
| 2804 | else { |
| 2805 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2806 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2807 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2808 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2809 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2810 | return; |
| 2811 | } |
| 2812 | |
| 2813 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2814 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2815 | * @vport: pointer to lpfc_vport data structure. |
| 2816 | * |
| 2817 | * This function issue a init_vpi mailbox command to initialize |
| 2818 | * VPI for the vport. |
| 2819 | */ |
| 2820 | void |
| 2821 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2822 | { |
| 2823 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2824 | int rc, vpi; |
| 2825 | |
| 2826 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2827 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2828 | if (!vpi) { |
| 2829 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2830 | LOG_MBOX, |
| 2831 | "3303 Failed to obtain vport vpi\n"); |
| 2832 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2833 | return; |
| 2834 | } |
| 2835 | vport->vpi = vpi; |
| 2836 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2837 | |
| 2838 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2839 | if (!mboxq) { |
| 2840 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2841 | LOG_MBOX, "2607 Failed to allocate " |
| 2842 | "init_vpi mailbox\n"); |
| 2843 | return; |
| 2844 | } |
| 2845 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2846 | mboxq->vport = vport; |
| 2847 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2848 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2849 | if (rc == MBX_NOT_FINISHED) { |
| 2850 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2851 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2852 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2857 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2858 | * @phba: pointer to lpfc hba data structure. |
| 2859 | * |
| 2860 | * This function loops through the list of vports on the @phba and issues an |
| 2861 | * FDISC if possible. |
| 2862 | */ |
| 2863 | void |
| 2864 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2865 | { |
| 2866 | struct lpfc_vport **vports; |
| 2867 | int i; |
| 2868 | |
| 2869 | vports = lpfc_create_vport_work_array(phba); |
| 2870 | if (vports != NULL) { |
| 2871 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2872 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2873 | continue; |
| 2874 | /* There are no vpi for this vport */ |
| 2875 | if (vports[i]->vpi > phba->max_vpi) { |
| 2876 | lpfc_vport_set_state(vports[i], |
| 2877 | FC_VPORT_FAILED); |
| 2878 | continue; |
| 2879 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2880 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2881 | lpfc_vport_set_state(vports[i], |
| 2882 | FC_VPORT_LINKDOWN); |
| 2883 | continue; |
| 2884 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2885 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2886 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2887 | continue; |
| 2888 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2889 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2890 | lpfc_initial_fdisc(vports[i]); |
| 2891 | else { |
| 2892 | lpfc_vport_set_state(vports[i], |
| 2893 | FC_VPORT_NO_FABRIC_SUPP); |
| 2894 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2895 | LOG_ELS, |
| 2896 | "0259 No NPIV " |
| 2897 | "Fabric support\n"); |
| 2898 | } |
| 2899 | } |
| 2900 | } |
| 2901 | lpfc_destroy_vport_work_array(phba, vports); |
| 2902 | } |
| 2903 | |
| 2904 | void |
| 2905 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2906 | { |
| 2907 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2908 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2909 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2910 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2911 | /* |
| 2912 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2913 | * error (except VFI in use) and continue with the discovery. |
| 2914 | */ |
| 2915 | if (mboxq->u.mb.mbxStatus && |
| 2916 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2917 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2918 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2919 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2920 | "2018 REG_VFI mbxStatus error x%x " |
| 2921 | "HBA state x%x\n", |
| 2922 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2923 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2924 | /* FLOGI failed, use loop map to make discovery list */ |
| 2925 | lpfc_disc_list_loopmap(vport); |
| 2926 | /* Start discovery */ |
| 2927 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2928 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2929 | } |
| 2930 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2931 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2932 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2933 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2934 | /* If the VFI is already registered, there is nothing else to do |
| 2935 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2936 | * we should drop through to set the port state to ready. |
| 2937 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2938 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2939 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2940 | vport->fc_flag & FC_PT2PT)) |
| 2941 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2942 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2943 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2944 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2945 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2946 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2947 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2948 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2949 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2950 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2951 | /* In case SLI4 FC loopback test, we are ready */ |
| 2952 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2953 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2954 | phba->link_state = LPFC_HBA_READY; |
| 2955 | goto out_free_mem; |
| 2956 | } |
| 2957 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2958 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2959 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 2960 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 2961 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 2962 | vport->phba->alpa_map[0], |
| 2963 | phba->link_state, phba->fc_topology); |
| 2964 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2965 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2966 | /* |
| 2967 | * For private loop or for NPort pt2pt, |
| 2968 | * just start discovery and we are done. |
| 2969 | */ |
| 2970 | if ((vport->fc_flag & FC_PT2PT) || |
| 2971 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2972 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2973 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2974 | /* Use loop map to make discovery list */ |
| 2975 | lpfc_disc_list_loopmap(vport); |
| 2976 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2977 | if (vport->fc_flag & FC_PT2PT) |
| 2978 | vport->port_state = LPFC_VPORT_READY; |
| 2979 | else |
| 2980 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2981 | } else { |
| 2982 | lpfc_start_fdiscs(phba); |
| 2983 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2984 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2985 | } |
| 2986 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2987 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2988 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | d6de08c | 2015-12-16 18:11:53 -0500 | [diff] [blame] | 2989 | if (dmabuf) { |
| 2990 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2991 | kfree(dmabuf); |
| 2992 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2993 | return; |
| 2994 | } |
| 2995 | |
| 2996 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2997 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2999 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3001 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3002 | struct serv_parm *sp = &vport->fc_sparam; |
| 3003 | uint32_t ed_tov; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | |
| 3005 | /* Check for error */ |
| 3006 | if (mb->mbxStatus) { |
| 3007 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3008 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3009 | "0319 READ_SPARAM mbxStatus error x%x " |
| 3010 | "hba state x%x>\n", |
| 3011 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | goto out; |
| 3014 | } |
| 3015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3016 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | sizeof (struct serv_parm)); |
James Smart | 21bf0b9 | 2015-08-31 16:48:21 -0400 | [diff] [blame] | 3018 | |
| 3019 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
| 3020 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 3021 | ed_tov = (ed_tov + 999999) / 1000000; |
| 3022 | |
| 3023 | phba->fc_edtov = ed_tov; |
| 3024 | phba->fc_ratov = (2 * ed_tov) / 1000; |
| 3025 | if (phba->fc_ratov < FF_DEF_RATOV) { |
| 3026 | /* RA_TOV should be atleast 10sec for initial flogi */ |
| 3027 | phba->fc_ratov = FF_DEF_RATOV; |
| 3028 | } |
| 3029 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3030 | lpfc_update_vport_wwn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3031 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 3032 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 3033 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 3034 | } |
| 3035 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3037 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | return; |
| 3040 | |
| 3041 | out: |
| 3042 | pmb->context1 = NULL; |
| 3043 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3044 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3045 | lpfc_issue_clear_la(phba, vport); |
| 3046 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | return; |
| 3048 | } |
| 3049 | |
| 3050 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3051 | 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] | 3052 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3053 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3054 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3055 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3057 | struct lpfc_dmabuf *mp; |
| 3058 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3059 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3060 | uint32_t fc_flags = 0; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3061 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3062 | spin_lock_irq(&phba->hbalock); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3063 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
| 3064 | |
| 3065 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3066 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3067 | case LPFC_LINK_SPEED_1GHZ: |
| 3068 | case LPFC_LINK_SPEED_2GHZ: |
| 3069 | case LPFC_LINK_SPEED_4GHZ: |
| 3070 | case LPFC_LINK_SPEED_8GHZ: |
| 3071 | case LPFC_LINK_SPEED_10GHZ: |
| 3072 | case LPFC_LINK_SPEED_16GHZ: |
| 3073 | case LPFC_LINK_SPEED_32GHZ: |
| 3074 | break; |
| 3075 | default: |
| 3076 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
| 3077 | break; |
| 3078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | } |
| 3080 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3081 | if (phba->fc_topology && |
| 3082 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3083 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3084 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3085 | phba->fc_topology, |
| 3086 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3087 | phba->fc_topology_changed = 1; |
| 3088 | } |
| 3089 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3090 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3091 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3093 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3094 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3095 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3096 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3097 | /* if npiv is enabled and this adapter supports npiv log |
| 3098 | * a message that npiv is not supported in this topology |
| 3099 | */ |
| 3100 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3101 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3102 | "1309 Link Up Event npiv not supported in loop " |
| 3103 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3104 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3105 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3106 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3108 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3109 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | |
| 3111 | if (i == 0) { |
| 3112 | phba->alpa_map[0] = 0; |
| 3113 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3114 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3115 | int numalpa, j, k; |
| 3116 | union { |
| 3117 | uint8_t pamap[16]; |
| 3118 | struct { |
| 3119 | uint32_t wd1; |
| 3120 | uint32_t wd2; |
| 3121 | uint32_t wd3; |
| 3122 | uint32_t wd4; |
| 3123 | } pa; |
| 3124 | } un; |
| 3125 | numalpa = phba->alpa_map[0]; |
| 3126 | j = 0; |
| 3127 | while (j < numalpa) { |
| 3128 | memset(un.pamap, 0, 16); |
| 3129 | for (k = 1; j < numalpa; k++) { |
| 3130 | un.pamap[k - 1] = |
| 3131 | phba->alpa_map[j + 1]; |
| 3132 | j++; |
| 3133 | if (k == 16) |
| 3134 | break; |
| 3135 | } |
| 3136 | /* Link Up Event ALPA map */ |
| 3137 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3138 | KERN_WARNING, |
| 3139 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3140 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | "ALPA map Data: x%x " |
| 3142 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3143 | un.pa.wd1, un.pa.wd2, |
| 3144 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | } |
| 3148 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3150 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3151 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3152 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3153 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3155 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3156 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3157 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3159 | if (fc_flags) { |
| 3160 | spin_lock_irq(shost->host_lock); |
| 3161 | vport->fc_flag |= fc_flags; |
| 3162 | spin_unlock_irq(shost->host_lock); |
| 3163 | } |
| 3164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3166 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3167 | if (!sparam_mbox) |
| 3168 | goto out; |
| 3169 | |
| 3170 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3171 | if (rc) { |
| 3172 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3173 | goto out; |
| 3174 | } |
| 3175 | sparam_mbox->vport = vport; |
| 3176 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3177 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3178 | if (rc == MBX_NOT_FINISHED) { |
| 3179 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3180 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3181 | kfree(mp); |
| 3182 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3183 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3184 | } |
| 3185 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3186 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3187 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3188 | if (!cfglink_mbox) |
| 3189 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3192 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3193 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3194 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3195 | if (rc == MBX_NOT_FINISHED) { |
| 3196 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3197 | goto out; |
| 3198 | } |
| 3199 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3200 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3201 | /* |
| 3202 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3203 | * is phase 1 implementation that support FCF index 0 and driver |
| 3204 | * defaults. |
| 3205 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3206 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3207 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3208 | GFP_KERNEL); |
| 3209 | if (unlikely(!fcf_record)) { |
| 3210 | lpfc_printf_log(phba, KERN_ERR, |
| 3211 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3212 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3213 | "fcf record\n"); |
| 3214 | rc = -ENODEV; |
| 3215 | goto out; |
| 3216 | } |
| 3217 | |
| 3218 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3219 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3220 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3221 | if (unlikely(rc)) { |
| 3222 | lpfc_printf_log(phba, KERN_ERR, |
| 3223 | LOG_MBOX | LOG_SLI, |
| 3224 | "2013 Could not manually add FCF " |
| 3225 | "record 0, status %d\n", rc); |
| 3226 | rc = -ENODEV; |
| 3227 | kfree(fcf_record); |
| 3228 | goto out; |
| 3229 | } |
| 3230 | kfree(fcf_record); |
| 3231 | } |
| 3232 | /* |
| 3233 | * The driver is expected to do FIP/FCF. Call the port |
| 3234 | * and get the FCF Table. |
| 3235 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3236 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3237 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3238 | spin_unlock_irq(&phba->hbalock); |
| 3239 | return; |
| 3240 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3241 | /* This is the initial FCF discovery scan */ |
| 3242 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3243 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3244 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3245 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3246 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3247 | LPFC_FCOE_FCF_GET_FIRST); |
| 3248 | if (rc) { |
| 3249 | spin_lock_irq(&phba->hbalock); |
| 3250 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3251 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3252 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3253 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3254 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3255 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3257 | |
| 3258 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3259 | out: |
| 3260 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3261 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3262 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3263 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | lpfc_issue_clear_la(phba, vport); |
| 3265 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3269 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3270 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | uint32_t control; |
| 3272 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3273 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3274 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3275 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3276 | control = readl(phba->HCregaddr); |
| 3277 | control |= HC_LAINT_ENA; |
| 3278 | writel(control, phba->HCregaddr); |
| 3279 | readl(phba->HCregaddr); /* flush */ |
| 3280 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3281 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | } |
| 3283 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3284 | static void |
| 3285 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3286 | { |
| 3287 | lpfc_linkdown(phba); |
| 3288 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3289 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3290 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3291 | } |
| 3292 | |
| 3293 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3295 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3297 | * as the completion routine when the command is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3298 | * handed off to the SLI layer. SLI4 only. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3299 | */ |
| 3300 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3301 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3303 | struct lpfc_vport *vport = pmb->vport; |
| 3304 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3305 | struct lpfc_mbx_read_top *la; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3306 | struct lpfc_sli_ring *pring; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3307 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3309 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3310 | /* Unblock ELS traffic */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3311 | pring = lpfc_phba_elsring(phba); |
| 3312 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3313 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | /* Check for error */ |
| 3315 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3316 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3317 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3318 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3320 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3321 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | } |
| 3323 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3324 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | |
| 3326 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3327 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3328 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3329 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3330 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3331 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3332 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3333 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3334 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3335 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3337 | if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | if (phba->fc_eventTag != 0) |
| 3339 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3340 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | |
| 3342 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3343 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3344 | spin_lock_irq(&phba->hbalock); |
| 3345 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3346 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3347 | else |
| 3348 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| 3349 | spin_unlock_irq(&phba->hbalock); |
| 3350 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3352 | phba->link_events++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3353 | if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3354 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3357 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3358 | "1306 Link Up Event in loop back mode " |
| 3359 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3360 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3361 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3362 | la), |
| 3363 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3364 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3365 | } else { |
| 3366 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3367 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3368 | "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] | 3369 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3370 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3371 | la), |
| 3372 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3373 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3374 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3375 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3376 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3377 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3378 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3379 | } else if (bf_get(lpfc_mbx_read_top_att_type, la) == |
| 3380 | LPFC_ATT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3382 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3383 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3384 | "1308 Link Down Event in loop back mode " |
| 3385 | "x%x received " |
| 3386 | "Data: x%x x%x x%x\n", |
| 3387 | la->eventTag, phba->fc_eventTag, |
| 3388 | phba->pport->port_state, vport->fc_flag); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3389 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3390 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3391 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3392 | "Data: x%x x%x x%x x%x x%x\n", |
| 3393 | la->eventTag, phba->fc_eventTag, |
| 3394 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3395 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3396 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3397 | lpfc_mbx_issue_link_down(phba); |
| 3398 | } |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3399 | if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) && |
| 3400 | ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3401 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3402 | phba->fc_stat.LinkDown++; |
| 3403 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3404 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3406 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3408 | lpfc_mbx_issue_link_down(phba); |
| 3409 | } else |
| 3410 | lpfc_enable_la(phba); |
| 3411 | |
| 3412 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3413 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3414 | "Data: x%x x%x x%x\n", |
| 3415 | la->eventTag, phba->fc_eventTag, |
| 3416 | phba->pport->port_state, vport->fc_flag); |
| 3417 | /* |
| 3418 | * The cmnd that triggered this will be waiting for this |
| 3419 | * signal. |
| 3420 | */ |
| 3421 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3422 | if (phba->wait_4_mlo_maint_flg) { |
| 3423 | phba->wait_4_mlo_maint_flg = 0; |
| 3424 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3425 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3426 | } |
| 3427 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3428 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3429 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3430 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3431 | lpfc_issue_clear_la(phba, vport); |
| 3432 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3433 | "1311 fa %d\n", |
| 3434 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | } |
| 3436 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3437 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3439 | kfree(mp); |
| 3440 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3441 | return; |
| 3442 | } |
| 3443 | |
| 3444 | /* |
| 3445 | * This routine handles processing a REG_LOGIN mailbox |
| 3446 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3447 | * as the completion routine when the command is |
| 3448 | * handed off to the SLI layer. |
| 3449 | */ |
| 3450 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3451 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3453 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3454 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3455 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3456 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3459 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3461 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3462 | "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 3463 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3464 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3465 | ndlp->nlp_usg_map, ndlp); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3466 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3467 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3468 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3469 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3470 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3471 | /* We rcvd a rscn after issuing this |
| 3472 | * mbox reg login, we may have cycled |
| 3473 | * back through the state and be |
| 3474 | * back at reg login state so this |
| 3475 | * mbox needs to be ignored becase |
| 3476 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3477 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3478 | */ |
| 3479 | spin_lock_irq(shost->host_lock); |
| 3480 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3481 | spin_unlock_irq(shost->host_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3482 | |
| 3483 | /* |
| 3484 | * We cannot leave the RPI registered because |
| 3485 | * if we go thru discovery again for this ndlp |
| 3486 | * a subsequent REG_RPI will fail. |
| 3487 | */ |
| 3488 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| 3489 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 4b7789b | 2015-12-16 18:11:55 -0500 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /* Call state machine */ |
| 3493 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3494 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3496 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3498 | /* decrement the node reference count held for this callback |
| 3499 | * function. |
| 3500 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3501 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | |
| 3503 | return; |
| 3504 | } |
| 3505 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3506 | static void |
| 3507 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3508 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3509 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3510 | struct lpfc_vport *vport = pmb->vport; |
| 3511 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3512 | |
| 3513 | switch (mb->mbxStatus) { |
| 3514 | case 0x0011: |
| 3515 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3516 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3517 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3518 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3519 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3520 | /* If VPI is busy, reset the HBA */ |
| 3521 | case 0x9700: |
| 3522 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3523 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3524 | vport->vpi, mb->mbxStatus); |
| 3525 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3526 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3527 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3529 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3530 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3531 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3532 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3533 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3534 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3535 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3536 | /* |
| 3537 | * This shost reference might have been taken at the beginning of |
| 3538 | * lpfc_vport_delete() |
| 3539 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3540 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3541 | scsi_host_put(shost); |
| 3542 | } |
| 3543 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3544 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3545 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3546 | { |
| 3547 | struct lpfc_hba *phba = vport->phba; |
| 3548 | LPFC_MBOXQ_t *mbox; |
| 3549 | int rc; |
| 3550 | |
| 3551 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3552 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3553 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3554 | |
| 3555 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3556 | mbox->vport = vport; |
| 3557 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3558 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3559 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3560 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3561 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3563 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3564 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3565 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3566 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | static void |
| 3570 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3571 | { |
| 3572 | struct lpfc_vport *vport = pmb->vport; |
| 3573 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3574 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3575 | |
| 3576 | switch (mb->mbxStatus) { |
| 3577 | case 0x0011: |
| 3578 | case 0x9601: |
| 3579 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3581 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3582 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3584 | spin_lock_irq(shost->host_lock); |
| 3585 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3586 | spin_unlock_irq(shost->host_lock); |
| 3587 | vport->fc_myDID = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3588 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3589 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3590 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame^] | 3591 | if (phba->nvmet_support) |
| 3592 | lpfc_nvmet_update_targetport(phba); |
| 3593 | else |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3594 | lpfc_nvme_update_localport(vport); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 3595 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3596 | goto out; |
| 3597 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3598 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3599 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3600 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3601 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3602 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3603 | vport->num_disc_nodes = 0; |
| 3604 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3605 | if (vport->fc_npr_cnt) |
| 3606 | lpfc_els_disc_plogi(vport); |
| 3607 | |
| 3608 | if (!vport->num_disc_nodes) { |
| 3609 | spin_lock_irq(shost->host_lock); |
| 3610 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3611 | spin_unlock_irq(shost->host_lock); |
| 3612 | lpfc_can_disctmo(vport); |
| 3613 | } |
| 3614 | vport->port_state = LPFC_VPORT_READY; |
| 3615 | |
| 3616 | out: |
| 3617 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3618 | return; |
| 3619 | } |
| 3620 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3621 | /** |
| 3622 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3623 | * @phba: pointer to lpfc hba data structure. |
| 3624 | * |
| 3625 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3626 | * the list of static vports to be created. The function create vports |
| 3627 | * based on the information returned from the HBA. |
| 3628 | **/ |
| 3629 | void |
| 3630 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3631 | { |
| 3632 | LPFC_MBOXQ_t *pmb = NULL; |
| 3633 | MAILBOX_t *mb; |
| 3634 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3635 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3636 | struct fc_vport_identifiers vport_id; |
| 3637 | struct fc_vport *new_fc_vport; |
| 3638 | struct Scsi_Host *shost; |
| 3639 | struct lpfc_vport *vport; |
| 3640 | uint16_t offset = 0; |
| 3641 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3642 | struct lpfc_dmabuf *mp; |
| 3643 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3644 | |
| 3645 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3646 | if (!pmb) { |
| 3647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3648 | "0542 lpfc_create_static_vport failed to" |
| 3649 | " allocate mailbox memory\n"); |
| 3650 | return; |
| 3651 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3652 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3653 | mb = &pmb->u.mb; |
| 3654 | |
| 3655 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3656 | if (!vport_info) { |
| 3657 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3658 | "0543 lpfc_create_static_vport failed to" |
| 3659 | " allocate vport_info\n"); |
| 3660 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3661 | return; |
| 3662 | } |
| 3663 | |
| 3664 | vport_buff = (uint8_t *) vport_info; |
| 3665 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3666 | /* free dma buffer from previous round */ |
| 3667 | if (pmb->context1) { |
| 3668 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3669 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3670 | kfree(mp); |
| 3671 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3672 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3673 | goto out; |
| 3674 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3675 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3676 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3677 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3678 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3679 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3680 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3681 | "0544 lpfc_create_static_vport failed to" |
| 3682 | " issue dump mailbox command ret 0x%x " |
| 3683 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3684 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3685 | goto out; |
| 3686 | } |
| 3687 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3688 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3689 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3690 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3691 | if (byte_count > sizeof(struct static_vport_info) - |
| 3692 | offset) |
| 3693 | byte_count = sizeof(struct static_vport_info) |
| 3694 | - offset; |
| 3695 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3696 | offset += byte_count; |
| 3697 | } else { |
| 3698 | if (mb->un.varDmp.word_cnt > |
| 3699 | sizeof(struct static_vport_info) - offset) |
| 3700 | mb->un.varDmp.word_cnt = |
| 3701 | sizeof(struct static_vport_info) |
| 3702 | - offset; |
| 3703 | byte_count = mb->un.varDmp.word_cnt; |
| 3704 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3705 | vport_buff + offset, |
| 3706 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3707 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3708 | offset += byte_count; |
| 3709 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3710 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3711 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3712 | offset < sizeof(struct static_vport_info)); |
| 3713 | |
| 3714 | |
| 3715 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3716 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3717 | != VPORT_INFO_REV)) { |
| 3718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3719 | "0545 lpfc_create_static_vport bad" |
| 3720 | " information header 0x%x 0x%x\n", |
| 3721 | le32_to_cpu(vport_info->signature), |
| 3722 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3723 | |
| 3724 | goto out; |
| 3725 | } |
| 3726 | |
| 3727 | shost = lpfc_shost_from_vport(phba->pport); |
| 3728 | |
| 3729 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3730 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3731 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3732 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3733 | if (!vport_id.port_name || !vport_id.node_name) |
| 3734 | continue; |
| 3735 | |
| 3736 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3737 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3738 | vport_id.disable = false; |
| 3739 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3740 | |
| 3741 | if (!new_fc_vport) { |
| 3742 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3743 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3744 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3745 | continue; |
| 3746 | } |
| 3747 | |
| 3748 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3749 | vport->vport_flag |= STATIC_VPORT; |
| 3750 | } |
| 3751 | |
| 3752 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3753 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3754 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3755 | if (pmb->context1) { |
| 3756 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3757 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3758 | kfree(mp); |
| 3759 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3760 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3761 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3762 | |
| 3763 | return; |
| 3764 | } |
| 3765 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | /* |
| 3767 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3768 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3769 | * as the completion routine when the command is |
| 3770 | * handed off to the SLI layer. |
| 3771 | */ |
| 3772 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3773 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3775 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3776 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3777 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3778 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3779 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3781 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3782 | pmb->context1 = NULL; |
| 3783 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3787 | "0258 Register Fabric login error: 0x%x\n", |
| 3788 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3790 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3791 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3793 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3794 | /* FLOGI failed, use loop map to make discovery list */ |
| 3795 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3797 | /* Start discovery */ |
| 3798 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3799 | /* Decrement the reference count to ndlp after the |
| 3800 | * reference to the ndlp are done. |
| 3801 | */ |
| 3802 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3803 | return; |
| 3804 | } |
| 3805 | |
| 3806 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3807 | /* Decrement the reference count to ndlp after the reference |
| 3808 | * to the ndlp are done. |
| 3809 | */ |
| 3810 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | return; |
| 3812 | } |
| 3813 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3814 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3815 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3816 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3820 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3821 | /* when physical port receive logo donot start |
| 3822 | * vport discovery */ |
| 3823 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3824 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3825 | else { |
| 3826 | shost = lpfc_shost_from_vport(vport); |
| 3827 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3828 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3829 | spin_unlock_irq(shost->host_lock); |
| 3830 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3831 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3835 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3836 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3837 | |
| 3838 | /* Drop the reference count from the mbox at the end after |
| 3839 | * all the current reference to the ndlp have been done. |
| 3840 | */ |
| 3841 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3842 | return; |
| 3843 | } |
| 3844 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3845 | /* |
| 3846 | * This routine will issue a GID_FT for each FC4 Type supported |
| 3847 | * by the driver. ALL GID_FTs must complete before discovery is started. |
| 3848 | */ |
| 3849 | int |
| 3850 | lpfc_issue_gidft(struct lpfc_vport *vport) |
| 3851 | { |
| 3852 | struct lpfc_hba *phba = vport->phba; |
| 3853 | |
| 3854 | /* Good status, issue CT Request to NameServer */ |
| 3855 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3856 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { |
| 3857 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
| 3858 | /* Cannot issue NameServer FCP Query, so finish up |
| 3859 | * discovery |
| 3860 | */ |
| 3861 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3862 | "0604 %s FC TYPE %x %s\n", |
| 3863 | "Failed to issue GID_FT to ", |
| 3864 | FC_TYPE_FCP, |
| 3865 | "Finishing discovery."); |
| 3866 | return 0; |
| 3867 | } |
| 3868 | vport->gidft_inp++; |
| 3869 | } |
| 3870 | |
| 3871 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3872 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
| 3873 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
| 3874 | /* Cannot issue NameServer NVME Query, so finish up |
| 3875 | * discovery |
| 3876 | */ |
| 3877 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
| 3878 | "0605 %s FC_TYPE %x %s %d\n", |
| 3879 | "Failed to issue GID_FT to ", |
| 3880 | FC_TYPE_NVME, |
| 3881 | "Finishing discovery: gidftinp ", |
| 3882 | vport->gidft_inp); |
| 3883 | if (vport->gidft_inp == 0) |
| 3884 | return 0; |
| 3885 | } else |
| 3886 | vport->gidft_inp++; |
| 3887 | } |
| 3888 | return vport->gidft_inp; |
| 3889 | } |
| 3890 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | /* |
| 3892 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3893 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3894 | * as the completion routine when the command is |
| 3895 | * handed off to the SLI layer. |
| 3896 | */ |
| 3897 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3900 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3902 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3903 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3905 | pmb->context1 = NULL; |
| 3906 | pmb->context2 = NULL; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3907 | vport->gidft_inp = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3908 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3910 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3911 | "0260 Register NameServer error: 0x%x\n", |
| 3912 | mb->mbxStatus); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3913 | |
| 3914 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3915 | /* decrement the node reference count held for this |
| 3916 | * callback function. |
| 3917 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3918 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3920 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3921 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3922 | |
| 3923 | /* If no other thread is using the ndlp, free it */ |
| 3924 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3926 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3927 | /* |
| 3928 | * RegLogin failed, use loop map to make discovery |
| 3929 | * list |
| 3930 | */ |
| 3931 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3932 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3933 | /* Start discovery */ |
| 3934 | lpfc_disc_start(vport); |
| 3935 | return; |
| 3936 | } |
| 3937 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | return; |
| 3939 | } |
| 3940 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3941 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3942 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3943 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3944 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3945 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3946 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 3947 | "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", |
| 3948 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 3949 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3950 | ndlp->nlp_usg_map, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3953 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3954 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3955 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3956 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3957 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3958 | |
| 3959 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3960 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
| 3961 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
| 3962 | |
| 3963 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 3964 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 3965 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
| 3966 | FC_TYPE_NVME); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3967 | |
| 3968 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3969 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | } |
| 3971 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3972 | vport->fc_ns_retry = 0; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3973 | if (lpfc_issue_gidft(vport) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3974 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 3976 | /* |
| 3977 | * At this point in time we may need to wait for multiple |
| 3978 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. |
| 3979 | * |
| 3980 | * decrement the node reference count held for this |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3981 | * callback function. |
| 3982 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3983 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3985 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3986 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | |
| 3988 | return; |
| 3989 | } |
| 3990 | |
| 3991 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3995 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | struct lpfc_rport_data *rdata; |
| 3997 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3998 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4000 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4001 | return; |
| 4002 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4004 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 4005 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4006 | rport_ids.port_id = ndlp->nlp_DID; |
| 4007 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4009 | /* |
| 4010 | * We leave our node pointer in rport->dd_data when we unregister a |
| 4011 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 4012 | * rport->dd_data points. So, if we're reusing a previously |
| 4013 | * registered port, drop the reference that we took the last time we |
| 4014 | * registered the port. |
| 4015 | */ |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4016 | rport = ndlp->rport; |
| 4017 | if (rport) { |
| 4018 | rdata = rport->dd_data; |
| 4019 | /* break the link before dropping the ref */ |
| 4020 | ndlp->rport = NULL; |
| 4021 | if (rdata && rdata->pnode == ndlp) |
| 4022 | lpfc_nlp_put(ndlp); |
| 4023 | rdata->pnode = NULL; |
| 4024 | /* drop reference for earlier registeration */ |
| 4025 | put_device(&rport->dev); |
| 4026 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4027 | |
| 4028 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 4029 | "rport add: did:x%x flg:x%x type x%x", |
| 4030 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4031 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4032 | /* Don't add the remote port if unloading. */ |
| 4033 | if (vport->load_flag & FC_UNLOADING) |
| 4034 | return; |
| 4035 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4036 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4037 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 4039 | "Warning: fc_remote_port_add failed\n"); |
| 4040 | return; |
| 4041 | } |
| 4042 | |
| 4043 | /* initialize static port data */ |
| 4044 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 4045 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4047 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4048 | |
| 4049 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 4050 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 4051 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 4052 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4053 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 4054 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 4055 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 4056 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4057 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4058 | "3183 rport register x%06x, rport %p role x%x\n", |
| 4059 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 4060 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4061 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4062 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4063 | ndlp->nlp_sid = rport->scsi_target_id; |
| 4064 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4065 | return; |
| 4066 | } |
| 4067 | |
| 4068 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4070 | { |
| 4071 | struct fc_rport *rport = ndlp->rport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4072 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4073 | struct lpfc_hba *phba = vport->phba; |
| 4074 | |
| 4075 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
| 4076 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4077 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4078 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4079 | "rport delete: did:x%x flg:x%x type x%x", |
| 4080 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4081 | |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4082 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 4083 | "3184 rport unregister x%06x, rport %p\n", |
| 4084 | ndlp->nlp_DID, rport); |
| 4085 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4086 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | |
| 4088 | return; |
| 4089 | } |
| 4090 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4091 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4092 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4093 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4094 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4095 | |
| 4096 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4097 | switch (state) { |
| 4098 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4100 | break; |
| 4101 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4103 | break; |
| 4104 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4105 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4106 | break; |
| 4107 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4108 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4109 | break; |
| 4110 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4112 | break; |
| 4113 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4114 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4115 | break; |
| 4116 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4118 | break; |
| 4119 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 4120 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 4121 | vport->fc_npr_cnt = 0; |
| 4122 | else |
| 4123 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4124 | break; |
| 4125 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4126 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4127 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4128 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4129 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4130 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4131 | int old_state, int new_state) |
| 4132 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4133 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4134 | struct lpfc_hba *phba = vport->phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4135 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4136 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4137 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4138 | ndlp->nlp_type |= NLP_FC_NODE; |
| 4139 | } |
| 4140 | if (new_state == NLP_STE_MAPPED_NODE) |
| 4141 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 4142 | if (new_state == NLP_STE_NPR_NODE) |
| 4143 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4145 | /* FCP and NVME Transport interface */ |
| 4146 | if ((old_state == NLP_STE_MAPPED_NODE || |
| 4147 | old_state == NLP_STE_UNMAPPED_NODE)) { |
| 4148 | if (ndlp->rport) { |
| 4149 | vport->phba->nport_event_cnt++; |
| 4150 | lpfc_unregister_remote_port(ndlp); |
| 4151 | } |
| 4152 | |
| 4153 | /* Notify the NVME transport of this rport's loss */ |
| 4154 | if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 4155 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) && |
| 4156 | (vport->phba->nvmet_support == 0) && |
| 4157 | ((ndlp->nlp_fc4_type & NLP_FC4_NVME) || |
| 4158 | (ndlp->nlp_DID == Fabric_DID))) { |
| 4159 | vport->phba->nport_event_cnt++; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4160 | lpfc_nvme_unregister_port(vport, ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4161 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4162 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4164 | /* FCP and NVME Transport interfaces */ |
| 4165 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4166 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4167 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4168 | if ((ndlp->nlp_fc4_type & NLP_FC4_FCP) || |
| 4169 | (ndlp->nlp_DID == Fabric_DID)) { |
| 4170 | vport->phba->nport_event_cnt++; |
| 4171 | /* |
| 4172 | * Tell the fc transport about the port, if we haven't |
| 4173 | * already. If we have, and it's a scsi entity, be |
| 4174 | */ |
| 4175 | lpfc_register_remote_port(vport, ndlp); |
| 4176 | } |
| 4177 | /* Notify the NVME transport of this new rport. */ |
| 4178 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
| 4179 | if (vport->phba->nvmet_support == 0) { |
| 4180 | /* Register this rport with the transport. |
| 4181 | * Initiators take the NDLP ref count in |
| 4182 | * the register. |
| 4183 | */ |
| 4184 | vport->phba->nport_event_cnt++; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 4185 | lpfc_nvme_register_port(vport, ndlp); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 4186 | } else { |
| 4187 | /* Just take an NDLP ref count since the |
| 4188 | * target does not register rports. |
| 4189 | */ |
| 4190 | lpfc_nlp_get(ndlp); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4191 | } |
| 4192 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4193 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4194 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4195 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4196 | (vport->stat_data_enabled)) { |
| 4197 | /* |
| 4198 | * A new target is discovered, if there is no buffer for |
| 4199 | * statistical data collection allocate buffer. |
| 4200 | */ |
| 4201 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4202 | sizeof(struct lpfc_scsicmd_bkt), |
| 4203 | GFP_KERNEL); |
| 4204 | |
| 4205 | if (!ndlp->lat_data) |
| 4206 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4207 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4208 | "allocate statistical data buffer DID " |
| 4209 | "0x%x\n", ndlp->nlp_DID); |
| 4210 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4211 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4212 | * If the node just added to Mapped list was an FCP target, |
| 4213 | * but the remote port registration failed or assigned a target |
| 4214 | * id outside the presentable range - move the node to the |
| 4215 | * Unmapped List. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4216 | */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4217 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4218 | (ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4219 | (!ndlp->rport || |
| 4220 | ndlp->rport->scsi_target_id == -1 || |
| 4221 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4222 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4223 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4224 | spin_unlock_irq(shost->host_lock); |
| 4225 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4227 | } |
| 4228 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4229 | static char * |
| 4230 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4231 | { |
| 4232 | static char *states[] = { |
| 4233 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4234 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4235 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4236 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4237 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4238 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4239 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4240 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4241 | [NLP_STE_NPR_NODE] = "NPR", |
| 4242 | }; |
| 4243 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4244 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4245 | strlcpy(buffer, states[state], size); |
| 4246 | else |
| 4247 | snprintf(buffer, size, "unknown (%d)", state); |
| 4248 | return buffer; |
| 4249 | } |
| 4250 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4251 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4252 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4253 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4254 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4256 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4257 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4258 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4259 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4260 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4261 | ndlp->nlp_DID, |
| 4262 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4263 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4264 | |
| 4265 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4266 | "node statechg did:x%x old:%d ste:%d", |
| 4267 | ndlp->nlp_DID, old_state, state); |
| 4268 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4269 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4270 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4272 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4273 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4274 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4275 | } |
| 4276 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4277 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4278 | spin_lock_irq(shost->host_lock); |
| 4279 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4280 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4281 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4282 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4283 | |
| 4284 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4285 | lpfc_nlp_counters(vport, state, 1); |
| 4286 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4290 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4291 | { |
| 4292 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4293 | |
| 4294 | if (list_empty(&ndlp->nlp_listp)) { |
| 4295 | spin_lock_irq(shost->host_lock); |
| 4296 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4297 | spin_unlock_irq(shost->host_lock); |
| 4298 | } |
| 4299 | } |
| 4300 | |
| 4301 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4302 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4303 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4305 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4306 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4307 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4309 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4310 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4312 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4313 | NLP_STE_UNUSED_NODE); |
| 4314 | } |
| 4315 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4316 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4317 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4318 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4319 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4320 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4321 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4322 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4323 | NLP_STE_UNUSED_NODE); |
| 4324 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4326 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4327 | * @vport: Pointer to Virtual Port object. |
| 4328 | * @ndlp: Pointer to FC node object. |
| 4329 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4330 | * |
| 4331 | * This function is always called when node object need to be initialized. |
| 4332 | * It initializes all the fields of the node object. Although the reference |
| 4333 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4334 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4335 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4336 | * the final release of ndlp is determined by its reference count. And, the |
| 4337 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4338 | **/ |
| 4339 | static inline void |
| 4340 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4341 | uint32_t did) |
| 4342 | { |
| 4343 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4344 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 4345 | init_timer(&ndlp->nlp_delayfunc); |
| 4346 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 4347 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 4348 | ndlp->nlp_DID = did; |
| 4349 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4350 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4351 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 4352 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4353 | kref_init(&ndlp->kref); |
| 4354 | NLP_INT_NODE_ACT(ndlp); |
| 4355 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4356 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4357 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4358 | |
| 4359 | struct lpfc_nodelist * |
| 4360 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4361 | int state) |
| 4362 | { |
| 4363 | struct lpfc_hba *phba = vport->phba; |
| 4364 | uint32_t did; |
| 4365 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4366 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4367 | |
| 4368 | if (!ndlp) |
| 4369 | return NULL; |
| 4370 | |
| 4371 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4372 | /* The ndlp should not be in memory free mode */ |
| 4373 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4374 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4375 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4376 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4377 | "usgmap:x%x refcnt:%d\n", |
| 4378 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4379 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4380 | return NULL; |
| 4381 | } |
| 4382 | /* The ndlp should not already be in active mode */ |
| 4383 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4384 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4385 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4386 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4387 | "usgmap:x%x refcnt:%d\n", |
| 4388 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4389 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4390 | return NULL; |
| 4391 | } |
| 4392 | |
| 4393 | /* Keep the original DID */ |
| 4394 | did = ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4395 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4396 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4397 | |
| 4398 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4399 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4400 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4401 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4402 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4403 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4404 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4405 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4406 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4407 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4408 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4409 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4410 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " |
| 4411 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4412 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4413 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4414 | ndlp->nlp_usg_map, ndlp); |
| 4415 | } |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4416 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4417 | |
| 4418 | if (state != NLP_STE_UNUSED_NODE) |
| 4419 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4420 | |
| 4421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4422 | "node enable: did:x%x", |
| 4423 | ndlp->nlp_DID, 0, 0); |
| 4424 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4428 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4429 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4430 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4431 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4432 | * 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] | 4433 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4434 | * until ALL other outstanding threads have completed. We check |
| 4435 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4436 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4437 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4438 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4439 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4440 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4441 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4442 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4443 | } |
James Smart | 0290217 | 2015-05-21 13:55:17 -0400 | [diff] [blame] | 4444 | |
| 4445 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4446 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /* |
| 4450 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4451 | */ |
| 4452 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4453 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4454 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4456 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | uint32_t tmo; |
| 4458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4460 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4461 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4462 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4463 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4464 | * FC spec states we need 3 * ratov for CT requests |
| 4465 | */ |
| 4466 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4469 | |
| 4470 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4471 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4472 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4473 | tmo, vport->port_state, vport->fc_flag); |
| 4474 | } |
| 4475 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4476 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4477 | spin_lock_irq(shost->host_lock); |
| 4478 | vport->fc_flag |= FC_DISC_TMO; |
| 4479 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | |
| 4481 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4482 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4483 | "0247 Start Discovery Timer state x%x " |
| 4484 | "Data: x%x x%lx x%x x%x\n", |
| 4485 | vport->port_state, tmo, |
| 4486 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4487 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | |
| 4489 | return; |
| 4490 | } |
| 4491 | |
| 4492 | /* |
| 4493 | * Cancel rescue timer for Discovery / RSCN handling |
| 4494 | */ |
| 4495 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4496 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4499 | unsigned long iflags; |
| 4500 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4502 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4503 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4504 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4506 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4507 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4508 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4509 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4510 | del_timer_sync(&vport->fc_disctmo); |
| 4511 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4512 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4513 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4517 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4518 | "0248 Cancel Discovery Timer state x%x " |
| 4519 | "Data: x%x x%x x%x\n", |
| 4520 | vport->port_state, vport->fc_flag, |
| 4521 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4522 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | /* |
| 4526 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4527 | * Return true if iocb matches the specified nport |
| 4528 | */ |
| 4529 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4531 | struct lpfc_sli_ring *pring, |
| 4532 | struct lpfc_iocbq *iocb, |
| 4533 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4534 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4536 | struct lpfc_vport *vport = ndlp->vport; |
| 4537 | |
| 4538 | if (iocb->vport != vport) |
| 4539 | return 0; |
| 4540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | if (pring->ringno == LPFC_ELS_RING) { |
| 4542 | switch (icmd->ulpCommand) { |
| 4543 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4544 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4545 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4547 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4548 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | case CMD_XMIT_ELS_RSP64_CX: |
| 4550 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4551 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4553 | } else if (pring->ringno == LPFC_FCP_RING) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | /* Skip match check if waiting to relogin to FCP target */ |
| 4555 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4556 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4557 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4558 | } |
| 4559 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4560 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4562 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4563 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4564 | } |
| 4565 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4566 | static void |
| 4567 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4568 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, |
| 4569 | struct list_head *dequeue_list) |
| 4570 | { |
| 4571 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4572 | |
| 4573 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4574 | /* Check to see if iocb matches the nport */ |
| 4575 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
| 4576 | /* match, dequeue */ |
| 4577 | list_move_tail(&iocb->list, dequeue_list); |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | static void |
| 4582 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4583 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4584 | { |
| 4585 | struct lpfc_sli *psli = &phba->sli; |
| 4586 | uint32_t i; |
| 4587 | |
| 4588 | spin_lock_irq(&phba->hbalock); |
| 4589 | for (i = 0; i < psli->num_rings; i++) |
| 4590 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], |
| 4591 | dequeue_list); |
| 4592 | spin_unlock_irq(&phba->hbalock); |
| 4593 | } |
| 4594 | |
| 4595 | static void |
| 4596 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, |
| 4597 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) |
| 4598 | { |
| 4599 | struct lpfc_sli_ring *pring; |
| 4600 | struct lpfc_queue *qp = NULL; |
| 4601 | |
| 4602 | spin_lock_irq(&phba->hbalock); |
| 4603 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 4604 | pring = qp->pring; |
| 4605 | if (!pring) |
| 4606 | continue; |
| 4607 | spin_lock_irq(&pring->ring_lock); |
| 4608 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
| 4609 | spin_unlock_irq(&pring->ring_lock); |
| 4610 | } |
| 4611 | spin_unlock_irq(&phba->hbalock); |
| 4612 | } |
| 4613 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | /* |
| 4615 | * Free resources / clean up outstanding I/Os |
| 4616 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4617 | */ |
| 4618 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4620 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4621 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4623 | lpfc_fabric_abort_nport(ndlp); |
| 4624 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4625 | /* |
| 4626 | * Everything that matches on txcmplq will be returned |
| 4627 | * by firmware with a no rpi error. |
| 4628 | */ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4629 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4630 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4631 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); |
| 4632 | else |
| 4633 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4635 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4636 | /* Cancel all the IOCBs from the completions list */ |
| 4637 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4638 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4639 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4640 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4641 | } |
| 4642 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4643 | /** |
| 4644 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4645 | * @phba: Pointer to HBA context object. |
| 4646 | * @pmb: Pointer to mailbox object. |
| 4647 | * |
| 4648 | * This function will issue an ELS LOGO command after completing |
| 4649 | * the UNREG_RPI. |
| 4650 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame] | 4651 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4652 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4653 | { |
| 4654 | struct lpfc_vport *vport = pmb->vport; |
| 4655 | struct lpfc_nodelist *ndlp; |
| 4656 | |
| 4657 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4658 | if (!ndlp) |
| 4659 | return; |
| 4660 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4661 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4662 | } |
| 4663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | /* |
| 4665 | * Free rpi associated with LPFC_NODELIST entry. |
| 4666 | * This routine is called from lpfc_freenode(), when we are removing |
| 4667 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4668 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4669 | * to the remote NPort. In addition, it is called after we receive |
| 4670 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4671 | * we are waiting to PLOGI back to the remote NPort. |
| 4672 | */ |
| 4673 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4674 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4676 | struct lpfc_hba *phba = vport->phba; |
| 4677 | LPFC_MBOXQ_t *mbox; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4678 | int rc, acc_plogi = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4679 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4681 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4682 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4683 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 4684 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4685 | "3366 RPI x%x needs to be " |
| 4686 | "unregistered nlp_flag x%x " |
| 4687 | "did x%x\n", |
| 4688 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4689 | ndlp->nlp_DID); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4691 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4692 | /* SLI4 ports require the physical rpi value. */ |
| 4693 | rpi = ndlp->nlp_rpi; |
| 4694 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4695 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4696 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4697 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4698 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4699 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4700 | mbox->context1 = ndlp; |
| 4701 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4702 | } else { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4703 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 4704 | (!(vport->load_flag & FC_UNLOADING)) && |
| 4705 | (bf_get(lpfc_sli_intf_if_type, |
| 4706 | &phba->sli4_hba.sli_intf) == |
James Smart | a6517db | 2016-03-31 14:12:29 -0700 | [diff] [blame] | 4707 | LPFC_SLI_INTF_IF_TYPE_2) && |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4708 | (kref_read(&ndlp->kref) > 0)) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4709 | mbox->context1 = lpfc_nlp_get(ndlp); |
| 4710 | mbox->mbox_cmpl = |
| 4711 | lpfc_sli4_unreg_rpi_cmpl_clr; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4712 | /* |
| 4713 | * accept PLOGIs after unreg_rpi_cmpl |
| 4714 | */ |
| 4715 | acc_plogi = 0; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4716 | } else |
| 4717 | mbox->mbox_cmpl = |
| 4718 | lpfc_sli_def_mbox_cmpl; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4721 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4722 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4724 | acc_plogi = 1; |
| 4725 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4728 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4729 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4730 | ndlp->nlp_rpi = 0; |
| 4731 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4732 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4733 | if (acc_plogi) |
| 4734 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | return 1; |
| 4736 | } |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 4737 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | return 0; |
| 4739 | } |
| 4740 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4741 | /** |
| 4742 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4743 | * @phba: pointer to lpfc hba data structure. |
| 4744 | * |
| 4745 | * This routine is invoked to unregister all the currently registered RPIs |
| 4746 | * to the HBA. |
| 4747 | **/ |
| 4748 | void |
| 4749 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4750 | { |
| 4751 | struct lpfc_vport **vports; |
| 4752 | struct lpfc_nodelist *ndlp; |
| 4753 | struct Scsi_Host *shost; |
| 4754 | int i; |
| 4755 | |
| 4756 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4757 | if (!vports) { |
| 4758 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4759 | "2884 Vport array allocation failed \n"); |
| 4760 | return; |
| 4761 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4762 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4763 | shost = lpfc_shost_from_vport(vports[i]); |
| 4764 | spin_lock_irq(shost->host_lock); |
| 4765 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4766 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4767 | /* The mempool_alloc might sleep */ |
| 4768 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4769 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4770 | spin_lock_irq(shost->host_lock); |
| 4771 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4772 | } |
| 4773 | spin_unlock_irq(shost->host_lock); |
| 4774 | } |
| 4775 | lpfc_destroy_vport_work_array(phba, vports); |
| 4776 | } |
| 4777 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4778 | void |
| 4779 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4780 | { |
| 4781 | struct lpfc_hba *phba = vport->phba; |
| 4782 | LPFC_MBOXQ_t *mbox; |
| 4783 | int rc; |
| 4784 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4785 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4786 | lpfc_sli4_unreg_all_rpis(vport); |
| 4787 | return; |
| 4788 | } |
| 4789 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4790 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4791 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4792 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4793 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4794 | mbox->vport = vport; |
| 4795 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4796 | mbox->context1 = NULL; |
| 4797 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4798 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4799 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4800 | |
| 4801 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4802 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4803 | "1836 Could not issue " |
| 4804 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4805 | } |
| 4806 | } |
| 4807 | |
| 4808 | void |
| 4809 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4810 | { |
| 4811 | struct lpfc_hba *phba = vport->phba; |
| 4812 | LPFC_MBOXQ_t *mbox; |
| 4813 | int rc; |
| 4814 | |
| 4815 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4816 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4817 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4818 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4819 | mbox->vport = vport; |
| 4820 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4821 | mbox->context1 = NULL; |
| 4822 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4823 | if (rc != MBX_TIMEOUT) |
| 4824 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4825 | |
| 4826 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4827 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4828 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4829 | "unreg_did (default rpis) status %d\n", |
| 4830 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | /* |
| 4835 | * Free resources associated with LPFC_NODELIST entry |
| 4836 | * so it can be freed. |
| 4837 | */ |
| 4838 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4839 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4841 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4842 | struct lpfc_hba *phba = vport->phba; |
| 4843 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4844 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | |
| 4846 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4847 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4848 | "0900 Cleanup node for NPort x%x " |
| 4849 | "Data: x%x x%x x%x\n", |
| 4850 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4851 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4852 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4853 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4854 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4855 | "usgmap:x%x refcnt:%d\n", |
| 4856 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4857 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4858 | lpfc_dequeue_node(vport, ndlp); |
| 4859 | } else { |
| 4860 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4861 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4862 | "usgmap:x%x refcnt:%d\n", |
| 4863 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4864 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4865 | lpfc_disable_node(vport, ndlp); |
| 4866 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4867 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4868 | |
| 4869 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4870 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4871 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4872 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4873 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4874 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4875 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4876 | mb->context2 = NULL; |
| 4877 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4878 | } |
| 4879 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4881 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4882 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4883 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4884 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4885 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4886 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4887 | continue; |
| 4888 | |
| 4889 | mb->context2 = NULL; |
| 4890 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4891 | } |
| 4892 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4894 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4895 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4896 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4897 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4898 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4899 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4900 | kfree(mp); |
| 4901 | } |
| 4902 | list_del(&mb->list); |
| 4903 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4904 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4905 | * the ndlp reference count as we are in the process |
| 4906 | * of lpfc_nlp_release. |
| 4907 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | } |
| 4909 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4910 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4912 | lpfc_els_abort(phba, ndlp); |
| 4913 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4914 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4915 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4916 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4918 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4920 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4921 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4922 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4923 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4924 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4926 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | /* |
| 4930 | * Check to see if we can free the nlp back to the freelist. |
| 4931 | * If we are in the middle of using the nlp in the discovery state |
| 4932 | * machine, defer the free till we reach the end of the state machine. |
| 4933 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4934 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4936 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4937 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4938 | struct lpfc_rport_data *rdata; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4939 | struct fc_rport *rport; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4940 | LPFC_MBOXQ_t *mbox; |
| 4941 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4943 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4944 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4945 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4946 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4947 | /* For this case we need to cleanup the default rpi |
| 4948 | * allocated by the firmware. |
| 4949 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4950 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4951 | "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 4952 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 4953 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 4954 | ndlp->nlp_usg_map, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4955 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4956 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4957 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4958 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4959 | if (rc) { |
| 4960 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4961 | } |
| 4962 | else { |
| 4963 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4964 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4965 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4966 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4967 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4968 | if (rc == MBX_NOT_FINISHED) { |
| 4969 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4970 | } |
| 4971 | } |
| 4972 | } |
| 4973 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4974 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4976 | /* |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4977 | * ndlp->rport must be set to NULL before it reaches here |
| 4978 | * i.e. break rport/node link before doing lpfc_nlp_put for |
| 4979 | * registered rport and then drop the reference of rport. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4980 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4981 | if (ndlp->rport) { |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4982 | /* |
| 4983 | * extra lpfc_nlp_put dropped the reference of ndlp |
| 4984 | * for registered rport so need to cleanup rport |
| 4985 | */ |
| 4986 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4987 | "0940 removed node x%p DID x%x " |
| 4988 | " rport not null %p\n", |
| 4989 | ndlp, ndlp->nlp_DID, ndlp->rport); |
| 4990 | rport = ndlp->rport; |
| 4991 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4992 | rdata->pnode = NULL; |
| 4993 | ndlp->rport = NULL; |
James Smart | 466e840 | 2015-05-21 13:55:28 -0400 | [diff] [blame] | 4994 | put_device(&rport->dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4995 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5000 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5003 | |
| 5004 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5005 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5007 | /* First check for Direct match */ |
| 5008 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5009 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5010 | |
| 5011 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5012 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5013 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5014 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | matchdid.un.word = did; |
| 5018 | ndlpdid.un.word = ndlp->nlp_DID; |
| 5019 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 5020 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 5021 | (mydid.un.b.area == matchdid.un.b.area)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5022 | /* This code is supposed to match the ID |
| 5023 | * for a private loop device that is |
| 5024 | * connect to fl_port. But we need to |
| 5025 | * check that the port did not just go |
| 5026 | * from pt2pt to fabric or we could end |
| 5027 | * up matching ndlp->nlp_DID 000001 to |
| 5028 | * fabric DID 0x20101 |
| 5029 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | if ((ndlpdid.un.b.domain == 0) && |
| 5031 | (ndlpdid.un.b.area == 0)) { |
James Smart | 6b337e0 | 2015-05-21 13:55:23 -0400 | [diff] [blame] | 5032 | if (ndlpdid.un.b.id && |
| 5033 | vport->phba->fc_topology == |
| 5034 | LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5035 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5037 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | matchdid.un.word = ndlp->nlp_DID; |
| 5041 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 5042 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 5043 | if ((matchdid.un.b.domain == 0) && |
| 5044 | (matchdid.un.b.area == 0)) { |
| 5045 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5046 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | } |
| 5048 | } |
| 5049 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5050 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5051 | } |
| 5052 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5053 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5054 | static struct lpfc_nodelist * |
| 5055 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 5057 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5058 | uint32_t data1; |
| 5059 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5060 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 5061 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5062 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 5063 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 5064 | ((uint32_t) ndlp->nlp_type << 8) | |
| 5065 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5066 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5067 | "0929 FIND node DID " |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5068 | "Data: x%p x%x x%x x%x %p\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5069 | ndlp, ndlp->nlp_DID, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5070 | ndlp->nlp_flag, data1, |
| 5071 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5072 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | } |
| 5074 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 5075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5077 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5078 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | return NULL; |
| 5080 | } |
| 5081 | |
| 5082 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5083 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5085 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5087 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5088 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5089 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5090 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5091 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5092 | return ndlp; |
| 5093 | } |
| 5094 | |
| 5095 | struct lpfc_nodelist * |
| 5096 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 5097 | { |
| 5098 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5099 | struct lpfc_nodelist *ndlp; |
| 5100 | |
| 5101 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5102 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5103 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 5104 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | return NULL; |
| 5106 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5107 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5108 | if (!ndlp) |
| 5109 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5110 | lpfc_nlp_init(vport, ndlp, did); |
| 5111 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5112 | if (vport->phba->nvmet_support) |
| 5113 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5114 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5115 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5116 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5118 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5119 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 5120 | if (!ndlp) |
| 5121 | return NULL; |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5122 | if (vport->phba->nvmet_support) |
| 5123 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5124 | spin_lock_irq(shost->host_lock); |
| 5125 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5126 | spin_unlock_irq(shost->host_lock); |
| 5127 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5128 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5129 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5130 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 5131 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5132 | if (lpfc_rscn_payload_check(vport, did)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5133 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5134 | * we don't need to try to discover it again. |
| 5135 | */ |
| 5136 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 5137 | return NULL; |
| 5138 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5139 | /* Since this node is marked for discovery, |
| 5140 | * delay timeout is not needed. |
| 5141 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5142 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5143 | if (vport->phba->nvmet_support) |
| 5144 | return ndlp; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5145 | spin_lock_irq(shost->host_lock); |
| 5146 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 5147 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 5148 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5150 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5151 | /* If we've already received a PLOGI from this NPort, |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5152 | * or we are already in the process of discovery on it, |
| 5153 | * we don't need to try to discover it again. |
| 5154 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5155 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5156 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5157 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5159 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 5160 | if (vport->phba->nvmet_support) |
| 5161 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5162 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5163 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | } |
| 5166 | return ndlp; |
| 5167 | } |
| 5168 | |
| 5169 | /* Build a list of nodes to discover based on the loopmap */ |
| 5170 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5171 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5172 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5173 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5174 | int j; |
| 5175 | uint32_t alpa, index; |
| 5176 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5177 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5178 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5179 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5180 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5182 | |
| 5183 | /* Check for loop map present or not */ |
| 5184 | if (phba->alpa_map[0]) { |
| 5185 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 5186 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5187 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | } |
| 5191 | } else { |
| 5192 | /* No alpamap, so try all alpa's */ |
| 5193 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 5194 | /* If cfg_scan_down is set, start from highest |
| 5195 | * ALPA (0xef) to lowest (0x1). |
| 5196 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5197 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | index = j; |
| 5199 | else |
| 5200 | index = FC_MAXLOOP - j - 1; |
| 5201 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5202 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5203 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5204 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | return; |
| 5208 | } |
| 5209 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5210 | /* SLI3 only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5211 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5212 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5213 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5215 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5216 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
| 5217 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5218 | int rc; |
| 5219 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5220 | /* |
| 5221 | * if it's not a physical port or if we already send |
| 5222 | * clear_la then don't send it. |
| 5223 | */ |
| 5224 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5225 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 5226 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5227 | return; |
| 5228 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | /* Link up discovery */ |
| 5230 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 5231 | phba->link_state = LPFC_CLEAR_LA; |
| 5232 | lpfc_clear_la(phba, mbox); |
| 5233 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 5234 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5235 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5236 | if (rc == MBX_NOT_FINISHED) { |
| 5237 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5238 | lpfc_disc_flush_list(vport); |
| 5239 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5240 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5241 | phba->link_state = LPFC_HBA_ERROR; |
| 5242 | } |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 5247 | void |
| 5248 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5249 | { |
| 5250 | LPFC_MBOXQ_t *regvpimbox; |
| 5251 | |
| 5252 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5253 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5254 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5255 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 5256 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5257 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5258 | == MBX_NOT_FINISHED) { |
| 5259 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5260 | } |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5265 | void |
| 5266 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5267 | { |
| 5268 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5269 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5270 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | uint32_t clear_la_pending; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5272 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5273 | if (!lpfc_is_link_up(phba)) { |
| 5274 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5275 | "3315 Link is not up %x\n", |
| 5276 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5277 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5278 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5279 | |
| 5280 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5281 | clear_la_pending = 1; |
| 5282 | else |
| 5283 | clear_la_pending = 0; |
| 5284 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5285 | if (vport->port_state < LPFC_VPORT_READY) |
| 5286 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5287 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5288 | lpfc_set_disctmo(vport); |
| 5289 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5290 | vport->fc_prevDID = vport->fc_myDID; |
| 5291 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5292 | |
| 5293 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5294 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5295 | "0202 Start Discovery hba state x%x " |
| 5296 | "Data: x%x x%x x%x\n", |
| 5297 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 5298 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | |
| 5300 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5301 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | |
| 5303 | if (num_sent) |
| 5304 | return; |
| 5305 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5306 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5307 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5308 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5309 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5310 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5311 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5312 | lpfc_issue_reg_vpi(phba, vport); |
| 5313 | return; |
| 5314 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5315 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5316 | /* |
| 5317 | * For SLI2, we need to set port_state to READY and continue |
| 5318 | * discovery. |
| 5319 | */ |
| 5320 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5321 | /* If we get here, there is nothing to ADISC */ |
James Smart | 85c0f17 | 2015-04-07 15:07:12 -0400 | [diff] [blame] | 5322 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5323 | |
| 5324 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5325 | vport->num_disc_nodes = 0; |
| 5326 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5327 | if (vport->fc_npr_cnt) |
| 5328 | lpfc_els_disc_plogi(vport); |
| 5329 | |
| 5330 | if (!vport->num_disc_nodes) { |
| 5331 | spin_lock_irq(shost->host_lock); |
| 5332 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5333 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5334 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5335 | } |
| 5336 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5337 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5338 | } else { |
| 5339 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5340 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5341 | |
| 5342 | if (num_sent) |
| 5343 | return; |
| 5344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5345 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | /* Check to see if more RSCNs came in while we |
| 5347 | * were processing this one. |
| 5348 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5349 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5350 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5351 | spin_lock_irq(shost->host_lock); |
| 5352 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5353 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5354 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5355 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5356 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | return; |
| 5360 | } |
| 5361 | |
| 5362 | /* |
| 5363 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5364 | * ring the match the sppecified nodelist. |
| 5365 | */ |
| 5366 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5367 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5368 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5369 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | struct lpfc_sli *psli; |
| 5371 | IOCB_t *icmd; |
| 5372 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5373 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5374 | |
| 5375 | psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5376 | pring = lpfc_phba_elsring(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5377 | |
| 5378 | /* Error matching iocb on txq or txcmplq |
| 5379 | * First check the txq. |
| 5380 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5381 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5382 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5383 | if (iocb->context1 != ndlp) { |
| 5384 | continue; |
| 5385 | } |
| 5386 | icmd = &iocb->iocb; |
| 5387 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5388 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5389 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5390 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | /* Next check the txcmplq */ |
| 5395 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5396 | if (iocb->context1 != ndlp) { |
| 5397 | continue; |
| 5398 | } |
| 5399 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5400 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5401 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5402 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5403 | } |
| 5404 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5405 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5406 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5407 | /* Cancel all the IOCBs from the completions list */ |
| 5408 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5409 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5410 | } |
| 5411 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5412 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5413 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | { |
| 5415 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5416 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5417 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5418 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5419 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5420 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5421 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5422 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5423 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5424 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5425 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5426 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5427 | } |
| 5428 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5429 | } |
| 5430 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5431 | void |
| 5432 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5433 | { |
| 5434 | lpfc_els_flush_rscn(vport); |
| 5435 | lpfc_els_flush_cmd(vport); |
| 5436 | lpfc_disc_flush_list(vport); |
| 5437 | } |
| 5438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | /*****************************************************************************/ |
| 5440 | /* |
| 5441 | * NAME: lpfc_disc_timeout |
| 5442 | * |
| 5443 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5444 | * |
| 5445 | * EXECUTION ENVIRONMENT: interrupt only |
| 5446 | * |
| 5447 | * CALLED FROM: |
| 5448 | * Timer function |
| 5449 | * |
| 5450 | * RETURNS: |
| 5451 | * none |
| 5452 | */ |
| 5453 | /*****************************************************************************/ |
| 5454 | void |
| 5455 | lpfc_disc_timeout(unsigned long ptr) |
| 5456 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5458 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5459 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5460 | unsigned long flags = 0; |
| 5461 | |
| 5462 | if (unlikely(!phba)) |
| 5463 | return; |
| 5464 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5465 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5466 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5467 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5468 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5469 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5470 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5471 | if (!tmo_posted) |
| 5472 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | return; |
| 5474 | } |
| 5475 | |
| 5476 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5477 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5479 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5480 | struct lpfc_hba *phba = vport->phba; |
| 5481 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5482 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5483 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | int rc, clrlaerr = 0; |
| 5485 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5486 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5487 | return; |
| 5488 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5489 | spin_lock_irq(shost->host_lock); |
| 5490 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5491 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5492 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5493 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5494 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5495 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5496 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5497 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | |
| 5499 | case LPFC_LOCAL_CFG_LINK: |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5500 | /* |
| 5501 | * port_state is identically LPFC_LOCAL_CFG_LINK while |
| 5502 | * waiting for FAN timeout |
| 5503 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5504 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5505 | "0221 FAN timeout\n"); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5506 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5507 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5508 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5509 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5510 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5511 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5512 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5513 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5514 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5515 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5516 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5517 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5518 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5519 | /* Fail outstanding IO now since device |
| 5520 | * is marked for PLOGI. |
| 5521 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5522 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5523 | } |
| 5524 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5525 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5526 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5527 | lpfc_initial_flogi(vport); |
| 5528 | else |
| 5529 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5530 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5531 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | break; |
| 5533 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5534 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5535 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5536 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5538 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5539 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5540 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | |
| 5542 | /* Assume no Fabric and go on with discovery. |
| 5543 | * Check for outstanding ELS FLOGI to abort. |
| 5544 | */ |
| 5545 | |
| 5546 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5547 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | |
| 5549 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5550 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | break; |
| 5552 | |
| 5553 | case LPFC_FABRIC_CFG_LINK: |
| 5554 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5555 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5556 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5557 | "0223 Timeout while waiting for " |
| 5558 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5560 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5561 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5562 | lpfc_els_abort(phba, ndlp); |
| 5563 | |
| 5564 | /* ReStart discovery */ |
| 5565 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | |
| 5567 | case LPFC_NS_QRY: |
| 5568 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5569 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5570 | "0224 NameServer Query timeout " |
| 5571 | "Data: x%x x%x\n", |
| 5572 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5574 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5575 | /* Try it one more time */ |
| 5576 | vport->fc_ns_retry++; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5577 | vport->gidft_inp = 0; |
| 5578 | rc = lpfc_issue_gidft(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5579 | if (rc == 0) |
| 5580 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5582 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5584 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5585 | /* |
| 5586 | * Discovery is over. |
| 5587 | * set port_state to PORT_READY if SLI2. |
| 5588 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5589 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5590 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5591 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5592 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5593 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5594 | lpfc_issue_clear_la(phba, vport); |
| 5595 | vport->port_state = LPFC_VPORT_READY; |
| 5596 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5600 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5601 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5602 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5603 | "0206 Device Discovery " |
| 5604 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5605 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5606 | break; |
| 5607 | } |
| 5608 | |
| 5609 | lpfc_linkdown(phba); |
| 5610 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5611 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5612 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5613 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5614 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5615 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5616 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5617 | if (rc == MBX_NOT_FINISHED) |
| 5618 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5619 | |
| 5620 | break; |
| 5621 | |
| 5622 | case LPFC_DISC_AUTH: |
| 5623 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5624 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5625 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5626 | lpfc_disc_flush_list(vport); |
| 5627 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5628 | /* |
| 5629 | * set port_state to PORT_READY if SLI2. |
| 5630 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5631 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5632 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5633 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5634 | lpfc_issue_reg_vpi(phba, vport); |
| 5635 | else { /* NPIV Not enabled */ |
| 5636 | lpfc_issue_clear_la(phba, vport); |
| 5637 | vport->port_state = LPFC_VPORT_READY; |
| 5638 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5639 | } |
| 5640 | break; |
| 5641 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5642 | case LPFC_VPORT_READY: |
| 5643 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5644 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5645 | "0231 RSCN timeout Data: x%x " |
| 5646 | "x%x\n", |
| 5647 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5648 | |
| 5649 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5650 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5651 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5652 | lpfc_els_flush_rscn(vport); |
| 5653 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5654 | } |
| 5655 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5656 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5657 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5658 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5659 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5660 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5661 | break; |
| 5662 | } |
| 5663 | |
| 5664 | switch (phba->link_state) { |
| 5665 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5666 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5667 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5668 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5669 | clrlaerr = 1; |
| 5670 | break; |
| 5671 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5672 | case LPFC_LINK_UP: |
| 5673 | lpfc_issue_clear_la(phba, vport); |
| 5674 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5675 | case LPFC_LINK_UNKNOWN: |
| 5676 | case LPFC_WARM_START: |
| 5677 | case LPFC_INIT_START: |
| 5678 | case LPFC_INIT_MBX_CMDS: |
| 5679 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5680 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5681 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5682 | "0230 Unexpected timeout, hba link " |
| 5683 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5684 | clrlaerr = 1; |
| 5685 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5686 | |
| 5687 | case LPFC_HBA_READY: |
| 5688 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5692 | lpfc_disc_flush_list(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5693 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 5694 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= |
| 5695 | ~LPFC_STOP_IOCB_EVENT; |
| 5696 | psli->sli3_ring[LPFC_FCP_RING].flag &= |
| 5697 | ~LPFC_STOP_IOCB_EVENT; |
| 5698 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5699 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5701 | return; |
| 5702 | } |
| 5703 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5704 | /* |
| 5705 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5706 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5707 | * as the completion routine when the command is |
| 5708 | * handed off to the SLI layer. |
| 5709 | */ |
| 5710 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5711 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5712 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5713 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5714 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5715 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5716 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5717 | |
| 5718 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5719 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5720 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5721 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5722 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5723 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5724 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5725 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5726 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5727 | "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", |
| 5728 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5729 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5730 | ndlp->nlp_usg_map, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5731 | /* |
| 5732 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5733 | * 0xfffffa (FDMI well known port). |
| 5734 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 5735 | * DPRT -> RPRT (vports) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5736 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5737 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5738 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 5739 | else |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 5740 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| 5741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5742 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5743 | /* decrement the node reference count held for this callback |
| 5744 | * function. |
| 5745 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5746 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5747 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5748 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5749 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5750 | |
| 5751 | return; |
| 5752 | } |
| 5753 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5754 | static int |
| 5755 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5756 | { |
| 5757 | uint16_t *rpi = param; |
| 5758 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5759 | /* check for active node */ |
| 5760 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5761 | return 0; |
| 5762 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5763 | return ndlp->nlp_rpi == *rpi; |
| 5764 | } |
| 5765 | |
| 5766 | static int |
| 5767 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5768 | { |
| 5769 | return memcmp(&ndlp->nlp_portname, param, |
| 5770 | sizeof(ndlp->nlp_portname)) == 0; |
| 5771 | } |
| 5772 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5773 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5774 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5775 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5776 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5777 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5778 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5779 | if (filter(ndlp, param)) { |
| 5780 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5781 | "3185 FIND node filter %p DID " |
| 5782 | "Data: x%p x%x x%x\n", |
| 5783 | filter, ndlp, ndlp->nlp_DID, |
| 5784 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5785 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5786 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5787 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5788 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5789 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5790 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | } |
| 5792 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5793 | /* |
| 5794 | * 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] | 5795 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5796 | */ |
| 5797 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5798 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5799 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5800 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5801 | } |
| 5802 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5803 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5804 | * 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] | 5805 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5806 | */ |
| 5807 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5808 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5809 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5810 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5811 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5812 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5813 | spin_lock_irq(shost->host_lock); |
| 5814 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5815 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5816 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5817 | } |
| 5818 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5819 | /* |
| 5820 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5821 | * is found, the routine returns the node element list pointer else |
| 5822 | * return NULL. |
| 5823 | */ |
| 5824 | struct lpfc_nodelist * |
| 5825 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5826 | { |
| 5827 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5828 | struct lpfc_nodelist *ndlp; |
| 5829 | |
| 5830 | spin_lock_irq(shost->host_lock); |
| 5831 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5832 | spin_unlock_irq(shost->host_lock); |
| 5833 | return ndlp; |
| 5834 | } |
| 5835 | |
| 5836 | /** |
| 5837 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5838 | * @phba: pointer to lpfc hba data structure. |
| 5839 | * @vpi: the physical host virtual N_Port identifier. |
| 5840 | * |
| 5841 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5842 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5843 | * of the vport with the matching @vpi. |
| 5844 | * |
| 5845 | * Return code |
| 5846 | * NULL - No vport with the matching @vpi found |
| 5847 | * Otherwise - Address to the vport with the matching @vpi. |
| 5848 | **/ |
| 5849 | struct lpfc_vport * |
| 5850 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5851 | { |
| 5852 | struct lpfc_vport *vport; |
| 5853 | unsigned long flags; |
| 5854 | int i = 0; |
| 5855 | |
| 5856 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5857 | if (vpi > 0) { |
| 5858 | /* |
| 5859 | * Translate the physical vpi to the logical vpi. The |
| 5860 | * vport stores the logical vpi. |
| 5861 | */ |
| 5862 | for (i = 0; i < phba->max_vpi; i++) { |
| 5863 | if (vpi == phba->vpi_ids[i]) |
| 5864 | break; |
| 5865 | } |
| 5866 | |
| 5867 | if (i >= phba->max_vpi) { |
| 5868 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5869 | "2936 Could not find Vport mapped " |
| 5870 | "to vpi %d\n", vpi); |
| 5871 | return NULL; |
| 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5876 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5877 | if (vport->vpi == i) { |
| 5878 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5879 | return vport; |
| 5880 | } |
| 5881 | } |
| 5882 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5883 | return NULL; |
| 5884 | } |
| 5885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5887 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5888 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5889 | { |
| 5890 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5891 | |
| 5892 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5893 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5894 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5895 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5896 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5897 | "0007 rpi:%x DID:%x flg:%x refcnt:%d " |
| 5898 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5899 | ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5900 | kref_read(&ndlp->kref), |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5901 | ndlp->nlp_usg_map, ndlp); |
| 5902 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5903 | ndlp->active_rrqs_xri_bitmap = |
| 5904 | mempool_alloc(vport->phba->active_rrq_pool, |
| 5905 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 5906 | if (ndlp->active_rrqs_xri_bitmap) |
| 5907 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 5908 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5909 | } |
| 5910 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5911 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5912 | |
| 5913 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5914 | "node init: did:x%x", |
| 5915 | ndlp->nlp_DID, 0, 0); |
| 5916 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5917 | return; |
| 5918 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5919 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5920 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5921 | * and mempool_free's the nodelist. |
| 5922 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5923 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5924 | lpfc_nlp_release(struct kref *kref) |
| 5925 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5926 | struct lpfc_hba *phba; |
| 5927 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5928 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 5929 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5930 | |
| 5931 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5932 | "node release: did:x%x flg:x%x type:x%x", |
| 5933 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 5934 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5935 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5936 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 5937 | "usgmap:x%x refcnt:%d rpi:%x\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5938 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5939 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5940 | |
| 5941 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5942 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5943 | |
| 5944 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5945 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5946 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5947 | NLP_CLR_NODE_ACT(ndlp); |
| 5948 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5949 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5950 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5951 | |
| 5952 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5953 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5954 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5955 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5956 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 5957 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5958 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5959 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5960 | } |
| 5961 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5962 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 5963 | * that one discovery thread won't free a ndlp while another discovery thread |
| 5964 | * is using it. |
| 5965 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5966 | struct lpfc_nodelist * |
| 5967 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 5968 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5969 | struct lpfc_hba *phba; |
| 5970 | unsigned long flags; |
| 5971 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5972 | if (ndlp) { |
| 5973 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5974 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 5975 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5976 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5977 | /* The check of ndlp usage to prevent incrementing the |
| 5978 | * ndlp reference count that is in the process of being |
| 5979 | * released. |
| 5980 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5981 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5982 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5983 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 5984 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5985 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5986 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 5987 | "usgmap:x%x refcnt:%d\n", |
| 5988 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 5989 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5990 | return NULL; |
| 5991 | } else |
| 5992 | kref_get(&ndlp->kref); |
| 5993 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5994 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5995 | return ndlp; |
| 5996 | } |
| 5997 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5998 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5999 | * count goes to 0, this indicates the the associated nodelist should be |
| 6000 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 6001 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 6002 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6003 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6004 | int |
| 6005 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 6006 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6007 | struct lpfc_hba *phba; |
| 6008 | unsigned long flags; |
| 6009 | |
| 6010 | if (!ndlp) |
| 6011 | return 1; |
| 6012 | |
| 6013 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6014 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 6015 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6016 | kref_read(&ndlp->kref)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6017 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6018 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 6019 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 6020 | * possible race condition that kref_put got invoked again |
| 6021 | * after previous one has done ndlp memory free. |
| 6022 | */ |
| 6023 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 6024 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6025 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6026 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 6027 | "usgmap:x%x refcnt:%d\n", |
| 6028 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6029 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6030 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6031 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6032 | /* Check the ndlp inactivate log flag to avoid the possible |
| 6033 | * race condition that kref_put got invoked again after ndlp |
| 6034 | * is already in inactivating state. |
| 6035 | */ |
| 6036 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 6037 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6038 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 6039 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 6040 | "usgmap:x%x refcnt:%d\n", |
| 6041 | (void *)ndlp, ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6042 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6043 | return 1; |
| 6044 | } |
| 6045 | /* For last put, mark the ndlp usage flags to make sure no |
| 6046 | * other kref_get and kref_put on the same ndlp shall get |
| 6047 | * in between the process when the final kref_put has been |
| 6048 | * invoked on this ndlp. |
| 6049 | */ |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6050 | if (kref_read(&ndlp->kref) == 1) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6051 | /* Indicate ndlp is put to inactive state. */ |
| 6052 | NLP_SET_IACT_REQ(ndlp); |
| 6053 | /* Acknowledge ndlp memory free has been seen. */ |
| 6054 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 6055 | NLP_SET_FREE_ACK(ndlp); |
| 6056 | } |
| 6057 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 6058 | /* Note, the kref_put returns 1 when decrementing a reference |
| 6059 | * count that was 1, it invokes the release callback function, |
| 6060 | * but it still left the reference count as 1 (not actually |
| 6061 | * performs the last decrementation). Otherwise, it actually |
| 6062 | * decrements the reference count and returns 0. |
| 6063 | */ |
| 6064 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6065 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6066 | |
| 6067 | /* 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] | 6068 | * by any other discovery thread. This routine returns 1 if the |
| 6069 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 6070 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6071 | */ |
| 6072 | int |
| 6073 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 6074 | { |
| 6075 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 6076 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 6077 | ndlp->nlp_DID, ndlp->nlp_flag, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 6078 | kref_read(&ndlp->kref)); |
| 6079 | if (kref_read(&ndlp->kref) == 1) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6080 | if (lpfc_nlp_put(ndlp)) |
| 6081 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6082 | return 0; |
| 6083 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6084 | |
| 6085 | /** |
| 6086 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 6087 | * @phba: Pointer to hba context object. |
| 6088 | * |
| 6089 | * This function iterate through all FC nodes associated |
| 6090 | * will all vports to check if there is any node with |
| 6091 | * fc_rports associated with it. If there is an fc_rport |
| 6092 | * associated with the node, then the node is either in |
| 6093 | * discovered state or its devloss_timer is pending. |
| 6094 | */ |
| 6095 | static int |
| 6096 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 6097 | { |
| 6098 | struct lpfc_vport **vports; |
| 6099 | int i, ret = 0; |
| 6100 | struct lpfc_nodelist *ndlp; |
| 6101 | struct Scsi_Host *shost; |
| 6102 | |
| 6103 | vports = lpfc_create_vport_work_array(phba); |
| 6104 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6105 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 6106 | if (!vports) |
| 6107 | return 1; |
| 6108 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6109 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6110 | shost = lpfc_shost_from_vport(vports[i]); |
| 6111 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6112 | /* |
| 6113 | * IF the CVL_RCVD bit is not set then we have sent the |
| 6114 | * flogi. |
| 6115 | * If dev_loss fires while we are waiting we do not want to |
| 6116 | * unreg the fcf. |
| 6117 | */ |
| 6118 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 6119 | spin_unlock_irq(shost->host_lock); |
| 6120 | ret = 1; |
| 6121 | goto out; |
| 6122 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6123 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 6124 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 6125 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 6126 | ret = 1; |
| 6127 | spin_unlock_irq(shost->host_lock); |
| 6128 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6129 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 6130 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6131 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6132 | "2624 RPI %x DID %x flag %x " |
| 6133 | "still logged in\n", |
| 6134 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 6135 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6136 | } |
| 6137 | } |
| 6138 | spin_unlock_irq(shost->host_lock); |
| 6139 | } |
| 6140 | out: |
| 6141 | lpfc_destroy_vport_work_array(phba, vports); |
| 6142 | return ret; |
| 6143 | } |
| 6144 | |
| 6145 | /** |
| 6146 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 6147 | * @phba: Pointer to hba context object. |
| 6148 | * @mboxq: Pointer to mailbox object. |
| 6149 | * |
| 6150 | * This function frees memory associated with the mailbox command. |
| 6151 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6152 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6153 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6154 | { |
| 6155 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6156 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6157 | |
| 6158 | if (mboxq->u.mb.mbxStatus) { |
| 6159 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6160 | "2555 UNREG_VFI mbxStatus error x%x " |
| 6161 | "HBA state x%x\n", |
| 6162 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6163 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6164 | spin_lock_irq(shost->host_lock); |
| 6165 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 6166 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6167 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6168 | return; |
| 6169 | } |
| 6170 | |
| 6171 | /** |
| 6172 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 6173 | * @phba: Pointer to hba context object. |
| 6174 | * @mboxq: Pointer to mailbox object. |
| 6175 | * |
| 6176 | * This function frees memory associated with the mailbox command. |
| 6177 | */ |
| 6178 | static void |
| 6179 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6180 | { |
| 6181 | struct lpfc_vport *vport = mboxq->vport; |
| 6182 | |
| 6183 | if (mboxq->u.mb.mbxStatus) { |
| 6184 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 6185 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 6186 | "HBA state x%x\n", |
| 6187 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 6188 | } |
| 6189 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6190 | return; |
| 6191 | } |
| 6192 | |
| 6193 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6194 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6195 | * @phba: Pointer to hba context object. |
| 6196 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6197 | * This function prepare the HBA for unregistering the currently registered |
| 6198 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 6199 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6200 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6201 | int |
| 6202 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6203 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6204 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6205 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6206 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6207 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6208 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6209 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6210 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6211 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6212 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6213 | /* At this point, all discovery is aborted */ |
| 6214 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6215 | |
| 6216 | /* Unregister VPIs */ |
| 6217 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6218 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6219 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6220 | /* Stop FLOGI/FDISC retries */ |
| 6221 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6222 | if (ndlp) |
| 6223 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6224 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6225 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6226 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6227 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6228 | shost = lpfc_shost_from_vport(vports[i]); |
| 6229 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 6230 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6231 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 6232 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6233 | } |
| 6234 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 6235 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 6236 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6237 | if (ndlp) |
| 6238 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 6239 | lpfc_cleanup_pending_mbox(phba->pport); |
| 6240 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6241 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 6242 | lpfc_mbx_unreg_vpi(phba->pport); |
| 6243 | shost = lpfc_shost_from_vport(phba->pport); |
| 6244 | spin_lock_irq(shost->host_lock); |
| 6245 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 6246 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 6247 | spin_unlock_irq(shost->host_lock); |
| 6248 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6249 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6250 | /* Cleanup any outstanding ELS commands */ |
| 6251 | lpfc_els_flush_all_cmd(phba); |
| 6252 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6253 | /* Unregister the physical port VFI */ |
| 6254 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 6255 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | /** |
| 6259 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 6260 | * @phba: Pointer to hba context object. |
| 6261 | * |
| 6262 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 6263 | * unregister the currently registered FCF record. The driver does not reset |
| 6264 | * the driver FCF usage state flags. |
| 6265 | * |
| 6266 | * Return 0 if successfully issued, none-zero otherwise. |
| 6267 | */ |
| 6268 | int |
| 6269 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6270 | { |
| 6271 | LPFC_MBOXQ_t *mbox; |
| 6272 | int rc; |
| 6273 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6274 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6275 | if (!mbox) { |
| 6276 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6277 | "2551 UNREG_FCFI mbox allocation failed" |
| 6278 | "HBA state x%x\n", phba->pport->port_state); |
| 6279 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6280 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6281 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6282 | mbox->vport = phba->pport; |
| 6283 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6284 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6285 | |
| 6286 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6287 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6288 | "2552 Unregister FCFI command failed rc x%x " |
| 6289 | "HBA state x%x\n", |
| 6290 | rc, phba->pport->port_state); |
| 6291 | return -EINVAL; |
| 6292 | } |
| 6293 | return 0; |
| 6294 | } |
| 6295 | |
| 6296 | /** |
| 6297 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6298 | * @phba: Pointer to hba context object. |
| 6299 | * |
| 6300 | * This function unregisters the currently reigstered FCF. This function |
| 6301 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6302 | */ |
| 6303 | void |
| 6304 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6305 | { |
| 6306 | int rc; |
| 6307 | |
| 6308 | /* Preparation for unregistering fcf */ |
| 6309 | rc = lpfc_unregister_fcf_prep(phba); |
| 6310 | if (rc) { |
| 6311 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6312 | "2748 Failed to prepare for unregistering " |
| 6313 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6314 | return; |
| 6315 | } |
| 6316 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6317 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6318 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6319 | if (rc) |
| 6320 | return; |
| 6321 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6322 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6323 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6324 | |
| 6325 | /* |
| 6326 | * If driver is not unloading, check if there is any other |
| 6327 | * FCF record that can be used for discovery. |
| 6328 | */ |
| 6329 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6330 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6331 | return; |
| 6332 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6333 | /* This is considered as the initial FCF discovery scan */ |
| 6334 | spin_lock_irq(&phba->hbalock); |
| 6335 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6336 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6337 | |
| 6338 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6339 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6340 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6341 | 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] | 6342 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6343 | if (rc) { |
| 6344 | spin_lock_irq(&phba->hbalock); |
| 6345 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6346 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6347 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6348 | "2553 lpfc_unregister_unused_fcf failed " |
| 6349 | "to read FCF record HBA state x%x\n", |
| 6350 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6351 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | /** |
| 6355 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6356 | * @phba: Pointer to hba context object. |
| 6357 | * |
| 6358 | * This function just unregisters the currently reigstered FCF. It does not |
| 6359 | * try to find another FCF for discovery. |
| 6360 | */ |
| 6361 | void |
| 6362 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6363 | { |
| 6364 | int rc; |
| 6365 | |
| 6366 | /* Preparation for unregistering fcf */ |
| 6367 | rc = lpfc_unregister_fcf_prep(phba); |
| 6368 | if (rc) { |
| 6369 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6370 | "2749 Failed to prepare for unregistering " |
| 6371 | "HBA's FCF record: rc=%d\n", rc); |
| 6372 | return; |
| 6373 | } |
| 6374 | |
| 6375 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6376 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6377 | if (rc) |
| 6378 | return; |
| 6379 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6380 | spin_lock_irq(&phba->hbalock); |
| 6381 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6382 | spin_unlock_irq(&phba->hbalock); |
| 6383 | } |
| 6384 | |
| 6385 | /** |
| 6386 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6387 | * @phba: Pointer to hba context object. |
| 6388 | * |
| 6389 | * This function check if there are any connected remote port for the FCF and |
| 6390 | * if all the devices are disconnected, this function unregister FCFI. |
| 6391 | * This function also tries to use another FCF for discovery. |
| 6392 | */ |
| 6393 | void |
| 6394 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6395 | { |
| 6396 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6397 | * If HBA is not running in FIP mode, if HBA does not support |
| 6398 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6399 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6400 | */ |
| 6401 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6402 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6403 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6404 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6405 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6406 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6407 | spin_unlock_irq(&phba->hbalock); |
| 6408 | return; |
| 6409 | } |
| 6410 | spin_unlock_irq(&phba->hbalock); |
| 6411 | |
| 6412 | if (lpfc_fcf_inuse(phba)) |
| 6413 | return; |
| 6414 | |
| 6415 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | /** |
| 6419 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6420 | * @phba: Pointer to hba context object. |
| 6421 | * @buff: Buffer containing the FCF connection table as in the config |
| 6422 | * region. |
| 6423 | * This function create driver data structure for the FCF connection |
| 6424 | * record table read from config region 23. |
| 6425 | */ |
| 6426 | static void |
| 6427 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6428 | uint8_t *buff) |
| 6429 | { |
| 6430 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6431 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6432 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6433 | uint32_t record_count; |
| 6434 | int i; |
| 6435 | |
| 6436 | /* Free the current connect table */ |
| 6437 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6438 | &phba->fcf_conn_rec_list, list) { |
| 6439 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6440 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6441 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6442 | |
| 6443 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6444 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6445 | sizeof(struct lpfc_fcf_conn_rec); |
| 6446 | |
| 6447 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6448 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6449 | |
| 6450 | for (i = 0; i < record_count; i++) { |
| 6451 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6452 | continue; |
| 6453 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6454 | GFP_KERNEL); |
| 6455 | if (!conn_entry) { |
| 6456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6457 | "2566 Failed to allocate connection" |
| 6458 | " table entry\n"); |
| 6459 | return; |
| 6460 | } |
| 6461 | |
| 6462 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6463 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6464 | list_add_tail(&conn_entry->list, |
| 6465 | &phba->fcf_conn_rec_list); |
| 6466 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6467 | |
| 6468 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6469 | i = 0; |
| 6470 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6471 | list) { |
| 6472 | conn_rec = &conn_entry->conn_rec; |
| 6473 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6474 | "3345 FCF connection list rec[%02d]: " |
| 6475 | "flags:x%04x, vtag:x%04x, " |
| 6476 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6477 | "%02x:%02x:%02x:%02x, " |
| 6478 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6479 | "%02x:%02x:%02x:%02x\n", i++, |
| 6480 | conn_rec->flags, conn_rec->vlan_tag, |
| 6481 | conn_rec->fabric_name[0], |
| 6482 | conn_rec->fabric_name[1], |
| 6483 | conn_rec->fabric_name[2], |
| 6484 | conn_rec->fabric_name[3], |
| 6485 | conn_rec->fabric_name[4], |
| 6486 | conn_rec->fabric_name[5], |
| 6487 | conn_rec->fabric_name[6], |
| 6488 | conn_rec->fabric_name[7], |
| 6489 | conn_rec->switch_name[0], |
| 6490 | conn_rec->switch_name[1], |
| 6491 | conn_rec->switch_name[2], |
| 6492 | conn_rec->switch_name[3], |
| 6493 | conn_rec->switch_name[4], |
| 6494 | conn_rec->switch_name[5], |
| 6495 | conn_rec->switch_name[6], |
| 6496 | conn_rec->switch_name[7]); |
| 6497 | } |
| 6498 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | /** |
| 6502 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6503 | * @phba: Pointer to hba context object. |
| 6504 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6505 | * |
| 6506 | * This function update driver data structure with config |
| 6507 | * parameters read from config region 23. |
| 6508 | */ |
| 6509 | static void |
| 6510 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6511 | uint8_t *buff) |
| 6512 | { |
| 6513 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6514 | struct lpfc_fcoe_params *fcoe_param; |
| 6515 | |
| 6516 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6517 | buff; |
| 6518 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6519 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6520 | |
| 6521 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6522 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6523 | return; |
| 6524 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6525 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6526 | phba->valid_vlan = 1; |
| 6527 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6528 | 0xFFF; |
| 6529 | } |
| 6530 | |
| 6531 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6532 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6533 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6534 | return; |
| 6535 | } |
| 6536 | |
| 6537 | /** |
| 6538 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6539 | * @buff: Buffer containing config region 23 data. |
| 6540 | * @size: Size of the data buffer. |
| 6541 | * @rec_type: Record type to be searched. |
| 6542 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6543 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6544 | * of the record specified by record_type. If record found, this |
| 6545 | * function return pointer to the record else return NULL. |
| 6546 | */ |
| 6547 | static uint8_t * |
| 6548 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6549 | { |
| 6550 | uint32_t offset = 0, rec_length; |
| 6551 | |
| 6552 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6553 | (size < sizeof(uint32_t))) |
| 6554 | return NULL; |
| 6555 | |
| 6556 | rec_length = buff[offset + 1]; |
| 6557 | |
| 6558 | /* |
| 6559 | * One TLV record has one word header and number of data words |
| 6560 | * specified in the rec_length field of the record header. |
| 6561 | */ |
| 6562 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6563 | <= size) { |
| 6564 | if (buff[offset] == rec_type) |
| 6565 | return &buff[offset]; |
| 6566 | |
| 6567 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6568 | return NULL; |
| 6569 | |
| 6570 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6571 | rec_length = buff[offset + 1]; |
| 6572 | } |
| 6573 | return NULL; |
| 6574 | } |
| 6575 | |
| 6576 | /** |
| 6577 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6578 | * @phba: Pointer to lpfc_hba data structure. |
| 6579 | * @buff: Buffer containing config region 23 data. |
| 6580 | * @size: Size of the data buffer. |
| 6581 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6582 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6583 | * populate driver data structure with the parameters. |
| 6584 | */ |
| 6585 | void |
| 6586 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6587 | uint8_t *buff, |
| 6588 | uint32_t size) |
| 6589 | { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6590 | uint32_t offset = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6591 | uint8_t *rec_ptr; |
| 6592 | |
| 6593 | /* |
| 6594 | * If data size is less than 2 words signature and version cannot be |
| 6595 | * verified. |
| 6596 | */ |
| 6597 | if (size < 2*sizeof(uint32_t)) |
| 6598 | return; |
| 6599 | |
| 6600 | /* Check the region signature first */ |
| 6601 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6603 | "2567 Config region 23 has bad signature\n"); |
| 6604 | return; |
| 6605 | } |
| 6606 | |
| 6607 | offset += 4; |
| 6608 | |
| 6609 | /* Check the data structure version */ |
| 6610 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6611 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6612 | "2568 Config region 23 has bad version\n"); |
| 6613 | return; |
| 6614 | } |
| 6615 | offset += 4; |
| 6616 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6617 | /* Read FCoE param record */ |
| 6618 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6619 | size - offset, FCOE_PARAM_TYPE); |
| 6620 | if (rec_ptr) |
| 6621 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6622 | |
| 6623 | /* Read FCF connection table */ |
| 6624 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6625 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6626 | if (rec_ptr) |
| 6627 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6628 | |
| 6629 | } |