| 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 | b857ff3 | 2014-04-04 13:52:50 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2014 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> |
| 28 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_transport_fc.h> |
| 33 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 45 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | |
| 47 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 48 | static uint8_t lpfcAlpaArray[] = { |
| 49 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 50 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 51 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 52 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 53 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 54 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 55 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 56 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 57 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 58 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 59 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 60 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 61 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 62 | }; |
| 63 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 64 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 65 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 66 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 67 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 69 | void |
| 70 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 71 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 72 | struct lpfc_rport_data *rdata; |
| 73 | struct lpfc_nodelist * ndlp; |
| 74 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 76 | rdata = rport->dd_data; |
| 77 | ndlp = rdata->pnode; |
| 78 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 79 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 80 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 81 | printk(KERN_ERR "Cannot find remote node" |
| 82 | " to terminate I/O Data x%x\n", |
| 83 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 87 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 88 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 89 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 90 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 91 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 92 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 93 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 94 | lpfc_sli_abort_iocb(ndlp->vport, |
| 95 | &phba->sli.ring[phba->sli.fcp_ring], |
| 96 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 97 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* |
| 101 | * This function will be called when dev_loss_tmo fire. |
| 102 | */ |
| 103 | void |
| 104 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 105 | { |
| 106 | struct lpfc_rport_data *rdata; |
| 107 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 109 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 110 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 111 | int put_node; |
| 112 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 113 | |
| 114 | rdata = rport->dd_data; |
| 115 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 116 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 117 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 118 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 119 | vport = ndlp->vport; |
| 120 | phba = vport->phba; |
| 121 | |
| 122 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 123 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 124 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 125 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 126 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 127 | "3181 dev_loss_callbk x%06x, rport %p flg x%x\n", |
| 128 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 129 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 130 | /* Don't defer this if we are in the process of deleting the vport |
| 131 | * or unloading the driver. The unload will cleanup the node |
| 132 | * appropriately we just need to cleanup the ndlp rport info here. |
| 133 | */ |
| 134 | if (vport->load_flag & FC_UNLOADING) { |
| 135 | put_node = rdata->pnode != NULL; |
| 136 | put_rport = ndlp->rport != NULL; |
| 137 | rdata->pnode = NULL; |
| 138 | ndlp->rport = NULL; |
| 139 | if (put_node) |
| 140 | lpfc_nlp_put(ndlp); |
| 141 | if (put_rport) |
| 142 | put_device(&rport->dev); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 147 | return; |
| 148 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 149 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 150 | |
| 151 | /* If the WWPN of the rport and ndlp don't match, ignore it */ |
| 152 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) { |
| 153 | put_device(&rport->dev); |
| 154 | return; |
| 155 | } |
| 156 | } |
| 157 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 158 | evtp = &ndlp->dev_loss_evt; |
| 159 | |
| 160 | if (!list_empty(&evtp->evt_listp)) |
| 161 | return; |
| 162 | |
James Smart | a62a435 | 2013-04-17 20:18:19 -0400 | [diff] [blame] | 163 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 164 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 165 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 166 | /* We need to hold the node by incrementing the reference |
| 167 | * count until this queued work is done |
| 168 | */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 169 | if (evtp->evt_arg1) { |
| 170 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 171 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 172 | lpfc_worker_wake_up(phba); |
| 173 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 174 | spin_unlock_irq(&phba->hbalock); |
| 175 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 179 | /** |
| 180 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 181 | * @ndlp: Pointer to remote node object. |
| 182 | * |
| 183 | * This function is called from the worker thread when devloss timeout timer |
| 184 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 185 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 186 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 187 | * when devloss timeout happened to this @ndlp. |
| 188 | **/ |
| 189 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 190 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 191 | { |
| 192 | struct lpfc_rport_data *rdata; |
| 193 | struct fc_rport *rport; |
| 194 | struct lpfc_vport *vport; |
| 195 | struct lpfc_hba *phba; |
| 196 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 197 | int put_node; |
| 198 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 199 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 200 | int fcf_inuse = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 201 | |
| 202 | rport = ndlp->rport; |
| 203 | |
| 204 | if (!rport) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 205 | return fcf_inuse; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 206 | |
| 207 | rdata = rport->dd_data; |
| 208 | name = (uint8_t *) &ndlp->nlp_portname; |
| 209 | vport = ndlp->vport; |
| 210 | phba = vport->phba; |
| 211 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 212 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 213 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 214 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 215 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 216 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 217 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 218 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 219 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 220 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", |
| 221 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 222 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 223 | /* Don't defer this if we are in the process of deleting the vport |
| 224 | * or unloading the driver. The unload will cleanup the node |
| 225 | * appropriately we just need to cleanup the ndlp rport info here. |
| 226 | */ |
| 227 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 228 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 229 | /* flush the target */ |
| 230 | lpfc_sli_abort_iocb(vport, |
| 231 | &phba->sli.ring[phba->sli.fcp_ring], |
| 232 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 233 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 234 | put_node = rdata->pnode != NULL; |
| 235 | put_rport = ndlp->rport != NULL; |
| 236 | rdata->pnode = NULL; |
| 237 | ndlp->rport = NULL; |
| 238 | if (put_node) |
| 239 | lpfc_nlp_put(ndlp); |
| 240 | if (put_rport) |
| 241 | put_device(&rport->dev); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 242 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 243 | } |
| 244 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 245 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 247 | "0284 Devloss timeout Ignored on " |
| 248 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 249 | "NPort x%x\n", |
| 250 | *name, *(name+1), *(name+2), *(name+3), |
| 251 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 252 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 253 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 254 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 255 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 257 | /* We will clean up these Nodes in linkup */ |
| 258 | put_node = rdata->pnode != NULL; |
| 259 | put_rport = ndlp->rport != NULL; |
| 260 | rdata->pnode = NULL; |
| 261 | ndlp->rport = NULL; |
| 262 | if (put_node) |
| 263 | lpfc_nlp_put(ndlp); |
| 264 | if (put_rport) |
| 265 | put_device(&rport->dev); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 266 | return fcf_inuse; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 267 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 268 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 270 | warn_on = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | /* flush the target */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 272 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 273 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 275 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 276 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 277 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 278 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 279 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 280 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 281 | *name, *(name+1), *(name+2), *(name+3), |
| 282 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 283 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 284 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 285 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 286 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 287 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 288 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 289 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 290 | *name, *(name+1), *(name+2), *(name+3), |
| 291 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 292 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 293 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 294 | } |
| 295 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 296 | put_node = rdata->pnode != NULL; |
| 297 | put_rport = ndlp->rport != NULL; |
| 298 | rdata->pnode = NULL; |
| 299 | ndlp->rport = NULL; |
| 300 | if (put_node) |
| 301 | lpfc_nlp_put(ndlp); |
| 302 | if (put_rport) |
| 303 | put_device(&rport->dev); |
| 304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 305 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 306 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 307 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 308 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 309 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 310 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 311 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 312 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 313 | return fcf_inuse; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 318 | * @phba: Pointer to hba context object. |
| 319 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 320 | * @nlp_did: remote node identifer with devloss timeout. |
| 321 | * |
| 322 | * This function is called from the worker thread after invoking devloss |
| 323 | * timeout handler and releasing the reference count for the ndlp with |
| 324 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 325 | * timeout of the last remote node which had been in use of FCF, when this |
| 326 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 327 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 328 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 329 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 330 | * engine is in FCF discovery process, the devloss timeout state shall |
| 331 | * be set for either the FCF table scan process or roundrobin failover |
| 332 | * process to unregister the in-use FCF. |
| 333 | **/ |
| 334 | static void |
| 335 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 336 | uint32_t nlp_did) |
| 337 | { |
| 338 | /* If devloss timeout happened to a remote node when FCF had no |
| 339 | * longer been in-use, do nothing. |
| 340 | */ |
| 341 | if (!fcf_inuse) |
| 342 | return; |
| 343 | |
| 344 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 345 | spin_lock_irq(&phba->hbalock); |
| 346 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 347 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 348 | spin_unlock_irq(&phba->hbalock); |
| 349 | return; |
| 350 | } |
| 351 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 352 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 353 | "2847 Last remote node (x%x) using " |
| 354 | "FCF devloss tmo\n", nlp_did); |
| 355 | } |
| 356 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 357 | spin_unlock_irq(&phba->hbalock); |
| 358 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 359 | "2868 Devloss tmo to FCF rediscovery " |
| 360 | "in progress\n"); |
| 361 | return; |
| 362 | } |
| 363 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 364 | spin_unlock_irq(&phba->hbalock); |
| 365 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 366 | "2869 Devloss tmo to idle FIP engine, " |
| 367 | "unreg in-use FCF and rescan.\n"); |
| 368 | /* Unregister in-use FCF and rescan */ |
| 369 | lpfc_unregister_fcf_rescan(phba); |
| 370 | return; |
| 371 | } |
| 372 | spin_unlock_irq(&phba->hbalock); |
| 373 | if (phba->hba_flag & FCF_TS_INPROG) |
| 374 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 375 | "2870 FCF table scan in progress\n"); |
| 376 | if (phba->hba_flag & FCF_RR_INPROG) |
| 377 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 378 | "2871 FLOGI roundrobin FCF failover " |
| 379 | "in progress\n"); |
| 380 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 381 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 382 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 383 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 385 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 386 | * @phba: Pointer to hba context object. |
| 387 | * |
| 388 | * This function is called from the functions which need to post |
| 389 | * events from interrupt context. This function allocates data |
| 390 | * structure required for posting event. It also keeps track of |
| 391 | * number of events pending and prevent event storm when there are |
| 392 | * too many events. |
| 393 | **/ |
| 394 | struct lpfc_fast_path_event * |
| 395 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 396 | struct lpfc_fast_path_event *ret; |
| 397 | |
| 398 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 399 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 400 | return NULL; |
| 401 | |
| 402 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 403 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 404 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 405 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 406 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 407 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 408 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 413 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 414 | * @phba: Pointer to hba context object. |
| 415 | * @evt: Event object which need to be freed. |
| 416 | * |
| 417 | * This function frees the data structure required for posting |
| 418 | * events. |
| 419 | **/ |
| 420 | void |
| 421 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 422 | struct lpfc_fast_path_event *evt) { |
| 423 | |
| 424 | atomic_dec(&phba->fast_event_count); |
| 425 | kfree(evt); |
| 426 | } |
| 427 | |
| 428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 429 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 430 | * @phba: Pointer to hba context object. |
| 431 | * @evtp: Event data structure. |
| 432 | * |
| 433 | * This function is called from worker thread, when the interrupt |
| 434 | * context need to post an event. This function posts the event |
| 435 | * to fc transport netlink interface. |
| 436 | **/ |
| 437 | static void |
| 438 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 439 | struct lpfc_work_evt *evtp) |
| 440 | { |
| 441 | unsigned long evt_category, evt_sub_category; |
| 442 | struct lpfc_fast_path_event *fast_evt_data; |
| 443 | char *evt_data; |
| 444 | uint32_t evt_data_size; |
| 445 | struct Scsi_Host *shost; |
| 446 | |
| 447 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 448 | work_evt); |
| 449 | |
| 450 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 451 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 452 | fabric_evt.subcategory; |
| 453 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 454 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 455 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 456 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 457 | evt_data_size = sizeof(fast_evt_data->un. |
| 458 | read_check_error); |
| 459 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 460 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 461 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 462 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 463 | } else { |
| 464 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 465 | return; |
| 466 | } |
| 467 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 468 | switch (evt_sub_category) { |
| 469 | case LPFC_EVENT_QFULL: |
| 470 | case LPFC_EVENT_DEVBSY: |
| 471 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 472 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 473 | break; |
| 474 | case LPFC_EVENT_CHECK_COND: |
| 475 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 476 | evt_data_size = sizeof(fast_evt_data->un. |
| 477 | check_cond_evt); |
| 478 | break; |
| 479 | case LPFC_EVENT_VARQUEDEPTH: |
| 480 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 481 | evt_data_size = sizeof(fast_evt_data->un. |
| 482 | queue_depth_evt); |
| 483 | break; |
| 484 | default: |
| 485 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 486 | return; |
| 487 | } |
| 488 | } else { |
| 489 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | fc_host_post_vendor_event(shost, |
| 494 | fc_get_event_number(), |
| 495 | evt_data_size, |
| 496 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 497 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 498 | |
| 499 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 500 | return; |
| 501 | } |
| 502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | { |
| 506 | struct lpfc_work_evt *evtp = NULL; |
| 507 | struct lpfc_nodelist *ndlp; |
| 508 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 509 | int fcf_inuse; |
| 510 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_lock_irq(&phba->hbalock); |
| 513 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 515 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 516 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 518 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 520 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 522 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 523 | /* decrement the node reference count held |
| 524 | * for this queued work |
| 525 | */ |
| 526 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 528 | case LPFC_EVT_DEV_LOSS: |
| 529 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 530 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 531 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 532 | /* decrement the node reference count held for |
| 533 | * this queued work |
| 534 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 535 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 536 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 537 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 538 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 539 | fcf_inuse, |
| 540 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 541 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 543 | if (phba->link_state < LPFC_LINK_DOWN) |
| 544 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 545 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 546 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 547 | complete((struct completion *)(evtp->evt_arg2)); |
| 548 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 549 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 550 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 551 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 552 | *(int *)(evtp->evt_arg1) = 0; |
| 553 | complete((struct completion *)(evtp->evt_arg2)); |
| 554 | break; |
| 555 | case LPFC_EVT_OFFLINE: |
| 556 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 557 | lpfc_sli_brdrestart(phba); |
| 558 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 559 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 560 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 561 | complete((struct completion *)(evtp->evt_arg2)); |
| 562 | break; |
| 563 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 564 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 565 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 566 | lpfc_sli_brdreset(phba); |
| 567 | lpfc_hba_down_post(phba); |
| 568 | *(int *)(evtp->evt_arg1) = |
| 569 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 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_KILL: |
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 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 576 | = (phba->pport->stopped) |
| 577 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 578 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 579 | complete((struct completion *)(evtp->evt_arg2)); |
| 580 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 581 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 582 | lpfc_send_fastpath_evt(phba, evtp); |
| 583 | free_evt = 0; |
| 584 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 585 | case LPFC_EVT_RESET_HBA: |
| 586 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 587 | lpfc_reset_hba(phba); |
| 588 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | } |
| 590 | if (free_evt) |
| 591 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 592 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 594 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 595 | |
| 596 | } |
| 597 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 598 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 599 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | { |
| 601 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 602 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 603 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 604 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 605 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 607 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | ha_copy = phba->work_ha; |
| 609 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 610 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 611 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 612 | /* First, try to post the next mailbox command to SLI4 device */ |
| 613 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 614 | lpfc_sli4_post_async_mbox(phba); |
| 615 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 616 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 617 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 618 | lpfc_handle_eratt(phba); |
| 619 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 620 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | lpfc_sli_handle_mb_event(phba); |
| 622 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 623 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 625 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 626 | /* Process SLI4 events */ |
| 627 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 628 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 629 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 630 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 631 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 632 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 633 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 634 | if (phba->hba_flag & ASYNC_EVENT) |
| 635 | lpfc_sli4_async_event_proc(phba); |
| 636 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 637 | spin_lock_irq(&phba->hbalock); |
| 638 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 639 | spin_unlock_irq(&phba->hbalock); |
| 640 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 641 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 642 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 643 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 644 | } |
| 645 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 646 | vports = lpfc_create_vport_work_array(phba); |
| 647 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 648 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 649 | /* |
| 650 | * We could have no vports in array if unloading, so if |
| 651 | * this happens then just use the pport |
| 652 | */ |
| 653 | if (vports[i] == NULL && i == 0) |
| 654 | vport = phba->pport; |
| 655 | else |
| 656 | vport = vports[i]; |
| 657 | if (vport == NULL) |
| 658 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 659 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 660 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 661 | vport->work_port_events &= ~work_port_events; |
| 662 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 663 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 664 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 665 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 666 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 667 | if (work_port_events & WORKER_HB_TMO) |
| 668 | lpfc_hb_timeout_handler(phba); |
| 669 | if (work_port_events & WORKER_MBOX_TMO) |
| 670 | lpfc_mbox_timeout_handler(phba); |
| 671 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 672 | lpfc_unblock_fabric_iocbs(phba); |
| 673 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 674 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 675 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 676 | lpfc_ramp_down_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 677 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 678 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 679 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 680 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 681 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 682 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 683 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 684 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 685 | if ((status & HA_RXMASK) || |
| 686 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 687 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 688 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 689 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 690 | /* Set the lpfc data pending flag */ |
| 691 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 692 | } else { |
James Smart | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 693 | if (phba->link_state >= LPFC_LINK_UP) { |
| 694 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 695 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 696 | (status & |
| 697 | HA_RXMASK)); |
| 698 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 699 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 700 | if ((phba->sli_rev == LPFC_SLI_REV4) & |
| 701 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 702 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 703 | /* |
| 704 | * Turn on Ring interrupts |
| 705 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 706 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 707 | spin_lock_irq(&phba->hbalock); |
| 708 | control = readl(phba->HCregaddr); |
| 709 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 710 | lpfc_debugfs_slow_ring_trc(phba, |
| 711 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 712 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 713 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 714 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 715 | writel(control, phba->HCregaddr); |
| 716 | readl(phba->HCregaddr); /* flush */ |
| 717 | } else { |
| 718 | lpfc_debugfs_slow_ring_trc(phba, |
| 719 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 720 | control, ha_copy, 0); |
| 721 | } |
| 722 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 723 | } |
| 724 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 725 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | } |
| 727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | int |
| 729 | lpfc_do_work(void *p) |
| 730 | { |
| 731 | struct lpfc_hba *phba = p; |
| 732 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 734 | set_user_nice(current, MIN_NICE); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 735 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 736 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 738 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 739 | /* wait and check worker queue activities */ |
| 740 | rc = wait_event_interruptible(phba->work_waitq, |
| 741 | (test_and_clear_bit(LPFC_DATA_READY, |
| 742 | &phba->data_flags) |
| 743 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 744 | /* Signal wakeup shall terminate the worker thread */ |
| 745 | if (rc) { |
| 746 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 747 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 749 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 750 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 751 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 754 | phba->worker_thread = NULL; |
| 755 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 756 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | * 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] | 762 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | * embedding it in the IOCB. |
| 764 | */ |
| 765 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 766 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 767 | uint32_t evt) |
| 768 | { |
| 769 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 770 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | |
| 772 | /* |
| 773 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 774 | * be queued to worker thread for processing |
| 775 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 776 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | if (!evtp) |
| 778 | return 0; |
| 779 | |
| 780 | evtp->evt_arg1 = arg1; |
| 781 | evtp->evt_arg2 = arg2; |
| 782 | evtp->evt = evt; |
| 783 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 784 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 785 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 788 | lpfc_worker_wake_up(phba); |
| 789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | return 1; |
| 791 | } |
| 792 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 793 | void |
| 794 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 795 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 796 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | struct lpfc_hba *phba = vport->phba; |
| 798 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 799 | int rc; |
| 800 | |
| 801 | 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] | 802 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 803 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 804 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 805 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 806 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 807 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 808 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | lpfc_unreg_rpi(vport, ndlp); |
| 810 | |
| 811 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 812 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 813 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 814 | continue; |
| 815 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 816 | remove |
| 817 | ? NLP_EVT_DEVICE_RM |
| 818 | : NLP_EVT_DEVICE_RECOVERY); |
| 819 | } |
| 820 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 821 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 822 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 823 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 824 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 825 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 826 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 830 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 831 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 833 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 834 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 835 | /* Cleanup any outstanding received buffers */ |
| 836 | lpfc_cleanup_rcv_buffers(vport); |
| 837 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | /* Cleanup any outstanding RSCN activity */ |
| 839 | lpfc_els_flush_rscn(vport); |
| 840 | |
| 841 | /* Cleanup any outstanding ELS commands */ |
| 842 | lpfc_els_flush_cmd(vport); |
| 843 | |
| 844 | lpfc_cleanup_rpis(vport, 0); |
| 845 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 846 | /* Turn off discovery timer if its running */ |
| 847 | lpfc_can_disctmo(vport); |
| 848 | } |
| 849 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 850 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 851 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 852 | { |
| 853 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 854 | |
| 855 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 856 | |
| 857 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 858 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 859 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 860 | |
| 861 | lpfc_port_link_failure(vport); |
| 862 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 863 | /* Stop delayed Nport discovery */ |
| 864 | spin_lock_irq(shost->host_lock); |
| 865 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 866 | spin_unlock_irq(shost->host_lock); |
| 867 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 868 | } |
| 869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 871 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 873 | struct lpfc_vport *vport = phba->pport; |
| 874 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 875 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 876 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 877 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 879 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 880 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 881 | |
| 882 | /* Block all SCSI stack I/Os */ |
| 883 | lpfc_scsi_dev_block(phba); |
| 884 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 885 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 886 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 887 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 888 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 889 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 890 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 891 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 892 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 893 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 894 | vports = lpfc_create_vport_work_array(phba); |
| 895 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 896 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 897 | /* Issue a LINK DOWN event to all nodes */ |
| 898 | lpfc_linkdown_port(vports[i]); |
| 899 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 900 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 902 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 903 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 904 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 905 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 906 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 907 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 909 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 914 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 915 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 916 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 917 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 919 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 920 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 921 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 923 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | } |
| 925 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 927 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 928 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 931 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 932 | } |
| 933 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 934 | static void |
| 935 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 936 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 937 | struct lpfc_nodelist *ndlp; |
| 938 | |
| 939 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 940 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 941 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 942 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 943 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 944 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 945 | /* On Linkup its safe to clean up the ndlp |
| 946 | * from Fabric connections. |
| 947 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 948 | if (ndlp->nlp_DID != Fabric_DID) |
| 949 | lpfc_unreg_rpi(vport, ndlp); |
| 950 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 951 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 952 | /* Fail outstanding IO now since device is |
| 953 | * marked for PLOGI. |
| 954 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 955 | lpfc_unreg_rpi(vport, ndlp); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | static void |
| 961 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 962 | { |
| 963 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | struct lpfc_hba *phba = vport->phba; |
| 965 | |
| 966 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 967 | return; |
| 968 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 969 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 970 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 971 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 972 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 973 | /* If NPIV is not enabled, only bring the physical port up */ |
| 974 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 975 | (vport != phba->pport)) |
| 976 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 979 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 981 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 982 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 983 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 984 | vport->fc_ns_retry = 0; |
| 985 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | if (vport->fc_flag & FC_LBIT) |
| 988 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static int |
| 993 | lpfc_linkup(struct lpfc_hba *phba) |
| 994 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 995 | struct lpfc_vport **vports; |
| 996 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 997 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 998 | lpfc_cleanup_wt_rrqs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | phba->link_state = LPFC_LINK_UP; |
| 1000 | |
| 1001 | /* Unblock fabric iocbs if they are blocked */ |
| 1002 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1003 | del_timer_sync(&phba->fabric_block_timer); |
| 1004 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1005 | vports = lpfc_create_vport_work_array(phba); |
| 1006 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1007 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1008 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1009 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * This routine handles processing a CLEAR_LA mailbox |
| 1016 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1017 | * as the completion routine when the command is |
| 1018 | * handed off to the SLI layer. |
| 1019 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1020 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1021 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1022 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1023 | struct lpfc_vport *vport = pmb->vport; |
| 1024 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1025 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1026 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1027 | uint32_t control; |
| 1028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1030 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1032 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1033 | |
| 1034 | /* Check for error */ |
| 1035 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1036 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1037 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1038 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1039 | "state x%x\n", |
| 1040 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1042 | goto out; |
| 1043 | } |
| 1044 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1045 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1046 | phba->link_state = LPFC_HBA_READY; |
| 1047 | |
| 1048 | spin_lock_irq(&phba->hbalock); |
| 1049 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1050 | control = readl(phba->HCregaddr); |
| 1051 | control |= HC_LAINT_ENA; |
| 1052 | writel(control, phba->HCregaddr); |
| 1053 | readl(phba->HCregaddr); /* flush */ |
| 1054 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1055 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1056 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1058 | out: |
| 1059 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1060 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1061 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1062 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1064 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1065 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1066 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | |
| 1070 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1071 | |
| 1072 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1074 | control = readl(phba->HCregaddr); |
| 1075 | control |= HC_LAINT_ENA; |
| 1076 | writel(control, phba->HCregaddr); |
| 1077 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1078 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | |
| 1080 | return; |
| 1081 | } |
| 1082 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1085 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1087 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1089 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1091 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1092 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1093 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1094 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1095 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1096 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1097 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1098 | return; |
| 1099 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1100 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1102 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1103 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1104 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1105 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1106 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1107 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1108 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1109 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1112 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1113 | */ |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 1114 | if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1115 | lpfc_initial_flogi(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1116 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | |
| 1118 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1119 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1120 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1121 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1122 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1123 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1124 | |
| 1125 | lpfc_linkdown(phba); |
| 1126 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1127 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1128 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1129 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1130 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1131 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | return; |
| 1133 | } |
| 1134 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1135 | /** |
| 1136 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1137 | * @phba pointer to the struct lpfc_hba for this port. |
| 1138 | * This fucnction resets the round robin bit mask and clears the |
| 1139 | * fcf priority list. The list deletions are done while holding the |
| 1140 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1141 | * from the lpfc_fcf_pri record. |
| 1142 | **/ |
| 1143 | void |
| 1144 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1145 | { |
| 1146 | struct lpfc_fcf_pri *fcf_pri; |
| 1147 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1148 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1149 | spin_lock_irq(&phba->hbalock); |
| 1150 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1151 | &phba->fcf.fcf_pri_list, list) { |
| 1152 | list_del_init(&fcf_pri->list); |
| 1153 | fcf_pri->fcf_rec.flag = 0; |
| 1154 | } |
| 1155 | spin_unlock_irq(&phba->hbalock); |
| 1156 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1158 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1159 | { |
| 1160 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1161 | |
| 1162 | if (mboxq->u.mb.mbxStatus) { |
| 1163 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1164 | "2017 REG_FCFI mbxStatus error x%x " |
| 1165 | "HBA state x%x\n", |
| 1166 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1167 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1171 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1172 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1173 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1174 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1175 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1176 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1177 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1178 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1179 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1180 | goto fail_out; |
| 1181 | |
| 1182 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1183 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1184 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1185 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1186 | if (vport->port_state != LPFC_FLOGI) { |
| 1187 | phba->hba_flag |= FCF_RR_INPROG; |
| 1188 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1189 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1190 | goto out; |
| 1191 | } |
| 1192 | spin_unlock_irq(&phba->hbalock); |
| 1193 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1194 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1195 | fail_out: |
| 1196 | spin_lock_irq(&phba->hbalock); |
| 1197 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1198 | spin_unlock_irq(&phba->hbalock); |
| 1199 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1200 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1205 | * @fab_name: pointer to fabric name. |
| 1206 | * @new_fcf_record: pointer to fcf record. |
| 1207 | * |
| 1208 | * This routine compare the fcf record's fabric name with provided |
| 1209 | * fabric name. If the fabric name are identical this function |
| 1210 | * returns 1 else return 0. |
| 1211 | **/ |
| 1212 | static uint32_t |
| 1213 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1214 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1215 | 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] | 1216 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1217 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1218 | return 0; |
| 1219 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1220 | return 0; |
| 1221 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1222 | return 0; |
| 1223 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1224 | return 0; |
| 1225 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1226 | return 0; |
| 1227 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1228 | return 0; |
| 1229 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1230 | return 0; |
| 1231 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1235 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1236 | * @fab_name: pointer to fabric name. |
| 1237 | * @new_fcf_record: pointer to fcf record. |
| 1238 | * |
| 1239 | * This routine compare the fcf record's switch name with provided |
| 1240 | * switch name. If the switch name are identical this function |
| 1241 | * returns 1 else return 0. |
| 1242 | **/ |
| 1243 | static uint32_t |
| 1244 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1245 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1246 | 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] | 1247 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1248 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1249 | return 0; |
| 1250 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1251 | return 0; |
| 1252 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1253 | return 0; |
| 1254 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1255 | return 0; |
| 1256 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1257 | return 0; |
| 1258 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1259 | return 0; |
| 1260 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1261 | return 0; |
| 1262 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1266 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1267 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1268 | * @new_fcf_record: pointer to fcf record. |
| 1269 | * |
| 1270 | * This routine compare the fcf record's mac address with HBA's |
| 1271 | * FCF mac address. If the mac addresses are identical this function |
| 1272 | * returns 1 else return 0. |
| 1273 | **/ |
| 1274 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1275 | 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] | 1276 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1277 | 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] | 1278 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1279 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1280 | return 0; |
| 1281 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1282 | return 0; |
| 1283 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1284 | return 0; |
| 1285 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1286 | return 0; |
| 1287 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1288 | return 0; |
| 1289 | return 1; |
| 1290 | } |
| 1291 | |
| 1292 | static bool |
| 1293 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1294 | { |
| 1295 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1299 | * lpfc_update_fcf_record - Update driver fcf record |
| 1300 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1301 | * @phba: pointer to lpfc hba data structure. |
| 1302 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1303 | * @new_fcf_record: pointer to hba fcf record. |
| 1304 | * |
| 1305 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1306 | * record. This routine is called with the host lock held. |
| 1307 | **/ |
| 1308 | static void |
| 1309 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1310 | struct fcf_record *new_fcf_record |
| 1311 | ) |
| 1312 | { |
| 1313 | struct lpfc_fcf_pri *fcf_pri; |
| 1314 | |
| 1315 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1316 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1317 | /* FCF record priority */ |
| 1318 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1319 | |
| 1320 | } |
| 1321 | |
| 1322 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1323 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1324 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1325 | * @new_fcf_record: pointer to fcf record. |
| 1326 | * |
| 1327 | * This routine copies the FCF information from the FCF |
| 1328 | * record to lpfc_hba data structure. |
| 1329 | **/ |
| 1330 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1331 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1332 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1333 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1334 | /* Fabric name */ |
| 1335 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1336 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1337 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1338 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1339 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1340 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1341 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1342 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1343 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1344 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1345 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1346 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1347 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1348 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1349 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1350 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1351 | /* Mac address */ |
| 1352 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1353 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1354 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1355 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1356 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1357 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1358 | /* FCF record index */ |
| 1359 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1360 | /* FCF record priority */ |
| 1361 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1362 | /* Switch name */ |
| 1363 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1364 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1365 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1366 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1367 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1368 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1370 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1371 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1372 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1373 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1374 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1375 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1376 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1377 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1378 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1382 | * lpfc_update_fcf_record - Update driver fcf record |
| 1383 | * @phba: pointer to lpfc hba data structure. |
| 1384 | * @fcf_rec: pointer to driver fcf record. |
| 1385 | * @new_fcf_record: pointer to hba fcf record. |
| 1386 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1387 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1388 | * @flag: flag bits to be set to the driver fcf record. |
| 1389 | * |
| 1390 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1391 | * together with the address mode, vlan_id, and other informations. This |
| 1392 | * routine is called with the host lock held. |
| 1393 | **/ |
| 1394 | static void |
| 1395 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1396 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1397 | uint16_t vlan_id, uint32_t flag) |
| 1398 | { |
| 1399 | /* Copy the fields from the HBA's FCF record */ |
| 1400 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1401 | /* Update other fields of driver FCF record */ |
| 1402 | fcf_rec->addr_mode = addr_mode; |
| 1403 | fcf_rec->vlan_id = vlan_id; |
| 1404 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1405 | __lpfc_update_fcf_record_pri(phba, |
| 1406 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1407 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1411 | * lpfc_register_fcf - Register the FCF with hba. |
| 1412 | * @phba: pointer to lpfc hba data structure. |
| 1413 | * |
| 1414 | * This routine issues a register fcfi mailbox command to register |
| 1415 | * the fcf with HBA. |
| 1416 | **/ |
| 1417 | static void |
| 1418 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1419 | { |
| 1420 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1421 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1422 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1423 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1424 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1425 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1426 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1427 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1428 | return; |
| 1429 | } |
| 1430 | |
| 1431 | /* The FCF is already registered, start discovery */ |
| 1432 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1433 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1434 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 1435 | if (phba->pport->port_state != LPFC_FLOGI && |
| 1436 | phba->pport->fc_flag & FC_FABRIC) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1437 | phba->hba_flag |= FCF_RR_INPROG; |
| 1438 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1439 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1440 | return; |
| 1441 | } |
| 1442 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1443 | return; |
| 1444 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1445 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1446 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1447 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1448 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1449 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1450 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1451 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1452 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1453 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1454 | |
| 1455 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1456 | fcf_mbxq->vport = phba->pport; |
| 1457 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1458 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1459 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1460 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1461 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1462 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1463 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1464 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1465 | |
| 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1471 | * @phba: pointer to lpfc hba data structure. |
| 1472 | * @new_fcf_record: pointer to fcf record. |
| 1473 | * @boot_flag: Indicates if this record used by boot bios. |
| 1474 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1475 | * @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] | 1476 | * |
| 1477 | * This routine compare the fcf record with connect list obtained from the |
| 1478 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1479 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1480 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1481 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1482 | * used for this FCF when the function returns. |
| 1483 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1484 | * 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] | 1485 | * 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] | 1486 | **/ |
| 1487 | static int |
| 1488 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1489 | struct fcf_record *new_fcf_record, |
| 1490 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1491 | uint16_t *vlan_id) |
| 1492 | { |
| 1493 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1494 | int i, j, fcf_vlan_id = 0; |
| 1495 | |
| 1496 | /* Find the lowest VLAN id in the FCF record */ |
| 1497 | for (i = 0; i < 512; i++) { |
| 1498 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1499 | fcf_vlan_id = i * 8; |
| 1500 | j = 0; |
| 1501 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1502 | j++; |
| 1503 | fcf_vlan_id++; |
| 1504 | } |
| 1505 | break; |
| 1506 | } |
| 1507 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1508 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1509 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1510 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1511 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1512 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1513 | return 0; |
| 1514 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1515 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1516 | *boot_flag = 0; |
| 1517 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1518 | new_fcf_record); |
| 1519 | if (phba->valid_vlan) |
| 1520 | *vlan_id = phba->vlan_id; |
| 1521 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1522 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1523 | return 1; |
| 1524 | } |
| 1525 | |
| 1526 | /* |
| 1527 | * If there are no FCF connection table entry, driver connect to all |
| 1528 | * FCFs. |
| 1529 | */ |
| 1530 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1531 | *boot_flag = 0; |
| 1532 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1533 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1534 | |
| 1535 | /* |
| 1536 | * When there are no FCF connect entries, use driver's default |
| 1537 | * addressing mode - FPMA. |
| 1538 | */ |
| 1539 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1540 | *addr_mode = LPFC_FCF_FPMA; |
| 1541 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1542 | /* If FCF record report a vlan id use that vlan id */ |
| 1543 | if (fcf_vlan_id) |
| 1544 | *vlan_id = fcf_vlan_id; |
| 1545 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1546 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1547 | return 1; |
| 1548 | } |
| 1549 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1550 | list_for_each_entry(conn_entry, |
| 1551 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1552 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1553 | continue; |
| 1554 | |
| 1555 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1556 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1557 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1558 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1559 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1560 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1561 | new_fcf_record)) |
| 1562 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1563 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1564 | /* |
| 1565 | * If the vlan bit map does not have the bit set for the |
| 1566 | * vlan id to be used, then it is not a match. |
| 1567 | */ |
| 1568 | if (!(new_fcf_record->vlan_bitmap |
| 1569 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1570 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1571 | continue; |
| 1572 | } |
| 1573 | |
| 1574 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1575 | * If connection record does not support any addressing mode, |
| 1576 | * skip the FCF record. |
| 1577 | */ |
| 1578 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1579 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1580 | continue; |
| 1581 | |
| 1582 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1583 | * Check if the connection record specifies a required |
| 1584 | * addressing mode. |
| 1585 | */ |
| 1586 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1587 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1588 | |
| 1589 | /* |
| 1590 | * If SPMA required but FCF not support this continue. |
| 1591 | */ |
| 1592 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1593 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1594 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1595 | continue; |
| 1596 | |
| 1597 | /* |
| 1598 | * If FPMA required but FCF not support this continue. |
| 1599 | */ |
| 1600 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1601 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1602 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1603 | continue; |
| 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * This fcf record matches filtering criteria. |
| 1608 | */ |
| 1609 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1610 | *boot_flag = 1; |
| 1611 | else |
| 1612 | *boot_flag = 0; |
| 1613 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1614 | /* |
| 1615 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1616 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1617 | * by FCF, allow fabric to pick the addressing mode. |
| 1618 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1619 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1620 | new_fcf_record); |
| 1621 | /* |
| 1622 | * If the user specified a required address mode, assign that |
| 1623 | * address mode |
| 1624 | */ |
| 1625 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1626 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1627 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1628 | FCFCNCT_AM_SPMA) ? |
| 1629 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1630 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1631 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1632 | * addr mode only if FCF support the addr_mode. |
| 1633 | */ |
| 1634 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1635 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1636 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1637 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1638 | *addr_mode = LPFC_FCF_SPMA; |
| 1639 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1640 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1641 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1642 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1643 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1644 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1645 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1646 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1647 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1648 | /* |
| 1649 | * If no vlan id is specified in connect list, use the vlan id |
| 1650 | * in the FCF record |
| 1651 | */ |
| 1652 | else if (fcf_vlan_id) |
| 1653 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1654 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1655 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1656 | |
| 1657 | return 1; |
| 1658 | } |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1664 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1665 | * @phba: pointer to lpfc hba data structure. |
| 1666 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1667 | * |
| 1668 | * This function check if there is any fcoe event pending while driver |
| 1669 | * scan FCF entries. If there is any pending event, it will restart the |
| 1670 | * FCF saning and return 1 else return 0. |
| 1671 | */ |
| 1672 | int |
| 1673 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1674 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1675 | /* |
| 1676 | * If the Link is up and no FCoE events while in the |
| 1677 | * FCF discovery, no need to restart FCF discovery. |
| 1678 | */ |
| 1679 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1680 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1681 | return 0; |
| 1682 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1683 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1684 | "2768 Pending link or FCF event during current " |
| 1685 | "handling of the previous event: link_state:x%x, " |
| 1686 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1687 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1688 | phba->fcoe_eventtag); |
| 1689 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1690 | spin_lock_irq(&phba->hbalock); |
| 1691 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1692 | spin_unlock_irq(&phba->hbalock); |
| 1693 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1694 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1695 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1696 | "2780 Restart FCF table scan due to " |
| 1697 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1698 | "evt_tag_current:x%x\n", |
| 1699 | phba->fcoe_eventtag_at_fcf_scan, |
| 1700 | phba->fcoe_eventtag); |
| 1701 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1702 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1703 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1704 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1705 | * flag |
| 1706 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1707 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1708 | "2833 Stop FCF discovery process due to link " |
| 1709 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1710 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1711 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1712 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1713 | spin_unlock_irq(&phba->hbalock); |
| 1714 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1715 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1716 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1717 | if (unreg_fcf) { |
| 1718 | spin_lock_irq(&phba->hbalock); |
| 1719 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1720 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1721 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1722 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1723 | return 1; |
| 1724 | } |
| 1725 | |
| 1726 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1727 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1728 | * @phba: pointer to lpfc hba data structure. |
| 1729 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1730 | * |
| 1731 | * This function makes an running random selection decision on FCF record to |
| 1732 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1733 | * probability. To perform integer manunipulation of random numbers with |
| 1734 | * 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] | 1735 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1736 | * |
| 1737 | * Returns true when outcome is for the newly read FCF record should be |
| 1738 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1739 | * chosen FCF record. |
| 1740 | **/ |
| 1741 | static bool |
| 1742 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1743 | { |
| 1744 | uint32_t rand_num; |
| 1745 | |
| 1746 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1747 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1748 | |
| 1749 | /* Decision with probability 1/fcf_cnt */ |
| 1750 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1751 | return true; |
| 1752 | else |
| 1753 | return false; |
| 1754 | } |
| 1755 | |
| 1756 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1757 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1758 | * @phba: pointer to lpfc hba data structure. |
| 1759 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1760 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1761 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1762 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1763 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1764 | * SGE parsing, and endianness swapping. |
| 1765 | * |
| 1766 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1767 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1768 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1769 | static struct fcf_record * |
| 1770 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1771 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1772 | { |
| 1773 | void *virt_addr; |
| 1774 | dma_addr_t phys_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1775 | struct lpfc_mbx_sge sge; |
| 1776 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1777 | uint32_t shdr_status, shdr_add_status; |
| 1778 | union lpfc_sli4_cfg_shdr *shdr; |
| 1779 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1780 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1781 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1782 | * routine only uses a single SGE. |
| 1783 | */ |
| 1784 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1785 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1786 | if (unlikely(!mboxq->sge_array)) { |
| 1787 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1788 | "2524 Failed to get the non-embedded SGE " |
| 1789 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1790 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1791 | } |
| 1792 | virt_addr = mboxq->sge_array->addr[0]; |
| 1793 | |
| 1794 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1795 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1796 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1797 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1798 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1799 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1800 | if (shdr_status == STATUS_FCF_TABLE_EMPTY) |
| 1801 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1802 | "2726 READ_FCF_RECORD Indicates empty " |
| 1803 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1804 | else |
| 1805 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1806 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1807 | "with status x%x add_status x%x, " |
| 1808 | "mbx\n", shdr_status, shdr_add_status); |
| 1809 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1810 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1811 | |
| 1812 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1813 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1814 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1815 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1816 | *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] | 1817 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1818 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1819 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1820 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1821 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1822 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1823 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1824 | return new_fcf_record; |
| 1825 | } |
| 1826 | |
| 1827 | /** |
| 1828 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1829 | * @phba: pointer to lpfc hba data structure. |
| 1830 | * @fcf_record: pointer to the fcf record. |
| 1831 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1832 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1833 | * |
| 1834 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1835 | * enabled. |
| 1836 | **/ |
| 1837 | static void |
| 1838 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1839 | struct fcf_record *fcf_record, |
| 1840 | uint16_t vlan_id, |
| 1841 | uint16_t next_fcf_index) |
| 1842 | { |
| 1843 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1844 | "2764 READ_FCF_RECORD:\n" |
| 1845 | "\tFCF_Index : x%x\n" |
| 1846 | "\tFCF_Avail : x%x\n" |
| 1847 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1848 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1849 | "\tFIP_Priority : x%x\n" |
| 1850 | "\tMAC_Provider : x%x\n" |
| 1851 | "\tLowest VLANID : x%x\n" |
| 1852 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1853 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1854 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1855 | "\tNext_FCF_Index: x%x\n", |
| 1856 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1857 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1858 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1859 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1860 | fcf_record->fip_priority, |
| 1861 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1862 | vlan_id, |
| 1863 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1864 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1865 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1866 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1867 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1868 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1869 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1870 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1871 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1872 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1873 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1874 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1875 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1876 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1877 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1878 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1879 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1880 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1881 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1882 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1883 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1884 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1885 | next_fcf_index); |
| 1886 | } |
| 1887 | |
| 1888 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1889 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1890 | * @phba: pointer to lpfc hba data structure. |
| 1891 | * @fcf_rec: pointer to an existing FCF record. |
| 1892 | * @new_fcf_record: pointer to a new FCF record. |
| 1893 | * @new_vlan_id: vlan id from the new FCF record. |
| 1894 | * |
| 1895 | * This function performs matching test of a new FCF record against an existing |
| 1896 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1897 | * will not be used as part of the FCF record matching criteria. |
| 1898 | * |
| 1899 | * Returns true if all the fields matching, otherwise returns false. |
| 1900 | */ |
| 1901 | static bool |
| 1902 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1903 | struct lpfc_fcf_rec *fcf_rec, |
| 1904 | struct fcf_record *new_fcf_record, |
| 1905 | uint16_t new_vlan_id) |
| 1906 | { |
| 1907 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1908 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1909 | return false; |
| 1910 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1911 | return false; |
| 1912 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1913 | return false; |
| 1914 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1915 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1916 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1917 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1918 | return true; |
| 1919 | } |
| 1920 | |
| 1921 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1922 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1923 | * @vport: Pointer to vport object. |
| 1924 | * @fcf_index: index to next fcf. |
| 1925 | * |
| 1926 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1927 | * When this function is invoked, there will be a current fcf registered |
| 1928 | * for flogi. |
| 1929 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1930 | * 1 for stop flogi on currently registered fcf; |
| 1931 | */ |
| 1932 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1933 | { |
| 1934 | struct lpfc_hba *phba = vport->phba; |
| 1935 | int rc; |
| 1936 | |
| 1937 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1938 | spin_lock_irq(&phba->hbalock); |
| 1939 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1940 | spin_unlock_irq(&phba->hbalock); |
| 1941 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1942 | "2872 Devloss tmo with no eligible " |
| 1943 | "FCF, unregister in-use FCF (x%x) " |
| 1944 | "and rescan FCF table\n", |
| 1945 | phba->fcf.current_rec.fcf_indx); |
| 1946 | lpfc_unregister_fcf_rescan(phba); |
| 1947 | goto stop_flogi_current_fcf; |
| 1948 | } |
| 1949 | /* Mark the end to FLOGI roundrobin failover */ |
| 1950 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1951 | /* Allow action to new fcf asynchronous event */ |
| 1952 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1953 | spin_unlock_irq(&phba->hbalock); |
| 1954 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1955 | "2865 No FCF available, stop roundrobin FCF " |
| 1956 | "failover and change port state:x%x/x%x\n", |
| 1957 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1958 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1959 | goto stop_flogi_current_fcf; |
| 1960 | } else { |
| 1961 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1962 | "2794 Try FLOGI roundrobin FCF failover to " |
| 1963 | "(x%x)\n", fcf_index); |
| 1964 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 1965 | if (rc) |
| 1966 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 1967 | "2761 FLOGI roundrobin FCF failover " |
| 1968 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 1969 | rc, phba->fcf.current_rec.fcf_indx); |
| 1970 | else |
| 1971 | goto stop_flogi_current_fcf; |
| 1972 | } |
| 1973 | return 0; |
| 1974 | |
| 1975 | stop_flogi_current_fcf: |
| 1976 | lpfc_can_disctmo(vport); |
| 1977 | return 1; |
| 1978 | } |
| 1979 | |
| 1980 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1981 | * lpfc_sli4_fcf_pri_list_del |
| 1982 | * @phba: pointer to lpfc hba data structure. |
| 1983 | * @fcf_index the index of the fcf record to delete |
| 1984 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 1985 | * If it is one the list then it is removed from the list, and the flag |
| 1986 | * is cleared. This routine grab the hbalock before removing the fcf |
| 1987 | * record from the list. |
| 1988 | **/ |
| 1989 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 1990 | uint16_t fcf_index) |
| 1991 | { |
| 1992 | struct lpfc_fcf_pri *new_fcf_pri; |
| 1993 | |
| 1994 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1995 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1996 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 1997 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 1998 | new_fcf_pri->fcf_rec.flag); |
| 1999 | spin_lock_irq(&phba->hbalock); |
| 2000 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2001 | if (phba->fcf.current_rec.priority == |
| 2002 | new_fcf_pri->fcf_rec.priority) |
| 2003 | phba->fcf.eligible_fcf_cnt--; |
| 2004 | list_del_init(&new_fcf_pri->list); |
| 2005 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2006 | } |
| 2007 | spin_unlock_irq(&phba->hbalock); |
| 2008 | } |
| 2009 | |
| 2010 | /** |
| 2011 | * lpfc_sli4_set_fcf_flogi_fail |
| 2012 | * @phba: pointer to lpfc hba data structure. |
| 2013 | * @fcf_index the index of the fcf record to update |
| 2014 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2015 | * flag so the the round robin slection for the particular priority level |
| 2016 | * will try a different fcf record that does not have this bit set. |
| 2017 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2018 | * adding it to the priority list. |
| 2019 | **/ |
| 2020 | void |
| 2021 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2022 | { |
| 2023 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2024 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2025 | spin_lock_irq(&phba->hbalock); |
| 2026 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2027 | spin_unlock_irq(&phba->hbalock); |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * lpfc_sli4_fcf_pri_list_add |
| 2032 | * @phba: pointer to lpfc hba data structure. |
| 2033 | * @fcf_index the index of the fcf record to add |
| 2034 | * This routine checks the priority of the fcf_index to be added. |
| 2035 | * If it is a lower priority than the current head of the fcf_pri list |
| 2036 | * then it is added to the list in the right order. |
| 2037 | * If it is the same priority as the current head of the list then it |
| 2038 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2039 | * If the fcf_index to be added is of a higher priority than the current |
| 2040 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2041 | * rr_bmask and it is added to the head of the list. |
| 2042 | * returns: |
| 2043 | * 0=success 1=failure |
| 2044 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame^] | 2045 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
| 2046 | uint16_t fcf_index, |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2047 | struct fcf_record *new_fcf_record) |
| 2048 | { |
| 2049 | uint16_t current_fcf_pri; |
| 2050 | uint16_t last_index; |
| 2051 | struct lpfc_fcf_pri *fcf_pri; |
| 2052 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2053 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2054 | int ret; |
| 2055 | |
| 2056 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2057 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2058 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2059 | fcf_index, new_fcf_record->fip_priority, |
| 2060 | new_fcf_pri->fcf_rec.flag); |
| 2061 | spin_lock_irq(&phba->hbalock); |
| 2062 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2063 | list_del_init(&new_fcf_pri->list); |
| 2064 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2065 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2066 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2067 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2068 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2069 | new_fcf_pri->fcf_rec.fcf_index); |
| 2070 | goto out; |
| 2071 | } |
| 2072 | |
| 2073 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2074 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2075 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2076 | ret = 0; /* Empty rr list */ |
| 2077 | goto out; |
| 2078 | } |
| 2079 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2080 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2081 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2082 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2083 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2084 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2085 | /* fcfs_at_this_priority_level = 1; */ |
| 2086 | phba->fcf.eligible_fcf_cnt = 1; |
| 2087 | } else |
| 2088 | /* fcfs_at_this_priority_level++; */ |
| 2089 | phba->fcf.eligible_fcf_cnt++; |
| 2090 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2091 | new_fcf_pri->fcf_rec.fcf_index); |
| 2092 | goto out; |
| 2093 | } |
| 2094 | |
| 2095 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2096 | &phba->fcf.fcf_pri_list, list) { |
| 2097 | if (new_fcf_pri->fcf_rec.priority <= |
| 2098 | fcf_pri->fcf_rec.priority) { |
| 2099 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2100 | list_add(&new_fcf_pri->list, |
| 2101 | &phba->fcf.fcf_pri_list); |
| 2102 | else |
| 2103 | list_add(&new_fcf_pri->list, |
| 2104 | &((struct lpfc_fcf_pri *) |
| 2105 | fcf_pri->list.prev)->list); |
| 2106 | ret = 0; |
| 2107 | goto out; |
| 2108 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2109 | || new_fcf_pri->fcf_rec.priority < |
| 2110 | next_fcf_pri->fcf_rec.priority) { |
| 2111 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2112 | ret = 0; |
| 2113 | goto out; |
| 2114 | } |
| 2115 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2116 | continue; |
| 2117 | |
| 2118 | } |
| 2119 | ret = 1; |
| 2120 | out: |
| 2121 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2122 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2123 | spin_unlock_irq(&phba->hbalock); |
| 2124 | return ret; |
| 2125 | } |
| 2126 | |
| 2127 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2128 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2129 | * @phba: pointer to lpfc hba data structure. |
| 2130 | * @mboxq: pointer to mailbox object. |
| 2131 | * |
| 2132 | * This function iterates through all the fcf records available in |
| 2133 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2134 | * the FCF for discovery it registers the FCF record and kicks start |
| 2135 | * discovery. |
| 2136 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2137 | * use an FCF record which matches fabric name and mac address of the |
| 2138 | * currently used FCF record. |
| 2139 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2140 | * used by BOOT_BIOS. |
| 2141 | */ |
| 2142 | void |
| 2143 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2144 | { |
| 2145 | struct fcf_record *new_fcf_record; |
| 2146 | uint32_t boot_flag, addr_mode; |
| 2147 | uint16_t fcf_index, next_fcf_index; |
| 2148 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 2149 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2150 | uint32_t seed; |
| 2151 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2152 | int rc; |
| 2153 | |
| 2154 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2155 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2156 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2157 | return; |
| 2158 | } |
| 2159 | |
| 2160 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2161 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2162 | &next_fcf_index); |
| 2163 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2164 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2165 | "2765 Mailbox command READ_FCF_RECORD " |
| 2166 | "failed to retrieve a FCF record.\n"); |
| 2167 | /* Let next new FCF event trigger fast failover */ |
| 2168 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2169 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2170 | spin_unlock_irq(&phba->hbalock); |
| 2171 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2172 | return; |
| 2173 | } |
| 2174 | |
| 2175 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2176 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2177 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2178 | |
| 2179 | /* Log the FCF record information if turned on */ |
| 2180 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2181 | next_fcf_index); |
| 2182 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2183 | /* |
| 2184 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2185 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2186 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2187 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2188 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2189 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2190 | bf_get(lpfc_fcf_record_fcf_index, |
| 2191 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2192 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2193 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2194 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2195 | bf_get(lpfc_fcf_record_fcf_index, |
| 2196 | new_fcf_record), |
| 2197 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2198 | new_fcf_record), |
| 2199 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2200 | new_fcf_record), |
| 2201 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2202 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2203 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2204 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2205 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2206 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2207 | phba->fcf.current_rec.fcf_indx) { |
| 2208 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2209 | "2862 FCF (x%x) matches property " |
| 2210 | "of in-use FCF (x%x)\n", |
| 2211 | bf_get(lpfc_fcf_record_fcf_index, |
| 2212 | new_fcf_record), |
| 2213 | phba->fcf.current_rec.fcf_indx); |
| 2214 | goto read_next_fcf; |
| 2215 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2216 | /* |
| 2217 | * In case the current in-use FCF record becomes |
| 2218 | * invalid/unavailable during FCF discovery that |
| 2219 | * was not triggered by fast FCF failover process, |
| 2220 | * treat it as fast FCF failover. |
| 2221 | */ |
| 2222 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2223 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2224 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2225 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2226 | "(x%x), enter FCF failover " |
| 2227 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2228 | phba->fcf.current_rec.fcf_indx); |
| 2229 | spin_lock_irq(&phba->hbalock); |
| 2230 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2231 | spin_unlock_irq(&phba->hbalock); |
| 2232 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2233 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2234 | LPFC_FCOE_FCF_GET_FIRST); |
| 2235 | return; |
| 2236 | } |
| 2237 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2238 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2239 | } else { |
| 2240 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2241 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2242 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2243 | if (rc) |
| 2244 | goto read_next_fcf; |
| 2245 | } |
| 2246 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2247 | /* |
| 2248 | * 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] | 2249 | * FCF record for the discovery. The condition that a rescan |
| 2250 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2251 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2252 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2253 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2254 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2255 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2256 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2257 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2258 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2259 | phba->fcf.current_rec.fcf_indx) { |
| 2260 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2261 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2262 | /* Stop FCF redisc wait timer */ |
| 2263 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2264 | phba); |
| 2265 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2266 | /* Fast failover, mark completed */ |
| 2267 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2268 | spin_unlock_irq(&phba->hbalock); |
| 2269 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2270 | "2836 New FCF matches in-use " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 2271 | "FCF (x%x), port_state:x%x, " |
| 2272 | "fc_flag:x%x\n", |
| 2273 | phba->fcf.current_rec.fcf_indx, |
| 2274 | phba->pport->port_state, |
| 2275 | phba->pport->fc_flag); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2276 | goto out; |
| 2277 | } else |
| 2278 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2279 | "2863 New FCF (x%x) matches " |
| 2280 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2281 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2282 | new_fcf_record), |
| 2283 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2284 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2285 | /* |
| 2286 | * Read next FCF record from HBA searching for the matching |
| 2287 | * with in-use record only if not during the fast failover |
| 2288 | * period. In case of fast failover period, it shall try to |
| 2289 | * determine whether the FCF record just read should be the |
| 2290 | * next candidate. |
| 2291 | */ |
| 2292 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2293 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2294 | goto read_next_fcf; |
| 2295 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2296 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2297 | /* |
| 2298 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2299 | * period; otherwise, update on current FCF record. |
| 2300 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2301 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2302 | fcf_rec = &phba->fcf.failover_rec; |
| 2303 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2304 | fcf_rec = &phba->fcf.current_rec; |
| 2305 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2306 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2307 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2308 | * If the driver FCF record does not have boot flag |
| 2309 | * set and new hba fcf record has boot flag set, use |
| 2310 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2311 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2312 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2313 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2314 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2315 | "2837 Update current FCF record " |
| 2316 | "(x%x) with new FCF record (x%x)\n", |
| 2317 | fcf_rec->fcf_indx, |
| 2318 | bf_get(lpfc_fcf_record_fcf_index, |
| 2319 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2320 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2321 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2322 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2323 | goto read_next_fcf; |
| 2324 | } |
| 2325 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2326 | * If the driver FCF record has boot flag set and the |
| 2327 | * new hba FCF record does not have boot flag, read |
| 2328 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2329 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2330 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2331 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2332 | goto read_next_fcf; |
| 2333 | } |
| 2334 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2335 | * If the new hba FCF record has lower priority value |
| 2336 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2337 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2338 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2339 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2340 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2341 | "2838 Update current FCF record " |
| 2342 | "(x%x) with new FCF record (x%x)\n", |
| 2343 | fcf_rec->fcf_indx, |
| 2344 | bf_get(lpfc_fcf_record_fcf_index, |
| 2345 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2346 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2347 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2348 | /* Reset running random FCF selection count */ |
| 2349 | phba->fcf.eligible_fcf_cnt = 1; |
| 2350 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2351 | /* Update running random FCF selection count */ |
| 2352 | phba->fcf.eligible_fcf_cnt++; |
| 2353 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2354 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2355 | if (select_new_fcf) { |
| 2356 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2357 | "2839 Update current FCF record " |
| 2358 | "(x%x) with new FCF record (x%x)\n", |
| 2359 | fcf_rec->fcf_indx, |
| 2360 | bf_get(lpfc_fcf_record_fcf_index, |
| 2361 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2362 | /* Choose the new FCF by random selection */ |
| 2363 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2364 | new_fcf_record, |
| 2365 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2366 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2367 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2368 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2369 | goto read_next_fcf; |
| 2370 | } |
| 2371 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2372 | * This is the first suitable FCF record, choose this record for |
| 2373 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2374 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2375 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2376 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2377 | "2840 Update initial FCF candidate " |
| 2378 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2379 | bf_get(lpfc_fcf_record_fcf_index, |
| 2380 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2381 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2382 | addr_mode, vlan_id, (boot_flag ? |
| 2383 | BOOT_ENABLE : 0)); |
| 2384 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2385 | /* Setup initial running random FCF selection count */ |
| 2386 | phba->fcf.eligible_fcf_cnt = 1; |
| 2387 | /* Seeding the random number generator for random selection */ |
| 2388 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 2389 | prandom_seed(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2390 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2391 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2392 | goto read_next_fcf; |
| 2393 | |
| 2394 | read_next_fcf: |
| 2395 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2396 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2397 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2398 | /* |
| 2399 | * Case of FCF fast failover scan |
| 2400 | */ |
| 2401 | |
| 2402 | /* |
| 2403 | * It has not found any suitable FCF record, cancel |
| 2404 | * FCF scan inprogress, and do nothing |
| 2405 | */ |
| 2406 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2407 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2408 | "2782 No suitable FCF found: " |
| 2409 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2410 | phba->fcoe_eventtag_at_fcf_scan, |
| 2411 | bf_get(lpfc_fcf_record_fcf_index, |
| 2412 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2413 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2414 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2415 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2416 | spin_unlock_irq(&phba->hbalock); |
| 2417 | /* Unregister in-use FCF and rescan */ |
| 2418 | lpfc_printf_log(phba, KERN_INFO, |
| 2419 | LOG_FIP, |
| 2420 | "2864 On devloss tmo " |
| 2421 | "unreg in-use FCF and " |
| 2422 | "rescan FCF table\n"); |
| 2423 | lpfc_unregister_fcf_rescan(phba); |
| 2424 | return; |
| 2425 | } |
| 2426 | /* |
| 2427 | * Let next new FCF event trigger fast failover |
| 2428 | */ |
| 2429 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2430 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2431 | return; |
| 2432 | } |
| 2433 | /* |
| 2434 | * It has found a suitable FCF record that is not |
| 2435 | * the same as in-use FCF record, unregister the |
| 2436 | * in-use FCF record, replace the in-use FCF record |
| 2437 | * with the new FCF record, mark FCF fast failover |
| 2438 | * completed, and then start register the new FCF |
| 2439 | * record. |
| 2440 | */ |
| 2441 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2442 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2443 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2444 | |
| 2445 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2446 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2447 | "2842 Replace in-use FCF (x%x) " |
| 2448 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2449 | phba->fcf.current_rec.fcf_indx, |
| 2450 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2451 | memcpy(&phba->fcf.current_rec, |
| 2452 | &phba->fcf.failover_rec, |
| 2453 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2454 | /* |
| 2455 | * Mark the fast FCF failover rediscovery completed |
| 2456 | * and the start of the first round of the roundrobin |
| 2457 | * FCF failover. |
| 2458 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2459 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2460 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2461 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2462 | /* Register to the new FCF record */ |
| 2463 | lpfc_register_fcf(phba); |
| 2464 | } else { |
| 2465 | /* |
| 2466 | * In case of transaction period to fast FCF failover, |
| 2467 | * do nothing when search to the end of the FCF table. |
| 2468 | */ |
| 2469 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2470 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2471 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2472 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2473 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2474 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2475 | /* |
| 2476 | * In case the current in-use FCF record no |
| 2477 | * longer existed during FCF discovery that |
| 2478 | * was not triggered by fast FCF failover |
| 2479 | * process, treat it as fast FCF failover. |
| 2480 | */ |
| 2481 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2482 | "2841 In-use FCF record (x%x) " |
| 2483 | "not reported, entering fast " |
| 2484 | "FCF failover mode scanning.\n", |
| 2485 | phba->fcf.current_rec.fcf_indx); |
| 2486 | spin_lock_irq(&phba->hbalock); |
| 2487 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2488 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2489 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2490 | LPFC_FCOE_FCF_GET_FIRST); |
| 2491 | return; |
| 2492 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2493 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2494 | lpfc_register_fcf(phba); |
| 2495 | } |
| 2496 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2497 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2498 | return; |
| 2499 | |
| 2500 | out: |
| 2501 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2502 | lpfc_register_fcf(phba); |
| 2503 | |
| 2504 | return; |
| 2505 | } |
| 2506 | |
| 2507 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2508 | * 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] | 2509 | * @phba: pointer to lpfc hba data structure. |
| 2510 | * @mboxq: pointer to mailbox object. |
| 2511 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2512 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2513 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2514 | * performing the failover. If the FCF read back is not valid/available, it |
| 2515 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2516 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2517 | * newly read FCF record to the failover FCF record, unregister currently |
| 2518 | * registered FCF record, copy the failover FCF record to the current |
| 2519 | * FCF record, and then register the current FCF record before proceeding |
| 2520 | * to trying FLOGI on the new failover FCF. |
| 2521 | */ |
| 2522 | void |
| 2523 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2524 | { |
| 2525 | struct fcf_record *new_fcf_record; |
| 2526 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2527 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2528 | uint16_t current_fcf_index; |
| 2529 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2530 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2531 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2532 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2533 | if (phba->link_state < LPFC_LINK_UP) { |
| 2534 | spin_lock_irq(&phba->hbalock); |
| 2535 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2536 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2537 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2538 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2542 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2543 | &next_fcf_index); |
| 2544 | if (!new_fcf_record) { |
| 2545 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2546 | "2766 Mailbox command READ_FCF_RECORD " |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 2547 | "failed to retrieve a FCF record. " |
| 2548 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, |
| 2549 | phba->fcf.fcf_flag); |
| 2550 | lpfc_unregister_fcf_rescan(phba); |
| 2551 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2555 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2556 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2557 | |
| 2558 | /* Log the FCF record information if turned on */ |
| 2559 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2560 | next_fcf_index); |
| 2561 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2562 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2563 | if (!rc) { |
| 2564 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2565 | "2848 Remove ineligible FCF (x%x) from " |
| 2566 | "from roundrobin bmask\n", fcf_index); |
| 2567 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2568 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2569 | /* Perform next round of roundrobin FCF failover */ |
| 2570 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2571 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2572 | if (rc) |
| 2573 | goto out; |
| 2574 | goto error_out; |
| 2575 | } |
| 2576 | |
| 2577 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2578 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2579 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2580 | "FCF (x%x) back to FCF (x%x)\n", |
| 2581 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2582 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2583 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2584 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2585 | goto out; |
| 2586 | } |
| 2587 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2588 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2589 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2590 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2591 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2592 | spin_lock_irq(&phba->hbalock); |
| 2593 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2594 | new_fcf_record, addr_mode, vlan_id, |
| 2595 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2596 | spin_unlock_irq(&phba->hbalock); |
| 2597 | |
| 2598 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2599 | |
| 2600 | /* Unregister the current in-use FCF record */ |
| 2601 | lpfc_unregister_fcf(phba); |
| 2602 | |
| 2603 | /* Replace in-use record with the new record */ |
| 2604 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2605 | sizeof(struct lpfc_fcf_rec)); |
| 2606 | |
| 2607 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2608 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2609 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2610 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2611 | error_out: |
| 2612 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2613 | out: |
| 2614 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /** |
| 2618 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2619 | * @phba: pointer to lpfc hba data structure. |
| 2620 | * @mboxq: pointer to mailbox object. |
| 2621 | * |
| 2622 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2623 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2624 | * failover when a new FCF event happened. If the FCF read back is |
| 2625 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2626 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2627 | */ |
| 2628 | void |
| 2629 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2630 | { |
| 2631 | struct fcf_record *new_fcf_record; |
| 2632 | uint32_t boot_flag, addr_mode; |
| 2633 | uint16_t fcf_index, next_fcf_index; |
| 2634 | uint16_t vlan_id; |
| 2635 | int rc; |
| 2636 | |
| 2637 | /* If link state is not up, no need to proceed */ |
| 2638 | if (phba->link_state < LPFC_LINK_UP) |
| 2639 | goto out; |
| 2640 | |
| 2641 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2642 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2643 | goto out; |
| 2644 | |
| 2645 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2646 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2647 | &next_fcf_index); |
| 2648 | if (!new_fcf_record) { |
| 2649 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2650 | "2767 Mailbox command READ_FCF_RECORD " |
| 2651 | "failed to retrieve a FCF record.\n"); |
| 2652 | goto out; |
| 2653 | } |
| 2654 | |
| 2655 | /* Check the connection list for eligibility */ |
| 2656 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2657 | &addr_mode, &vlan_id); |
| 2658 | |
| 2659 | /* Log the FCF record information if turned on */ |
| 2660 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2661 | next_fcf_index); |
| 2662 | |
| 2663 | if (!rc) |
| 2664 | goto out; |
| 2665 | |
| 2666 | /* Update the eligible FCF record index bmask */ |
| 2667 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2668 | |
| 2669 | 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] | 2670 | |
| 2671 | out: |
| 2672 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2673 | } |
| 2674 | |
| 2675 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2676 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2677 | * @phba: pointer to lpfc hba data structure. |
| 2678 | * @mboxq: pointer to mailbox data structure. |
| 2679 | * |
| 2680 | * This function handles completion of init vfi mailbox command. |
| 2681 | */ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame^] | 2682 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2683 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2684 | { |
| 2685 | struct lpfc_vport *vport = mboxq->vport; |
| 2686 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2687 | /* |
| 2688 | * VFI not supported on interface type 0, just do the flogi |
| 2689 | * Also continue if the VFI is in use - just use the same one. |
| 2690 | */ |
| 2691 | if (mboxq->u.mb.mbxStatus && |
| 2692 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2693 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2694 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2695 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2696 | LOG_MBOX, |
| 2697 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2698 | mboxq->u.mb.mbxStatus); |
| 2699 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2700 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2701 | return; |
| 2702 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2703 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2704 | lpfc_initial_flogi(vport); |
| 2705 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2706 | return; |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2711 | * @vport: pointer to lpfc_vport data structure. |
| 2712 | * |
| 2713 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2714 | * VPI for the physical port. |
| 2715 | */ |
| 2716 | void |
| 2717 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2718 | { |
| 2719 | LPFC_MBOXQ_t *mboxq; |
| 2720 | int rc; |
| 2721 | struct lpfc_hba *phba = vport->phba; |
| 2722 | |
| 2723 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2724 | if (!mboxq) { |
| 2725 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2726 | LOG_MBOX, "2892 Failed to allocate " |
| 2727 | "init_vfi mailbox\n"); |
| 2728 | return; |
| 2729 | } |
| 2730 | lpfc_init_vfi(mboxq, vport); |
| 2731 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2732 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2733 | if (rc == MBX_NOT_FINISHED) { |
| 2734 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2735 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2736 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2741 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2742 | * @phba: pointer to lpfc hba data structure. |
| 2743 | * @mboxq: pointer to mailbox data structure. |
| 2744 | * |
| 2745 | * This function handles completion of init vpi mailbox command. |
| 2746 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2747 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2748 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2749 | { |
| 2750 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2751 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2752 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2753 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2754 | if (mboxq->u.mb.mbxStatus) { |
| 2755 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2756 | LOG_MBOX, |
| 2757 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2758 | mboxq->u.mb.mbxStatus); |
| 2759 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2760 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2761 | return; |
| 2762 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2763 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2764 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2765 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2766 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2767 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2768 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2769 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2770 | if (!ndlp) |
| 2771 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2772 | LOG_DISCOVERY, |
| 2773 | "2731 Cannot find fabric " |
| 2774 | "controller node\n"); |
| 2775 | else |
| 2776 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2777 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2778 | return; |
| 2779 | } |
| 2780 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2781 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2782 | lpfc_initial_fdisc(vport); |
| 2783 | else { |
| 2784 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2785 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2786 | "2606 No NPIV Fabric support\n"); |
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 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2789 | return; |
| 2790 | } |
| 2791 | |
| 2792 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2793 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2794 | * @vport: pointer to lpfc_vport data structure. |
| 2795 | * |
| 2796 | * This function issue a init_vpi mailbox command to initialize |
| 2797 | * VPI for the vport. |
| 2798 | */ |
| 2799 | void |
| 2800 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2801 | { |
| 2802 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2803 | int rc, vpi; |
| 2804 | |
| 2805 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2806 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2807 | if (!vpi) { |
| 2808 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2809 | LOG_MBOX, |
| 2810 | "3303 Failed to obtain vport vpi\n"); |
| 2811 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2812 | return; |
| 2813 | } |
| 2814 | vport->vpi = vpi; |
| 2815 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2816 | |
| 2817 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2818 | if (!mboxq) { |
| 2819 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2820 | LOG_MBOX, "2607 Failed to allocate " |
| 2821 | "init_vpi mailbox\n"); |
| 2822 | return; |
| 2823 | } |
| 2824 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2825 | mboxq->vport = vport; |
| 2826 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2827 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2828 | if (rc == MBX_NOT_FINISHED) { |
| 2829 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2830 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2831 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2836 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2837 | * @phba: pointer to lpfc hba data structure. |
| 2838 | * |
| 2839 | * This function loops through the list of vports on the @phba and issues an |
| 2840 | * FDISC if possible. |
| 2841 | */ |
| 2842 | void |
| 2843 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2844 | { |
| 2845 | struct lpfc_vport **vports; |
| 2846 | int i; |
| 2847 | |
| 2848 | vports = lpfc_create_vport_work_array(phba); |
| 2849 | if (vports != NULL) { |
| 2850 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2851 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2852 | continue; |
| 2853 | /* There are no vpi for this vport */ |
| 2854 | if (vports[i]->vpi > phba->max_vpi) { |
| 2855 | lpfc_vport_set_state(vports[i], |
| 2856 | FC_VPORT_FAILED); |
| 2857 | continue; |
| 2858 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2859 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2860 | lpfc_vport_set_state(vports[i], |
| 2861 | FC_VPORT_LINKDOWN); |
| 2862 | continue; |
| 2863 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2864 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2865 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2866 | continue; |
| 2867 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2868 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2869 | lpfc_initial_fdisc(vports[i]); |
| 2870 | else { |
| 2871 | lpfc_vport_set_state(vports[i], |
| 2872 | FC_VPORT_NO_FABRIC_SUPP); |
| 2873 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2874 | LOG_ELS, |
| 2875 | "0259 No NPIV " |
| 2876 | "Fabric support\n"); |
| 2877 | } |
| 2878 | } |
| 2879 | } |
| 2880 | lpfc_destroy_vport_work_array(phba, vports); |
| 2881 | } |
| 2882 | |
| 2883 | void |
| 2884 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2885 | { |
| 2886 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2887 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2888 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2889 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2890 | /* |
| 2891 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2892 | * error (except VFI in use) and continue with the discovery. |
| 2893 | */ |
| 2894 | if (mboxq->u.mb.mbxStatus && |
| 2895 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2896 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2897 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2898 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2899 | "2018 REG_VFI mbxStatus error x%x " |
| 2900 | "HBA state x%x\n", |
| 2901 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2902 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2903 | /* FLOGI failed, use loop map to make discovery list */ |
| 2904 | lpfc_disc_list_loopmap(vport); |
| 2905 | /* Start discovery */ |
| 2906 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2907 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2908 | } |
| 2909 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2910 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2911 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2912 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2913 | /* If the VFI is already registered, there is nothing else to do |
| 2914 | * Unless this was a VFI update and we are in PT2PT mode, then |
| 2915 | * we should drop through to set the port state to ready. |
| 2916 | */ |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2917 | if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2918 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
| 2919 | vport->fc_flag & FC_PT2PT)) |
| 2920 | goto out_free_mem; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2921 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2922 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2923 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2924 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2925 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2926 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2927 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2928 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2929 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2930 | /* In case SLI4 FC loopback test, we are ready */ |
| 2931 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2932 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2933 | phba->link_state = LPFC_HBA_READY; |
| 2934 | goto out_free_mem; |
| 2935 | } |
| 2936 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2937 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2938 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " |
| 2939 | "alpacnt:%d LinkState:%x topology:%x\n", |
| 2940 | vport->port_state, vport->fc_flag, vport->fc_myDID, |
| 2941 | vport->phba->alpa_map[0], |
| 2942 | phba->link_state, phba->fc_topology); |
| 2943 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2944 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2945 | /* |
| 2946 | * For private loop or for NPort pt2pt, |
| 2947 | * just start discovery and we are done. |
| 2948 | */ |
| 2949 | if ((vport->fc_flag & FC_PT2PT) || |
| 2950 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2951 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2952 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2953 | /* Use loop map to make discovery list */ |
| 2954 | lpfc_disc_list_loopmap(vport); |
| 2955 | /* Start discovery */ |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2956 | if (vport->fc_flag & FC_PT2PT) |
| 2957 | vport->port_state = LPFC_VPORT_READY; |
| 2958 | else |
| 2959 | lpfc_disc_start(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2960 | } else { |
| 2961 | lpfc_start_fdiscs(phba); |
| 2962 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2963 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2964 | } |
| 2965 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2966 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2967 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2968 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2969 | kfree(dmabuf); |
| 2970 | return; |
| 2971 | } |
| 2972 | |
| 2973 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2976 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2978 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | |
| 2980 | |
| 2981 | /* Check for error */ |
| 2982 | if (mb->mbxStatus) { |
| 2983 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2984 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2985 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2986 | "hba state x%x>\n", |
| 2987 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | goto out; |
| 2990 | } |
| 2991 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2992 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | sizeof (struct serv_parm)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 2994 | lpfc_update_vport_wwn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2995 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2996 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2997 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2998 | } |
| 2999 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3001 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3002 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | return; |
| 3004 | |
| 3005 | out: |
| 3006 | pmb->context1 = NULL; |
| 3007 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3008 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3009 | lpfc_issue_clear_la(phba, vport); |
| 3010 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | return; |
| 3012 | } |
| 3013 | |
| 3014 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3015 | 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] | 3016 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3017 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3018 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3019 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3020 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3021 | struct lpfc_dmabuf *mp; |
| 3022 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3023 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3024 | uint32_t fc_flags = 0; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3025 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3026 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3027 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3028 | case LPFC_LINK_SPEED_1GHZ: |
| 3029 | case LPFC_LINK_SPEED_2GHZ: |
| 3030 | case LPFC_LINK_SPEED_4GHZ: |
| 3031 | case LPFC_LINK_SPEED_8GHZ: |
| 3032 | case LPFC_LINK_SPEED_10GHZ: |
| 3033 | case LPFC_LINK_SPEED_16GHZ: |
| 3034 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3035 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3036 | default: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3037 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3038 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | } |
| 3040 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3041 | if (phba->fc_topology && |
| 3042 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { |
| 3043 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3044 | "3314 Toplogy changed was 0x%x is 0x%x\n", |
| 3045 | phba->fc_topology, |
| 3046 | bf_get(lpfc_mbx_read_top_topology, la)); |
| 3047 | phba->fc_topology_changed = 1; |
| 3048 | } |
| 3049 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3050 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3053 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3054 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3055 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3056 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3057 | /* if npiv is enabled and this adapter supports npiv log |
| 3058 | * a message that npiv is not supported in this topology |
| 3059 | */ |
| 3060 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3061 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3062 | "1309 Link Up Event npiv not supported in loop " |
| 3063 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3064 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3065 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3066 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3068 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3069 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | |
| 3071 | if (i == 0) { |
| 3072 | phba->alpa_map[0] = 0; |
| 3073 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3074 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | int numalpa, j, k; |
| 3076 | union { |
| 3077 | uint8_t pamap[16]; |
| 3078 | struct { |
| 3079 | uint32_t wd1; |
| 3080 | uint32_t wd2; |
| 3081 | uint32_t wd3; |
| 3082 | uint32_t wd4; |
| 3083 | } pa; |
| 3084 | } un; |
| 3085 | numalpa = phba->alpa_map[0]; |
| 3086 | j = 0; |
| 3087 | while (j < numalpa) { |
| 3088 | memset(un.pamap, 0, 16); |
| 3089 | for (k = 1; j < numalpa; k++) { |
| 3090 | un.pamap[k - 1] = |
| 3091 | phba->alpa_map[j + 1]; |
| 3092 | j++; |
| 3093 | if (k == 16) |
| 3094 | break; |
| 3095 | } |
| 3096 | /* Link Up Event ALPA map */ |
| 3097 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3098 | KERN_WARNING, |
| 3099 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3100 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3101 | "ALPA map Data: x%x " |
| 3102 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3103 | un.pa.wd1, un.pa.wd2, |
| 3104 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3109 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3110 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3111 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3112 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3113 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3114 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3115 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3117 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3118 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3119 | if (fc_flags) { |
| 3120 | spin_lock_irq(shost->host_lock); |
| 3121 | vport->fc_flag |= fc_flags; |
| 3122 | spin_unlock_irq(shost->host_lock); |
| 3123 | } |
| 3124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3125 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3126 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3127 | if (!sparam_mbox) |
| 3128 | goto out; |
| 3129 | |
| 3130 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3131 | if (rc) { |
| 3132 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3133 | goto out; |
| 3134 | } |
| 3135 | sparam_mbox->vport = vport; |
| 3136 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3137 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3138 | if (rc == MBX_NOT_FINISHED) { |
| 3139 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3140 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3141 | kfree(mp); |
| 3142 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3143 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | } |
| 3145 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3146 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3147 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3148 | if (!cfglink_mbox) |
| 3149 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3150 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3152 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3153 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3154 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3155 | if (rc == MBX_NOT_FINISHED) { |
| 3156 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3157 | goto out; |
| 3158 | } |
| 3159 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3160 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3161 | /* |
| 3162 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3163 | * is phase 1 implementation that support FCF index 0 and driver |
| 3164 | * defaults. |
| 3165 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3166 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3167 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3168 | GFP_KERNEL); |
| 3169 | if (unlikely(!fcf_record)) { |
| 3170 | lpfc_printf_log(phba, KERN_ERR, |
| 3171 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3172 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3173 | "fcf record\n"); |
| 3174 | rc = -ENODEV; |
| 3175 | goto out; |
| 3176 | } |
| 3177 | |
| 3178 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3179 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3180 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3181 | if (unlikely(rc)) { |
| 3182 | lpfc_printf_log(phba, KERN_ERR, |
| 3183 | LOG_MBOX | LOG_SLI, |
| 3184 | "2013 Could not manually add FCF " |
| 3185 | "record 0, status %d\n", rc); |
| 3186 | rc = -ENODEV; |
| 3187 | kfree(fcf_record); |
| 3188 | goto out; |
| 3189 | } |
| 3190 | kfree(fcf_record); |
| 3191 | } |
| 3192 | /* |
| 3193 | * The driver is expected to do FIP/FCF. Call the port |
| 3194 | * and get the FCF Table. |
| 3195 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3196 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3197 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3198 | spin_unlock_irq(&phba->hbalock); |
| 3199 | return; |
| 3200 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3201 | /* This is the initial FCF discovery scan */ |
| 3202 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3203 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3204 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3205 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3206 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3207 | LPFC_FCOE_FCF_GET_FIRST); |
| 3208 | if (rc) { |
| 3209 | spin_lock_irq(&phba->hbalock); |
| 3210 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3211 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3212 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3213 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3214 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3215 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3217 | |
| 3218 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3219 | out: |
| 3220 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3221 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3222 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3223 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3224 | lpfc_issue_clear_la(phba, vport); |
| 3225 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3229 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | uint32_t control; |
| 3232 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3233 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3235 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3236 | control = readl(phba->HCregaddr); |
| 3237 | control |= HC_LAINT_ENA; |
| 3238 | writel(control, phba->HCregaddr); |
| 3239 | readl(phba->HCregaddr); /* flush */ |
| 3240 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3241 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | } |
| 3243 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3244 | static void |
| 3245 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3246 | { |
| 3247 | lpfc_linkdown(phba); |
| 3248 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3249 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3250 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3251 | } |
| 3252 | |
| 3253 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3255 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3257 | * as the completion routine when the command is |
| 3258 | * handed off to the SLI layer. |
| 3259 | */ |
| 3260 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3261 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3263 | struct lpfc_vport *vport = pmb->vport; |
| 3264 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3265 | struct lpfc_mbx_read_top *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3266 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3268 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3269 | /* Unblock ELS traffic */ |
| 3270 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | /* Check for error */ |
| 3272 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3273 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3274 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3275 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3277 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3278 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | } |
| 3280 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3281 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | |
| 3283 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3284 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3286 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3288 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3289 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3290 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3291 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3292 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3294 | if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | if (phba->fc_eventTag != 0) |
| 3296 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3297 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | |
| 3299 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3300 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3301 | spin_lock_irq(&phba->hbalock); |
| 3302 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3303 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3304 | else |
| 3305 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| 3306 | spin_unlock_irq(&phba->hbalock); |
| 3307 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3309 | phba->link_events++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3310 | 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] | 3311 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3313 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3314 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3315 | "1306 Link Up Event in loop back mode " |
| 3316 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3317 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3318 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3319 | la), |
| 3320 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3321 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3322 | } else { |
| 3323 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3324 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3325 | "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] | 3326 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3327 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3328 | la), |
| 3329 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3330 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3331 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3332 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3333 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3334 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3335 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3336 | } else if (bf_get(lpfc_mbx_read_top_att_type, la) == |
| 3337 | LPFC_ATT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3339 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3340 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3341 | "1308 Link Down Event in loop back mode " |
| 3342 | "x%x received " |
| 3343 | "Data: x%x x%x x%x\n", |
| 3344 | la->eventTag, phba->fc_eventTag, |
| 3345 | phba->pport->port_state, vport->fc_flag); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3346 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3347 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3348 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3349 | "Data: x%x x%x x%x x%x x%x\n", |
| 3350 | la->eventTag, phba->fc_eventTag, |
| 3351 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3352 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3353 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3354 | lpfc_mbx_issue_link_down(phba); |
| 3355 | } |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3356 | if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) && |
| 3357 | ((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] | 3358 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3359 | phba->fc_stat.LinkDown++; |
| 3360 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3361 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3363 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3365 | lpfc_mbx_issue_link_down(phba); |
| 3366 | } else |
| 3367 | lpfc_enable_la(phba); |
| 3368 | |
| 3369 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3370 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3371 | "Data: x%x x%x x%x\n", |
| 3372 | la->eventTag, phba->fc_eventTag, |
| 3373 | phba->pport->port_state, vport->fc_flag); |
| 3374 | /* |
| 3375 | * The cmnd that triggered this will be waiting for this |
| 3376 | * signal. |
| 3377 | */ |
| 3378 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3379 | if (phba->wait_4_mlo_maint_flg) { |
| 3380 | phba->wait_4_mlo_maint_flg = 0; |
| 3381 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3382 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3383 | } |
| 3384 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3385 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3386 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3387 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3388 | lpfc_issue_clear_la(phba, vport); |
| 3389 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3390 | "1311 fa %d\n", |
| 3391 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | } |
| 3393 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3394 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3396 | kfree(mp); |
| 3397 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3398 | return; |
| 3399 | } |
| 3400 | |
| 3401 | /* |
| 3402 | * This routine handles processing a REG_LOGIN mailbox |
| 3403 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3404 | * as the completion routine when the command is |
| 3405 | * handed off to the SLI layer. |
| 3406 | */ |
| 3407 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3408 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3411 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3412 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3413 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3416 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3418 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3419 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3420 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3421 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3422 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3423 | /* We rcvd a rscn after issuing this |
| 3424 | * mbox reg login, we may have cycled |
| 3425 | * back through the state and be |
| 3426 | * back at reg login state so this |
| 3427 | * mbox needs to be ignored becase |
| 3428 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3429 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3430 | */ |
| 3431 | spin_lock_irq(shost->host_lock); |
| 3432 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3433 | spin_unlock_irq(shost->host_lock); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3434 | } else |
| 3435 | /* Good status, call state machine */ |
| 3436 | lpfc_disc_state_machine(vport, ndlp, pmb, |
| 3437 | NLP_EVT_CMPL_REG_LOGIN); |
| 3438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3440 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3442 | /* decrement the node reference count held for this callback |
| 3443 | * function. |
| 3444 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3445 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | |
| 3447 | return; |
| 3448 | } |
| 3449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3450 | static void |
| 3451 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3452 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3453 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3454 | struct lpfc_vport *vport = pmb->vport; |
| 3455 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3456 | |
| 3457 | switch (mb->mbxStatus) { |
| 3458 | case 0x0011: |
| 3459 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3460 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3461 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3462 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3463 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3464 | /* If VPI is busy, reset the HBA */ |
| 3465 | case 0x9700: |
| 3466 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3467 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3468 | vport->vpi, mb->mbxStatus); |
| 3469 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3470 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3471 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3472 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3473 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3474 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3475 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3476 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3477 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3478 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3479 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3480 | /* |
| 3481 | * This shost reference might have been taken at the beginning of |
| 3482 | * lpfc_vport_delete() |
| 3483 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3484 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3485 | scsi_host_put(shost); |
| 3486 | } |
| 3487 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3488 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3489 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3490 | { |
| 3491 | struct lpfc_hba *phba = vport->phba; |
| 3492 | LPFC_MBOXQ_t *mbox; |
| 3493 | int rc; |
| 3494 | |
| 3495 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3496 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3497 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3498 | |
| 3499 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3500 | mbox->vport = vport; |
| 3501 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3502 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3503 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3504 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3505 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3506 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3507 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3508 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3509 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3510 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | static void |
| 3514 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3515 | { |
| 3516 | struct lpfc_vport *vport = pmb->vport; |
| 3517 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3518 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3519 | |
| 3520 | switch (mb->mbxStatus) { |
| 3521 | case 0x0011: |
| 3522 | case 0x9601: |
| 3523 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3524 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3525 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3526 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3527 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3528 | spin_lock_irq(shost->host_lock); |
| 3529 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3530 | spin_unlock_irq(shost->host_lock); |
| 3531 | vport->fc_myDID = 0; |
| 3532 | goto out; |
| 3533 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3534 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3535 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3536 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3537 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3538 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3539 | vport->num_disc_nodes = 0; |
| 3540 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3541 | if (vport->fc_npr_cnt) |
| 3542 | lpfc_els_disc_plogi(vport); |
| 3543 | |
| 3544 | if (!vport->num_disc_nodes) { |
| 3545 | spin_lock_irq(shost->host_lock); |
| 3546 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3547 | spin_unlock_irq(shost->host_lock); |
| 3548 | lpfc_can_disctmo(vport); |
| 3549 | } |
| 3550 | vport->port_state = LPFC_VPORT_READY; |
| 3551 | |
| 3552 | out: |
| 3553 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3554 | return; |
| 3555 | } |
| 3556 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3557 | /** |
| 3558 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3559 | * @phba: pointer to lpfc hba data structure. |
| 3560 | * |
| 3561 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3562 | * the list of static vports to be created. The function create vports |
| 3563 | * based on the information returned from the HBA. |
| 3564 | **/ |
| 3565 | void |
| 3566 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3567 | { |
| 3568 | LPFC_MBOXQ_t *pmb = NULL; |
| 3569 | MAILBOX_t *mb; |
| 3570 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3571 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3572 | struct fc_vport_identifiers vport_id; |
| 3573 | struct fc_vport *new_fc_vport; |
| 3574 | struct Scsi_Host *shost; |
| 3575 | struct lpfc_vport *vport; |
| 3576 | uint16_t offset = 0; |
| 3577 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3578 | struct lpfc_dmabuf *mp; |
| 3579 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3580 | |
| 3581 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3582 | if (!pmb) { |
| 3583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3584 | "0542 lpfc_create_static_vport failed to" |
| 3585 | " allocate mailbox memory\n"); |
| 3586 | return; |
| 3587 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3588 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3589 | mb = &pmb->u.mb; |
| 3590 | |
| 3591 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3592 | if (!vport_info) { |
| 3593 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3594 | "0543 lpfc_create_static_vport failed to" |
| 3595 | " allocate vport_info\n"); |
| 3596 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3597 | return; |
| 3598 | } |
| 3599 | |
| 3600 | vport_buff = (uint8_t *) vport_info; |
| 3601 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3602 | /* free dma buffer from previous round */ |
| 3603 | if (pmb->context1) { |
| 3604 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3605 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3606 | kfree(mp); |
| 3607 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3608 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3609 | goto out; |
| 3610 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3611 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3612 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3613 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3614 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3615 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3616 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3617 | "0544 lpfc_create_static_vport failed to" |
| 3618 | " issue dump mailbox command ret 0x%x " |
| 3619 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3620 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3621 | goto out; |
| 3622 | } |
| 3623 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3624 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3625 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3626 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3627 | if (byte_count > sizeof(struct static_vport_info) - |
| 3628 | offset) |
| 3629 | byte_count = sizeof(struct static_vport_info) |
| 3630 | - offset; |
| 3631 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3632 | offset += byte_count; |
| 3633 | } else { |
| 3634 | if (mb->un.varDmp.word_cnt > |
| 3635 | sizeof(struct static_vport_info) - offset) |
| 3636 | mb->un.varDmp.word_cnt = |
| 3637 | sizeof(struct static_vport_info) |
| 3638 | - offset; |
| 3639 | byte_count = mb->un.varDmp.word_cnt; |
| 3640 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3641 | vport_buff + offset, |
| 3642 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3643 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3644 | offset += byte_count; |
| 3645 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3646 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3647 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3648 | offset < sizeof(struct static_vport_info)); |
| 3649 | |
| 3650 | |
| 3651 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3652 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3653 | != VPORT_INFO_REV)) { |
| 3654 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3655 | "0545 lpfc_create_static_vport bad" |
| 3656 | " information header 0x%x 0x%x\n", |
| 3657 | le32_to_cpu(vport_info->signature), |
| 3658 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3659 | |
| 3660 | goto out; |
| 3661 | } |
| 3662 | |
| 3663 | shost = lpfc_shost_from_vport(phba->pport); |
| 3664 | |
| 3665 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3666 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3667 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3668 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3669 | if (!vport_id.port_name || !vport_id.node_name) |
| 3670 | continue; |
| 3671 | |
| 3672 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3673 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3674 | vport_id.disable = false; |
| 3675 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3676 | |
| 3677 | if (!new_fc_vport) { |
| 3678 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3679 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3680 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3681 | continue; |
| 3682 | } |
| 3683 | |
| 3684 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3685 | vport->vport_flag |= STATIC_VPORT; |
| 3686 | } |
| 3687 | |
| 3688 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3689 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3690 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3691 | if (pmb->context1) { |
| 3692 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3693 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3694 | kfree(mp); |
| 3695 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3696 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3697 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3698 | |
| 3699 | return; |
| 3700 | } |
| 3701 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | /* |
| 3703 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3704 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3705 | * as the completion routine when the command is |
| 3706 | * handed off to the SLI layer. |
| 3707 | */ |
| 3708 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3711 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3712 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3713 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3714 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3715 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3717 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3718 | pmb->context1 = NULL; |
| 3719 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3720 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3722 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3723 | "0258 Register Fabric login error: 0x%x\n", |
| 3724 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3726 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3727 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3729 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3730 | /* FLOGI failed, use loop map to make discovery list */ |
| 3731 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3733 | /* Start discovery */ |
| 3734 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3735 | /* Decrement the reference count to ndlp after the |
| 3736 | * reference to the ndlp are done. |
| 3737 | */ |
| 3738 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3739 | return; |
| 3740 | } |
| 3741 | |
| 3742 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3743 | /* Decrement the reference count to ndlp after the reference |
| 3744 | * to the ndlp are done. |
| 3745 | */ |
| 3746 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | return; |
| 3748 | } |
| 3749 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3750 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3751 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3752 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3756 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3757 | /* when physical port receive logo donot start |
| 3758 | * vport discovery */ |
| 3759 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3760 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3761 | else { |
| 3762 | shost = lpfc_shost_from_vport(vport); |
| 3763 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3764 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3765 | spin_unlock_irq(shost->host_lock); |
| 3766 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3767 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3771 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3772 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3773 | |
| 3774 | /* Drop the reference count from the mbox at the end after |
| 3775 | * all the current reference to the ndlp have been done. |
| 3776 | */ |
| 3777 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | return; |
| 3779 | } |
| 3780 | |
| 3781 | /* |
| 3782 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3783 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3784 | * as the completion routine when the command is |
| 3785 | * handed off to the SLI layer. |
| 3786 | */ |
| 3787 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3790 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3791 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3792 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3793 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3795 | pmb->context1 = NULL; |
| 3796 | pmb->context2 = NULL; |
| 3797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3799 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3800 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3801 | "0260 Register NameServer error: 0x%x\n", |
| 3802 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3803 | /* decrement the node reference count held for this |
| 3804 | * callback function. |
| 3805 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3806 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3808 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3809 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3810 | |
| 3811 | /* If no other thread is using the ndlp, free it */ |
| 3812 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3814 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3815 | /* |
| 3816 | * RegLogin failed, use loop map to make discovery |
| 3817 | * list |
| 3818 | */ |
| 3819 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3821 | /* Start discovery */ |
| 3822 | lpfc_disc_start(vport); |
| 3823 | return; |
| 3824 | } |
| 3825 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | return; |
| 3827 | } |
| 3828 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3829 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3830 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3831 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3836 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3837 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3838 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3839 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3840 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3841 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3842 | |
| 3843 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3844 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | } |
| 3846 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3849 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3851 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3854 | /* decrement the node reference count held for this |
| 3855 | * callback function. |
| 3856 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3857 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3859 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | |
| 3862 | return; |
| 3863 | } |
| 3864 | |
| 3865 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3868 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3869 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | struct lpfc_rport_data *rdata; |
| 3871 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3872 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | |
| 3874 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3875 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3876 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | rport_ids.port_id = ndlp->nlp_DID; |
| 3878 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3880 | /* |
| 3881 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3882 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3883 | * rport->dd_data points. So, if we're reusing a previously |
| 3884 | * registered port, drop the reference that we took the last time we |
| 3885 | * registered the port. |
| 3886 | */ |
| 3887 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3888 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3889 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3890 | |
| 3891 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3892 | "rport add: did:x%x flg:x%x type x%x", |
| 3893 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3894 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 3895 | /* Don't add the remote port if unloading. */ |
| 3896 | if (vport->load_flag & FC_UNLOADING) |
| 3897 | return; |
| 3898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3899 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3900 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3902 | "Warning: fc_remote_port_add failed\n"); |
| 3903 | return; |
| 3904 | } |
| 3905 | |
| 3906 | /* initialize static port data */ |
| 3907 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3908 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3910 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3911 | |
| 3912 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3913 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3914 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3915 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3916 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3917 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3918 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3919 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3920 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3921 | "3183 rport register x%06x, rport %p role x%x\n", |
| 3922 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 3923 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3924 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3925 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3926 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3927 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3928 | return; |
| 3929 | } |
| 3930 | |
| 3931 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3933 | { |
| 3934 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3935 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3936 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3937 | "rport delete: did:x%x flg:x%x type x%x", |
| 3938 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3939 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3940 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3941 | "3184 rport unregister x%06x, rport %p\n", |
| 3942 | ndlp->nlp_DID, rport); |
| 3943 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3944 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | |
| 3946 | return; |
| 3947 | } |
| 3948 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3949 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3951 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3953 | |
| 3954 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3955 | switch (state) { |
| 3956 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3958 | break; |
| 3959 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3960 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3961 | break; |
| 3962 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3963 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3964 | break; |
| 3965 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3966 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3967 | break; |
| 3968 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3970 | break; |
| 3971 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3972 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3973 | break; |
| 3974 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3975 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3976 | break; |
| 3977 | case NLP_STE_NPR_NODE: |
James Smart | 646a2dd | 2013-12-17 20:29:22 -0500 | [diff] [blame] | 3978 | if (vport->fc_npr_cnt == 0 && count == -1) |
| 3979 | vport->fc_npr_cnt = 0; |
| 3980 | else |
| 3981 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3982 | break; |
| 3983 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3985 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3986 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3987 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3988 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3989 | int old_state, int new_state) |
| 3990 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3991 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3992 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3993 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3994 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3995 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3996 | } |
| 3997 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3998 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3999 | if (new_state == NLP_STE_NPR_NODE) |
| 4000 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4002 | /* Transport interface */ |
| 4003 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 4004 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4005 | vport->phba->nport_event_cnt++; |
| 4006 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4007 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4009 | if (new_state == NLP_STE_MAPPED_NODE || |
| 4010 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4011 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4012 | /* |
| 4013 | * Tell the fc transport about the port, if we haven't |
| 4014 | * already. If we have, and it's a scsi entity, be |
| 4015 | * sure to unblock any attached scsi devices |
| 4016 | */ |
| 4017 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4018 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4019 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 4020 | (vport->stat_data_enabled)) { |
| 4021 | /* |
| 4022 | * A new target is discovered, if there is no buffer for |
| 4023 | * statistical data collection allocate buffer. |
| 4024 | */ |
| 4025 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 4026 | sizeof(struct lpfc_scsicmd_bkt), |
| 4027 | GFP_KERNEL); |
| 4028 | |
| 4029 | if (!ndlp->lat_data) |
| 4030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4031 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4032 | "allocate statistical data buffer DID " |
| 4033 | "0x%x\n", ndlp->nlp_DID); |
| 4034 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4035 | /* |
| 4036 | * if we added to Mapped list, but the remote port |
| 4037 | * registration failed or assigned a target id outside |
| 4038 | * our presentable range - move the node to the |
| 4039 | * Unmapped List |
| 4040 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4041 | if (new_state == NLP_STE_MAPPED_NODE && |
| 4042 | (!ndlp->rport || |
| 4043 | ndlp->rport->scsi_target_id == -1 || |
| 4044 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4045 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4046 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | spin_unlock_irq(shost->host_lock); |
| 4048 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4050 | } |
| 4051 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4052 | static char * |
| 4053 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4054 | { |
| 4055 | static char *states[] = { |
| 4056 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4057 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4058 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4059 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4060 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4061 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4062 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4063 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4064 | [NLP_STE_NPR_NODE] = "NPR", |
| 4065 | }; |
| 4066 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4067 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4068 | strlcpy(buffer, states[state], size); |
| 4069 | else |
| 4070 | snprintf(buffer, size, "unknown (%d)", state); |
| 4071 | return buffer; |
| 4072 | } |
| 4073 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4074 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4075 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4076 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4077 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4078 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4079 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4080 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4081 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4082 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4083 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4084 | ndlp->nlp_DID, |
| 4085 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4086 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4087 | |
| 4088 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4089 | "node statechg did:x%x old:%d ste:%d", |
| 4090 | ndlp->nlp_DID, old_state, state); |
| 4091 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4092 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4093 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4094 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4095 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4096 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4097 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4098 | } |
| 4099 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4100 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4101 | spin_lock_irq(shost->host_lock); |
| 4102 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4103 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4104 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4105 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4106 | |
| 4107 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4108 | lpfc_nlp_counters(vport, state, 1); |
| 4109 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4113 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4114 | { |
| 4115 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4116 | |
| 4117 | if (list_empty(&ndlp->nlp_listp)) { |
| 4118 | spin_lock_irq(shost->host_lock); |
| 4119 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4120 | spin_unlock_irq(shost->host_lock); |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4126 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4127 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4128 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4129 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4130 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4131 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4132 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4133 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4135 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4136 | NLP_STE_UNUSED_NODE); |
| 4137 | } |
| 4138 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4139 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4140 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4141 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4142 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4143 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4144 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4145 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4146 | NLP_STE_UNUSED_NODE); |
| 4147 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4148 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4149 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4150 | * @vport: Pointer to Virtual Port object. |
| 4151 | * @ndlp: Pointer to FC node object. |
| 4152 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4153 | * |
| 4154 | * This function is always called when node object need to be initialized. |
| 4155 | * It initializes all the fields of the node object. Although the reference |
| 4156 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4157 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4158 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4159 | * the final release of ndlp is determined by its reference count. And, the |
| 4160 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4161 | **/ |
| 4162 | static inline void |
| 4163 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4164 | uint32_t did) |
| 4165 | { |
| 4166 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4167 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 4168 | init_timer(&ndlp->nlp_delayfunc); |
| 4169 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 4170 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 4171 | ndlp->nlp_DID = did; |
| 4172 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4173 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4174 | ndlp->nlp_sid = NLP_NO_SID; |
| 4175 | kref_init(&ndlp->kref); |
| 4176 | NLP_INT_NODE_ACT(ndlp); |
| 4177 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4178 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4179 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4180 | |
| 4181 | struct lpfc_nodelist * |
| 4182 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4183 | int state) |
| 4184 | { |
| 4185 | struct lpfc_hba *phba = vport->phba; |
| 4186 | uint32_t did; |
| 4187 | unsigned long flags; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4188 | unsigned long *active_rrqs_xri_bitmap = NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4189 | |
| 4190 | if (!ndlp) |
| 4191 | return NULL; |
| 4192 | |
| 4193 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4194 | /* The ndlp should not be in memory free mode */ |
| 4195 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4196 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4197 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4198 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4199 | "usgmap:x%x refcnt:%d\n", |
| 4200 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4201 | atomic_read(&ndlp->kref.refcount)); |
| 4202 | return NULL; |
| 4203 | } |
| 4204 | /* The ndlp should not already be in active mode */ |
| 4205 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4206 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4207 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4208 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4209 | "usgmap:x%x refcnt:%d\n", |
| 4210 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4211 | atomic_read(&ndlp->kref.refcount)); |
| 4212 | return NULL; |
| 4213 | } |
| 4214 | |
| 4215 | /* Keep the original DID */ |
| 4216 | did = ndlp->nlp_DID; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4217 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4218 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4219 | |
| 4220 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4221 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4222 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4223 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4224 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4225 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4226 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; |
| 4227 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4228 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 4229 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4230 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
| 4231 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4232 | |
| 4233 | if (state != NLP_STE_UNUSED_NODE) |
| 4234 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4235 | |
| 4236 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4237 | "node enable: did:x%x", |
| 4238 | ndlp->nlp_DID, 0, 0); |
| 4239 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4244 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4245 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4246 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4247 | * 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] | 4248 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4249 | * until ALL other outstanding threads have completed. We check |
| 4250 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4251 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4252 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4253 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4254 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4255 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4256 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4257 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4258 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /* |
| 4262 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4263 | */ |
| 4264 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4265 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4267 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4268 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4269 | uint32_t tmo; |
| 4270 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4272 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4273 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4274 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4275 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4276 | * FC spec states we need 3 * ratov for CT requests |
| 4277 | */ |
| 4278 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4279 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4281 | |
| 4282 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4283 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4284 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4285 | tmo, vport->port_state, vport->fc_flag); |
| 4286 | } |
| 4287 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4288 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4289 | spin_lock_irq(shost->host_lock); |
| 4290 | vport->fc_flag |= FC_DISC_TMO; |
| 4291 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | |
| 4293 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4294 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4295 | "0247 Start Discovery Timer state x%x " |
| 4296 | "Data: x%x x%lx x%x x%x\n", |
| 4297 | vport->port_state, tmo, |
| 4298 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4299 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | |
| 4301 | return; |
| 4302 | } |
| 4303 | |
| 4304 | /* |
| 4305 | * Cancel rescue timer for Discovery / RSCN handling |
| 4306 | */ |
| 4307 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | unsigned long iflags; |
| 4312 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4313 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4314 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4315 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4319 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4320 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4321 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4322 | del_timer_sync(&vport->fc_disctmo); |
| 4323 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4324 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4325 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4329 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4330 | "0248 Cancel Discovery Timer state x%x " |
| 4331 | "Data: x%x x%x x%x\n", |
| 4332 | vport->port_state, vport->fc_flag, |
| 4333 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4334 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | /* |
| 4338 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4339 | * Return true if iocb matches the specified nport |
| 4340 | */ |
| 4341 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4342 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4343 | struct lpfc_sli_ring *pring, |
| 4344 | struct lpfc_iocbq *iocb, |
| 4345 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | struct lpfc_sli *psli = &phba->sli; |
| 4348 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4349 | struct lpfc_vport *vport = ndlp->vport; |
| 4350 | |
| 4351 | if (iocb->vport != vport) |
| 4352 | return 0; |
| 4353 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | if (pring->ringno == LPFC_ELS_RING) { |
| 4355 | switch (icmd->ulpCommand) { |
| 4356 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4357 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4358 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4360 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4361 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | case CMD_XMIT_ELS_RSP64_CX: |
| 4363 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4364 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4366 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4367 | |
| 4368 | } else if (pring->ringno == psli->fcp_ring) { |
| 4369 | /* Skip match check if waiting to relogin to FCP target */ |
| 4370 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4371 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4372 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | } |
| 4374 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4375 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4376 | } |
| 4377 | } else if (pring->ringno == psli->next_ring) { |
| 4378 | |
| 4379 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4380 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | /* |
| 4384 | * Free resources / clean up outstanding I/Os |
| 4385 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4386 | */ |
| 4387 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4388 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4390 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | struct lpfc_sli *psli; |
| 4392 | struct lpfc_sli_ring *pring; |
| 4393 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4394 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4396 | lpfc_fabric_abort_nport(ndlp); |
| 4397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4398 | /* |
| 4399 | * Everything that matches on txcmplq will be returned |
| 4400 | * by firmware with a no rpi error. |
| 4401 | */ |
| 4402 | psli = &phba->sli; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4403 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | /* Now process each ring */ |
| 4405 | for (i = 0; i < psli->num_rings; i++) { |
| 4406 | pring = &psli->ring[i]; |
| 4407 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4408 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | /* |
| 4412 | * Check to see if iocb matches the nport we are |
| 4413 | * looking for |
| 4414 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4415 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 4416 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4417 | /* It matches, so deque and call compl |
| 4418 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4419 | list_move_tail(&iocb->list, |
| 4420 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | } |
| 4422 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4423 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | } |
| 4425 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4426 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4427 | /* Cancel all the IOCBs from the completions list */ |
| 4428 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4429 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4430 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4431 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | } |
| 4433 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4434 | /** |
| 4435 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4436 | * @phba: Pointer to HBA context object. |
| 4437 | * @pmb: Pointer to mailbox object. |
| 4438 | * |
| 4439 | * This function will issue an ELS LOGO command after completing |
| 4440 | * the UNREG_RPI. |
| 4441 | **/ |
Rashika Kheria | b86a675 | 2014-09-03 12:55:17 -0400 | [diff] [blame^] | 4442 | static void |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4443 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4444 | { |
| 4445 | struct lpfc_vport *vport = pmb->vport; |
| 4446 | struct lpfc_nodelist *ndlp; |
| 4447 | |
| 4448 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4449 | if (!ndlp) |
| 4450 | return; |
| 4451 | lpfc_issue_els_logo(vport, ndlp, 0); |
James Smart | 4aa74c3 | 2013-09-06 12:19:06 -0400 | [diff] [blame] | 4452 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4453 | } |
| 4454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | /* |
| 4456 | * Free rpi associated with LPFC_NODELIST entry. |
| 4457 | * This routine is called from lpfc_freenode(), when we are removing |
| 4458 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4459 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4460 | * to the remote NPort. In addition, it is called after we receive |
| 4461 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4462 | * we are waiting to PLOGI back to the remote NPort. |
| 4463 | */ |
| 4464 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4465 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4467 | struct lpfc_hba *phba = vport->phba; |
| 4468 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4469 | int rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4470 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | |
James Smart | f454a9a | 2013-09-06 12:20:07 -0400 | [diff] [blame] | 4472 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
| 4473 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { |
| 4474 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 4475 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4476 | "3366 RPI x%x needs to be " |
| 4477 | "unregistered nlp_flag x%x " |
| 4478 | "did x%x\n", |
| 4479 | ndlp->nlp_rpi, ndlp->nlp_flag, |
| 4480 | ndlp->nlp_DID); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4482 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4483 | /* SLI4 ports require the physical rpi value. */ |
| 4484 | rpi = ndlp->nlp_rpi; |
| 4485 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4486 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4487 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4488 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4489 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4490 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4491 | mbox->context1 = ndlp; |
| 4492 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4493 | } else { |
| 4494 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4495 | } |
| 4496 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4497 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4499 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4500 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4502 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4503 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4504 | ndlp->nlp_rpi = 0; |
| 4505 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4506 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | return 1; |
| 4508 | } |
| 4509 | return 0; |
| 4510 | } |
| 4511 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4512 | /** |
| 4513 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4514 | * @phba: pointer to lpfc hba data structure. |
| 4515 | * |
| 4516 | * This routine is invoked to unregister all the currently registered RPIs |
| 4517 | * to the HBA. |
| 4518 | **/ |
| 4519 | void |
| 4520 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4521 | { |
| 4522 | struct lpfc_vport **vports; |
| 4523 | struct lpfc_nodelist *ndlp; |
| 4524 | struct Scsi_Host *shost; |
| 4525 | int i; |
| 4526 | |
| 4527 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4528 | if (!vports) { |
| 4529 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4530 | "2884 Vport array allocation failed \n"); |
| 4531 | return; |
| 4532 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4533 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4534 | shost = lpfc_shost_from_vport(vports[i]); |
| 4535 | spin_lock_irq(shost->host_lock); |
| 4536 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4537 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4538 | /* The mempool_alloc might sleep */ |
| 4539 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4540 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4541 | spin_lock_irq(shost->host_lock); |
| 4542 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4543 | } |
| 4544 | spin_unlock_irq(shost->host_lock); |
| 4545 | } |
| 4546 | lpfc_destroy_vport_work_array(phba, vports); |
| 4547 | } |
| 4548 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4549 | void |
| 4550 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4551 | { |
| 4552 | struct lpfc_hba *phba = vport->phba; |
| 4553 | LPFC_MBOXQ_t *mbox; |
| 4554 | int rc; |
| 4555 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4556 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4557 | lpfc_sli4_unreg_all_rpis(vport); |
| 4558 | return; |
| 4559 | } |
| 4560 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4561 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4562 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4563 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4564 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4565 | mbox->vport = vport; |
| 4566 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4567 | mbox->context1 = NULL; |
| 4568 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4569 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4570 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4571 | |
| 4572 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4573 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4574 | "1836 Could not issue " |
| 4575 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | void |
| 4580 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4581 | { |
| 4582 | struct lpfc_hba *phba = vport->phba; |
| 4583 | LPFC_MBOXQ_t *mbox; |
| 4584 | int rc; |
| 4585 | |
| 4586 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4587 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4588 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4589 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4590 | mbox->vport = vport; |
| 4591 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4592 | mbox->context1 = NULL; |
| 4593 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4594 | if (rc != MBX_TIMEOUT) |
| 4595 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4596 | |
| 4597 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4598 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4599 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4600 | "unreg_did (default rpis) status %d\n", |
| 4601 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4602 | } |
| 4603 | } |
| 4604 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4605 | /* |
| 4606 | * Free resources associated with LPFC_NODELIST entry |
| 4607 | * so it can be freed. |
| 4608 | */ |
| 4609 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4610 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4612 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4613 | struct lpfc_hba *phba = vport->phba; |
| 4614 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4615 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | |
| 4617 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4618 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4619 | "0900 Cleanup node for NPort x%x " |
| 4620 | "Data: x%x x%x x%x\n", |
| 4621 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4622 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4623 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4624 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4625 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4626 | "usgmap:x%x refcnt:%d\n", |
| 4627 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4628 | atomic_read(&ndlp->kref.refcount)); |
| 4629 | lpfc_dequeue_node(vport, ndlp); |
| 4630 | } else { |
| 4631 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4632 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4633 | "usgmap:x%x refcnt:%d\n", |
| 4634 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4635 | atomic_read(&ndlp->kref.refcount)); |
| 4636 | lpfc_disable_node(vport, ndlp); |
| 4637 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4639 | |
| 4640 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4641 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4643 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4644 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4645 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4647 | mb->context2 = NULL; |
| 4648 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4649 | } |
| 4650 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4651 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4652 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4653 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4654 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4655 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4656 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4657 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4658 | continue; |
| 4659 | |
| 4660 | mb->context2 = NULL; |
| 4661 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4662 | } |
| 4663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4665 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4666 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4667 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4669 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4670 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4671 | kfree(mp); |
| 4672 | } |
| 4673 | list_del(&mb->list); |
| 4674 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4675 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4676 | * the ndlp reference count as we are in the process |
| 4677 | * of lpfc_nlp_release. |
| 4678 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | } |
| 4680 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4681 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4682 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4683 | lpfc_els_abort(phba, ndlp); |
| 4684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4685 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4686 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4687 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4688 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4689 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4691 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4692 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4693 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4694 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4695 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4696 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4697 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | /* |
| 4701 | * Check to see if we can free the nlp back to the freelist. |
| 4702 | * If we are in the middle of using the nlp in the discovery state |
| 4703 | * machine, defer the free till we reach the end of the state machine. |
| 4704 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4705 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4706 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4708 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4709 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4710 | LPFC_MBOXQ_t *mbox; |
| 4711 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4712 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4713 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4714 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4715 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4716 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4717 | /* For this case we need to cleanup the default rpi |
| 4718 | * allocated by the firmware. |
| 4719 | */ |
| 4720 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4721 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4722 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4723 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4724 | if (rc) { |
| 4725 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4726 | } |
| 4727 | else { |
| 4728 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4729 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4730 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4731 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4732 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4733 | if (rc == MBX_NOT_FINISHED) { |
| 4734 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4735 | } |
| 4736 | } |
| 4737 | } |
| 4738 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4739 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4740 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4741 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4742 | * We can get here with a non-NULL ndlp->rport because when we |
| 4743 | * unregister a rport we don't break the rport/node linkage. So if we |
| 4744 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4745 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4746 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4747 | rdata = ndlp->rport->dd_data; |
| 4748 | rdata->pnode = NULL; |
| 4749 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4750 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4754 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4755 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4757 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | |
| 4759 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4760 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4761 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4762 | /* First check for Direct match */ |
| 4763 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4764 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | |
| 4766 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4767 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4769 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | matchdid.un.word = did; |
| 4773 | ndlpdid.un.word = ndlp->nlp_DID; |
| 4774 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 4775 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 4776 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 4777 | if ((ndlpdid.un.b.domain == 0) && |
| 4778 | (ndlpdid.un.b.area == 0)) { |
| 4779 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4780 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4782 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | matchdid.un.word = ndlp->nlp_DID; |
| 4786 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 4787 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 4788 | if ((matchdid.un.b.domain == 0) && |
| 4789 | (matchdid.un.b.area == 0)) { |
| 4790 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4791 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | } |
| 4793 | } |
| 4794 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4795 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | } |
| 4797 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4798 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4799 | static struct lpfc_nodelist * |
| 4800 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 4802 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4803 | uint32_t data1; |
| 4804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4805 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 4806 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4807 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 4808 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 4809 | ((uint32_t) ndlp->nlp_type << 8) | |
| 4810 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4811 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4812 | "0929 FIND node DID " |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4813 | "Data: x%p x%x x%x x%x %p\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4814 | ndlp, ndlp->nlp_DID, |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 4815 | ndlp->nlp_flag, data1, |
| 4816 | ndlp->active_rrqs_xri_bitmap); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4817 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4818 | } |
| 4819 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4823 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | return NULL; |
| 4825 | } |
| 4826 | |
| 4827 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4828 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4829 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4830 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4832 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4833 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4834 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4835 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4836 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4837 | return ndlp; |
| 4838 | } |
| 4839 | |
| 4840 | struct lpfc_nodelist * |
| 4841 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 4842 | { |
| 4843 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4844 | struct lpfc_nodelist *ndlp; |
| 4845 | |
| 4846 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4847 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4848 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4849 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4850 | return NULL; |
| 4851 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4852 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | if (!ndlp) |
| 4854 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4855 | lpfc_nlp_init(vport, ndlp, did); |
| 4856 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4857 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4859 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4861 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4862 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4863 | if (!ndlp) |
| 4864 | return NULL; |
| 4865 | spin_lock_irq(shost->host_lock); |
| 4866 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4867 | spin_unlock_irq(shost->host_lock); |
| 4868 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4870 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4871 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4872 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4873 | if (lpfc_rscn_payload_check(vport, did)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4874 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4875 | * we don't need to try to discover it again. |
| 4876 | */ |
| 4877 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4878 | return NULL; |
| 4879 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4880 | /* Since this node is marked for discovery, |
| 4881 | * delay timeout is not needed. |
| 4882 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4883 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4884 | spin_lock_irq(shost->host_lock); |
| 4885 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4886 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4887 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4889 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4890 | /* If we've already received a PLOGI from this NPort, |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4891 | * or we are already in the process of discovery on it, |
| 4892 | * we don't need to try to discover it again. |
| 4893 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4894 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4895 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4896 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4897 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4898 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4899 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4900 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4901 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | } |
| 4903 | return ndlp; |
| 4904 | } |
| 4905 | |
| 4906 | /* Build a list of nodes to discover based on the loopmap */ |
| 4907 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4908 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4909 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4910 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | int j; |
| 4912 | uint32_t alpa, index; |
| 4913 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4914 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4915 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4916 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4917 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | |
| 4920 | /* Check for loop map present or not */ |
| 4921 | if (phba->alpa_map[0]) { |
| 4922 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4923 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4924 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | } |
| 4928 | } else { |
| 4929 | /* No alpamap, so try all alpa's */ |
| 4930 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4931 | /* If cfg_scan_down is set, start from highest |
| 4932 | * ALPA (0xef) to lowest (0x1). |
| 4933 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4934 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | index = j; |
| 4936 | else |
| 4937 | index = FC_MAXLOOP - j - 1; |
| 4938 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4939 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4940 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4941 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | return; |
| 4945 | } |
| 4946 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4948 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4949 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4950 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4951 | struct lpfc_sli *psli = &phba->sli; |
| 4952 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4953 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4954 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4955 | int rc; |
| 4956 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4957 | /* |
| 4958 | * if it's not a physical port or if we already send |
| 4959 | * clear_la then don't send it. |
| 4960 | */ |
| 4961 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4962 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4963 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4964 | return; |
| 4965 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4966 | /* Link up discovery */ |
| 4967 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4968 | phba->link_state = LPFC_CLEAR_LA; |
| 4969 | lpfc_clear_la(phba, mbox); |
| 4970 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4971 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4972 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4973 | if (rc == MBX_NOT_FINISHED) { |
| 4974 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4975 | lpfc_disc_flush_list(vport); |
| 4976 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4977 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4978 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4979 | phba->link_state = LPFC_HBA_ERROR; |
| 4980 | } |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4985 | void |
| 4986 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4987 | { |
| 4988 | LPFC_MBOXQ_t *regvpimbox; |
| 4989 | |
| 4990 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4991 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4992 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4993 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4994 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4995 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4996 | == MBX_NOT_FINISHED) { |
| 4997 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4998 | } |
| 4999 | } |
| 5000 | } |
| 5001 | |
| 5002 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 5003 | void |
| 5004 | lpfc_disc_start(struct lpfc_vport *vport) |
| 5005 | { |
| 5006 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5007 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5008 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5010 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5011 | |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5012 | if (!lpfc_is_link_up(phba)) { |
| 5013 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 5014 | "3315 Link is not up %x\n", |
| 5015 | phba->link_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | return; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5017 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5018 | |
| 5019 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5020 | clear_la_pending = 1; |
| 5021 | else |
| 5022 | clear_la_pending = 0; |
| 5023 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5024 | if (vport->port_state < LPFC_VPORT_READY) |
| 5025 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5026 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5027 | lpfc_set_disctmo(vport); |
| 5028 | |
| 5029 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5031 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5032 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5033 | |
| 5034 | vport->fc_prevDID = vport->fc_myDID; |
| 5035 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | |
| 5037 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5038 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 5039 | "0202 Start Discovery hba state x%x " |
| 5040 | "Data: x%x x%x x%x\n", |
| 5041 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 5042 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | |
| 5044 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5045 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | |
| 5047 | if (num_sent) |
| 5048 | return; |
| 5049 | |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5050 | /* Register the VPI for SLI3, NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5051 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5052 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5053 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5054 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 6fa139f | 2013-04-17 20:20:00 -0400 | [diff] [blame] | 5055 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5056 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5057 | lpfc_issue_reg_vpi(phba, vport); |
| 5058 | return; |
| 5059 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5060 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5061 | /* |
| 5062 | * For SLI2, we need to set port_state to READY and continue |
| 5063 | * discovery. |
| 5064 | */ |
| 5065 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5066 | /* If we get here, there is nothing to ADISC */ |
| 5067 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5068 | lpfc_issue_clear_la(phba, vport); |
| 5069 | |
| 5070 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5071 | vport->num_disc_nodes = 0; |
| 5072 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5073 | if (vport->fc_npr_cnt) |
| 5074 | lpfc_els_disc_plogi(vport); |
| 5075 | |
| 5076 | if (!vport->num_disc_nodes) { |
| 5077 | spin_lock_irq(shost->host_lock); |
| 5078 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5079 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5080 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5081 | } |
| 5082 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5083 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | } else { |
| 5085 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5086 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5087 | |
| 5088 | if (num_sent) |
| 5089 | return; |
| 5090 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5091 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5092 | /* Check to see if more RSCNs came in while we |
| 5093 | * were processing this one. |
| 5094 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5095 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5096 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5097 | spin_lock_irq(shost->host_lock); |
| 5098 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5099 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5100 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5101 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5102 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5103 | } |
| 5104 | } |
| 5105 | return; |
| 5106 | } |
| 5107 | |
| 5108 | /* |
| 5109 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5110 | * ring the match the sppecified nodelist. |
| 5111 | */ |
| 5112 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5113 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5115 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5116 | struct lpfc_sli *psli; |
| 5117 | IOCB_t *icmd; |
| 5118 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5119 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | |
| 5121 | psli = &phba->sli; |
| 5122 | pring = &psli->ring[LPFC_ELS_RING]; |
| 5123 | |
| 5124 | /* Error matching iocb on txq or txcmplq |
| 5125 | * First check the txq. |
| 5126 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5127 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5128 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5129 | if (iocb->context1 != ndlp) { |
| 5130 | continue; |
| 5131 | } |
| 5132 | icmd = &iocb->iocb; |
| 5133 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5134 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5135 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5136 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | /* Next check the txcmplq */ |
| 5141 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5142 | if (iocb->context1 != ndlp) { |
| 5143 | continue; |
| 5144 | } |
| 5145 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5146 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5147 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5148 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | } |
| 5150 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5151 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5152 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5153 | /* Cancel all the IOCBs from the completions list */ |
| 5154 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5155 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5156 | } |
| 5157 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5158 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5159 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5160 | { |
| 5161 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5162 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5165 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5166 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5167 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5168 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5169 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5170 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5171 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5172 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5173 | } |
| 5174 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5175 | } |
| 5176 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5177 | void |
| 5178 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5179 | { |
| 5180 | lpfc_els_flush_rscn(vport); |
| 5181 | lpfc_els_flush_cmd(vport); |
| 5182 | lpfc_disc_flush_list(vport); |
| 5183 | } |
| 5184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | /*****************************************************************************/ |
| 5186 | /* |
| 5187 | * NAME: lpfc_disc_timeout |
| 5188 | * |
| 5189 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5190 | * |
| 5191 | * EXECUTION ENVIRONMENT: interrupt only |
| 5192 | * |
| 5193 | * CALLED FROM: |
| 5194 | * Timer function |
| 5195 | * |
| 5196 | * RETURNS: |
| 5197 | * none |
| 5198 | */ |
| 5199 | /*****************************************************************************/ |
| 5200 | void |
| 5201 | lpfc_disc_timeout(unsigned long ptr) |
| 5202 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5203 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5204 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5205 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | unsigned long flags = 0; |
| 5207 | |
| 5208 | if (unlikely(!phba)) |
| 5209 | return; |
| 5210 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5211 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5212 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5213 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5214 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5215 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5216 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5217 | if (!tmo_posted) |
| 5218 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5219 | return; |
| 5220 | } |
| 5221 | |
| 5222 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5225 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5226 | struct lpfc_hba *phba = vport->phba; |
| 5227 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5228 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5229 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | int rc, clrlaerr = 0; |
| 5231 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5232 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | return; |
| 5234 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5235 | spin_lock_irq(shost->host_lock); |
| 5236 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5237 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5239 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5240 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5241 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5242 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | |
| 5245 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 5247 | * FAN |
| 5248 | */ |
| 5249 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5250 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5251 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5252 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5254 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5255 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5256 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5257 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5258 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5259 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5260 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5261 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5262 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5263 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5264 | /* Fail outstanding IO now since device |
| 5265 | * is marked for PLOGI. |
| 5266 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5267 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5268 | } |
| 5269 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5270 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5271 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5272 | lpfc_initial_flogi(vport); |
| 5273 | else |
| 5274 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5275 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5276 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5277 | break; |
| 5278 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5279 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5281 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5283 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5284 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5285 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | |
| 5287 | /* Assume no Fabric and go on with discovery. |
| 5288 | * Check for outstanding ELS FLOGI to abort. |
| 5289 | */ |
| 5290 | |
| 5291 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5292 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5293 | |
| 5294 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5295 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | break; |
| 5297 | |
| 5298 | case LPFC_FABRIC_CFG_LINK: |
| 5299 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5300 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5301 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5302 | "0223 Timeout while waiting for " |
| 5303 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5306 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5307 | lpfc_els_abort(phba, ndlp); |
| 5308 | |
| 5309 | /* ReStart discovery */ |
| 5310 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5311 | |
| 5312 | case LPFC_NS_QRY: |
| 5313 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5314 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5315 | "0224 NameServer Query timeout " |
| 5316 | "Data: x%x x%x\n", |
| 5317 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5319 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5320 | /* Try it one more time */ |
| 5321 | vport->fc_ns_retry++; |
| 5322 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 5323 | vport->fc_ns_retry, 0); |
| 5324 | if (rc == 0) |
| 5325 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5326 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5327 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5329 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5330 | /* |
| 5331 | * Discovery is over. |
| 5332 | * set port_state to PORT_READY if SLI2. |
| 5333 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5334 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5335 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5336 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5337 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5338 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5339 | lpfc_issue_clear_la(phba, vport); |
| 5340 | vport->port_state = LPFC_VPORT_READY; |
| 5341 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5345 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5346 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5347 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5348 | "0206 Device Discovery " |
| 5349 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5350 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5351 | break; |
| 5352 | } |
| 5353 | |
| 5354 | lpfc_linkdown(phba); |
| 5355 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5356 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5357 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5358 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5359 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5360 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5361 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5362 | if (rc == MBX_NOT_FINISHED) |
| 5363 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5364 | |
| 5365 | break; |
| 5366 | |
| 5367 | case LPFC_DISC_AUTH: |
| 5368 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5369 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5370 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5371 | lpfc_disc_flush_list(vport); |
| 5372 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5373 | /* |
| 5374 | * set port_state to PORT_READY if SLI2. |
| 5375 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5376 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5377 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5378 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5379 | lpfc_issue_reg_vpi(phba, vport); |
| 5380 | else { /* NPIV Not enabled */ |
| 5381 | lpfc_issue_clear_la(phba, vport); |
| 5382 | vport->port_state = LPFC_VPORT_READY; |
| 5383 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5384 | } |
| 5385 | break; |
| 5386 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5387 | case LPFC_VPORT_READY: |
| 5388 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5389 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5390 | "0231 RSCN timeout Data: x%x " |
| 5391 | "x%x\n", |
| 5392 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5393 | |
| 5394 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5395 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5397 | lpfc_els_flush_rscn(vport); |
| 5398 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5399 | } |
| 5400 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5401 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5402 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5403 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5404 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5405 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5406 | break; |
| 5407 | } |
| 5408 | |
| 5409 | switch (phba->link_state) { |
| 5410 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5411 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5412 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5413 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5414 | clrlaerr = 1; |
| 5415 | break; |
| 5416 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5417 | case LPFC_LINK_UP: |
| 5418 | lpfc_issue_clear_la(phba, vport); |
| 5419 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5420 | case LPFC_LINK_UNKNOWN: |
| 5421 | case LPFC_WARM_START: |
| 5422 | case LPFC_INIT_START: |
| 5423 | case LPFC_INIT_MBX_CMDS: |
| 5424 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5425 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5426 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5427 | "0230 Unexpected timeout, hba link " |
| 5428 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5429 | clrlaerr = 1; |
| 5430 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5431 | |
| 5432 | case LPFC_HBA_READY: |
| 5433 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5437 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5438 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5440 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5441 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | return; |
| 5445 | } |
| 5446 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | /* |
| 5448 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5449 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5450 | * as the completion routine when the command is |
| 5451 | * handed off to the SLI layer. |
| 5452 | */ |
| 5453 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5454 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5455 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5456 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5458 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5459 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5460 | |
| 5461 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5462 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5463 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5464 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5465 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5466 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5467 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5468 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5470 | /* |
| 5471 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 5472 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 5473 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5475 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5476 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5477 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 5478 | else |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5479 | mod_timer(&vport->fc_fdmitmo, |
| 5480 | jiffies + msecs_to_jiffies(1000 * 60)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5481 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5482 | /* decrement the node reference count held for this callback |
| 5483 | * function. |
| 5484 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5485 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5487 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5488 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5489 | |
| 5490 | return; |
| 5491 | } |
| 5492 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5493 | static int |
| 5494 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5495 | { |
| 5496 | uint16_t *rpi = param; |
| 5497 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5498 | /* check for active node */ |
| 5499 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5500 | return 0; |
| 5501 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5502 | return ndlp->nlp_rpi == *rpi; |
| 5503 | } |
| 5504 | |
| 5505 | static int |
| 5506 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5507 | { |
| 5508 | return memcmp(&ndlp->nlp_portname, param, |
| 5509 | sizeof(ndlp->nlp_portname)) == 0; |
| 5510 | } |
| 5511 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5512 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5515 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5517 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5518 | if (filter(ndlp, param)) { |
| 5519 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5520 | "3185 FIND node filter %p DID " |
| 5521 | "Data: x%p x%x x%x\n", |
| 5522 | filter, ndlp, ndlp->nlp_DID, |
| 5523 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5524 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5525 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5526 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5527 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5528 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5529 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5530 | } |
| 5531 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5532 | /* |
| 5533 | * 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] | 5534 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5535 | */ |
| 5536 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5539 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5540 | } |
| 5541 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5542 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5543 | * 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] | 5544 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5545 | */ |
| 5546 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5547 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5548 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5549 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5550 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5551 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5552 | spin_lock_irq(shost->host_lock); |
| 5553 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5554 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5555 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5556 | } |
| 5557 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5558 | /* |
| 5559 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5560 | * is found, the routine returns the node element list pointer else |
| 5561 | * return NULL. |
| 5562 | */ |
| 5563 | struct lpfc_nodelist * |
| 5564 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5565 | { |
| 5566 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5567 | struct lpfc_nodelist *ndlp; |
| 5568 | |
| 5569 | spin_lock_irq(shost->host_lock); |
| 5570 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5571 | spin_unlock_irq(shost->host_lock); |
| 5572 | return ndlp; |
| 5573 | } |
| 5574 | |
| 5575 | /** |
| 5576 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5577 | * @phba: pointer to lpfc hba data structure. |
| 5578 | * @vpi: the physical host virtual N_Port identifier. |
| 5579 | * |
| 5580 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5581 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5582 | * of the vport with the matching @vpi. |
| 5583 | * |
| 5584 | * Return code |
| 5585 | * NULL - No vport with the matching @vpi found |
| 5586 | * Otherwise - Address to the vport with the matching @vpi. |
| 5587 | **/ |
| 5588 | struct lpfc_vport * |
| 5589 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5590 | { |
| 5591 | struct lpfc_vport *vport; |
| 5592 | unsigned long flags; |
| 5593 | int i = 0; |
| 5594 | |
| 5595 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5596 | if (vpi > 0) { |
| 5597 | /* |
| 5598 | * Translate the physical vpi to the logical vpi. The |
| 5599 | * vport stores the logical vpi. |
| 5600 | */ |
| 5601 | for (i = 0; i < phba->max_vpi; i++) { |
| 5602 | if (vpi == phba->vpi_ids[i]) |
| 5603 | break; |
| 5604 | } |
| 5605 | |
| 5606 | if (i >= phba->max_vpi) { |
| 5607 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5608 | "2936 Could not find Vport mapped " |
| 5609 | "to vpi %d\n", vpi); |
| 5610 | return NULL; |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5615 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5616 | if (vport->vpi == i) { |
| 5617 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5618 | return vport; |
| 5619 | } |
| 5620 | } |
| 5621 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5622 | return NULL; |
| 5623 | } |
| 5624 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5625 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5626 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5627 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5628 | { |
| 5629 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5630 | |
| 5631 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5632 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5633 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5634 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5635 | ndlp->active_rrqs_xri_bitmap = |
| 5636 | mempool_alloc(vport->phba->active_rrq_pool, |
| 5637 | GFP_KERNEL); |
James Smart | 59c5f61 | 2014-05-21 08:05:10 -0400 | [diff] [blame] | 5638 | if (ndlp->active_rrqs_xri_bitmap) |
| 5639 | memset(ndlp->active_rrqs_xri_bitmap, 0, |
| 5640 | ndlp->phba->cfg_rrq_xri_bitmap_sz); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5641 | } |
| 5642 | |
James Smart | 725dd39 | 2013-10-10 12:23:30 -0400 | [diff] [blame] | 5643 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5644 | |
| 5645 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5646 | "node init: did:x%x", |
| 5647 | ndlp->nlp_DID, 0, 0); |
| 5648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5649 | return; |
| 5650 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5651 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5652 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5653 | * and mempool_free's the nodelist. |
| 5654 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5655 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5656 | lpfc_nlp_release(struct kref *kref) |
| 5657 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5658 | struct lpfc_hba *phba; |
| 5659 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5660 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 5661 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5662 | |
| 5663 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5664 | "node release: did:x%x flg:x%x type:x%x", |
| 5665 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 5666 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5667 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5668 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5669 | "usgmap:x%x refcnt:%d\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5670 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5671 | atomic_read(&ndlp->kref.refcount)); |
| 5672 | |
| 5673 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5675 | |
| 5676 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5677 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5678 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5679 | NLP_CLR_NODE_ACT(ndlp); |
| 5680 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5681 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5682 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5683 | |
| 5684 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5685 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5686 | kfree(ndlp->lat_data); |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5687 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5688 | mempool_free(ndlp->active_rrqs_xri_bitmap, |
| 5689 | ndlp->phba->active_rrq_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5690 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5691 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5692 | } |
| 5693 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5694 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 5695 | * that one discovery thread won't free a ndlp while another discovery thread |
| 5696 | * is using it. |
| 5697 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5698 | struct lpfc_nodelist * |
| 5699 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 5700 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5701 | struct lpfc_hba *phba; |
| 5702 | unsigned long flags; |
| 5703 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5704 | if (ndlp) { |
| 5705 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5706 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 5707 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5708 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5709 | /* The check of ndlp usage to prevent incrementing the |
| 5710 | * ndlp reference count that is in the process of being |
| 5711 | * released. |
| 5712 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5713 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5714 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5715 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 5716 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5717 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5718 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 5719 | "usgmap:x%x refcnt:%d\n", |
| 5720 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5721 | atomic_read(&ndlp->kref.refcount)); |
| 5722 | return NULL; |
| 5723 | } else |
| 5724 | kref_get(&ndlp->kref); |
| 5725 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5726 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5727 | return ndlp; |
| 5728 | } |
| 5729 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5730 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5731 | * count goes to 0, this indicates the the associated nodelist should be |
| 5732 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 5733 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 5734 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5735 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5736 | int |
| 5737 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 5738 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5739 | struct lpfc_hba *phba; |
| 5740 | unsigned long flags; |
| 5741 | |
| 5742 | if (!ndlp) |
| 5743 | return 1; |
| 5744 | |
| 5745 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5746 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 5747 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5748 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5749 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5750 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5751 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 5752 | * possible race condition that kref_put got invoked again |
| 5753 | * after previous one has done ndlp memory free. |
| 5754 | */ |
| 5755 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 5756 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5757 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5758 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 5759 | "usgmap:x%x refcnt:%d\n", |
| 5760 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5761 | atomic_read(&ndlp->kref.refcount)); |
| 5762 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5763 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5764 | /* Check the ndlp inactivate log flag to avoid the possible |
| 5765 | * race condition that kref_put got invoked again after ndlp |
| 5766 | * is already in inactivating state. |
| 5767 | */ |
| 5768 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 5769 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5770 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5771 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 5772 | "usgmap:x%x refcnt:%d\n", |
| 5773 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5774 | atomic_read(&ndlp->kref.refcount)); |
| 5775 | return 1; |
| 5776 | } |
| 5777 | /* For last put, mark the ndlp usage flags to make sure no |
| 5778 | * other kref_get and kref_put on the same ndlp shall get |
| 5779 | * in between the process when the final kref_put has been |
| 5780 | * invoked on this ndlp. |
| 5781 | */ |
| 5782 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 5783 | /* Indicate ndlp is put to inactive state. */ |
| 5784 | NLP_SET_IACT_REQ(ndlp); |
| 5785 | /* Acknowledge ndlp memory free has been seen. */ |
| 5786 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 5787 | NLP_SET_FREE_ACK(ndlp); |
| 5788 | } |
| 5789 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5790 | /* Note, the kref_put returns 1 when decrementing a reference |
| 5791 | * count that was 1, it invokes the release callback function, |
| 5792 | * but it still left the reference count as 1 (not actually |
| 5793 | * performs the last decrementation). Otherwise, it actually |
| 5794 | * decrements the reference count and returns 0. |
| 5795 | */ |
| 5796 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5797 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5798 | |
| 5799 | /* 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] | 5800 | * by any other discovery thread. This routine returns 1 if the |
| 5801 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 5802 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5803 | */ |
| 5804 | int |
| 5805 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 5806 | { |
| 5807 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5808 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 5809 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5810 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5811 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 5812 | if (lpfc_nlp_put(ndlp)) |
| 5813 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5814 | return 0; |
| 5815 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5816 | |
| 5817 | /** |
| 5818 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 5819 | * @phba: Pointer to hba context object. |
| 5820 | * |
| 5821 | * This function iterate through all FC nodes associated |
| 5822 | * will all vports to check if there is any node with |
| 5823 | * fc_rports associated with it. If there is an fc_rport |
| 5824 | * associated with the node, then the node is either in |
| 5825 | * discovered state or its devloss_timer is pending. |
| 5826 | */ |
| 5827 | static int |
| 5828 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 5829 | { |
| 5830 | struct lpfc_vport **vports; |
| 5831 | int i, ret = 0; |
| 5832 | struct lpfc_nodelist *ndlp; |
| 5833 | struct Scsi_Host *shost; |
| 5834 | |
| 5835 | vports = lpfc_create_vport_work_array(phba); |
| 5836 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5837 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 5838 | if (!vports) |
| 5839 | return 1; |
| 5840 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5841 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5842 | shost = lpfc_shost_from_vport(vports[i]); |
| 5843 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5844 | /* |
| 5845 | * IF the CVL_RCVD bit is not set then we have sent the |
| 5846 | * flogi. |
| 5847 | * If dev_loss fires while we are waiting we do not want to |
| 5848 | * unreg the fcf. |
| 5849 | */ |
| 5850 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 5851 | spin_unlock_irq(shost->host_lock); |
| 5852 | ret = 1; |
| 5853 | goto out; |
| 5854 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5855 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 5856 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 5857 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 5858 | ret = 1; |
| 5859 | spin_unlock_irq(shost->host_lock); |
| 5860 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5861 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 5862 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5863 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5864 | "2624 RPI %x DID %x flag %x " |
| 5865 | "still logged in\n", |
| 5866 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5867 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5868 | } |
| 5869 | } |
| 5870 | spin_unlock_irq(shost->host_lock); |
| 5871 | } |
| 5872 | out: |
| 5873 | lpfc_destroy_vport_work_array(phba, vports); |
| 5874 | return ret; |
| 5875 | } |
| 5876 | |
| 5877 | /** |
| 5878 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 5879 | * @phba: Pointer to hba context object. |
| 5880 | * @mboxq: Pointer to mailbox object. |
| 5881 | * |
| 5882 | * This function frees memory associated with the mailbox command. |
| 5883 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5884 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5885 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5886 | { |
| 5887 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5888 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5889 | |
| 5890 | if (mboxq->u.mb.mbxStatus) { |
| 5891 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5892 | "2555 UNREG_VFI mbxStatus error x%x " |
| 5893 | "HBA state x%x\n", |
| 5894 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5895 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5896 | spin_lock_irq(shost->host_lock); |
| 5897 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 5898 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5899 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5900 | return; |
| 5901 | } |
| 5902 | |
| 5903 | /** |
| 5904 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 5905 | * @phba: Pointer to hba context object. |
| 5906 | * @mboxq: Pointer to mailbox object. |
| 5907 | * |
| 5908 | * This function frees memory associated with the mailbox command. |
| 5909 | */ |
| 5910 | static void |
| 5911 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5912 | { |
| 5913 | struct lpfc_vport *vport = mboxq->vport; |
| 5914 | |
| 5915 | if (mboxq->u.mb.mbxStatus) { |
| 5916 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5917 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 5918 | "HBA state x%x\n", |
| 5919 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5920 | } |
| 5921 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5922 | return; |
| 5923 | } |
| 5924 | |
| 5925 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5926 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5927 | * @phba: Pointer to hba context object. |
| 5928 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5929 | * This function prepare the HBA for unregistering the currently registered |
| 5930 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 5931 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5932 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5933 | int |
| 5934 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5935 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5936 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5937 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5938 | struct Scsi_Host *shost; |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5939 | int i = 0, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5940 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5941 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5942 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5943 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5944 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5945 | /* At this point, all discovery is aborted */ |
| 5946 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5947 | |
| 5948 | /* Unregister VPIs */ |
| 5949 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5950 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5951 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5952 | /* Stop FLOGI/FDISC retries */ |
| 5953 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 5954 | if (ndlp) |
| 5955 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5956 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5957 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5958 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5959 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5960 | shost = lpfc_shost_from_vport(vports[i]); |
| 5961 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5962 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5963 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5964 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5965 | } |
| 5966 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 5967 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
| 5968 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 5969 | if (ndlp) |
| 5970 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
| 5971 | lpfc_cleanup_pending_mbox(phba->pport); |
| 5972 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5973 | lpfc_sli4_unreg_all_rpis(phba->pport); |
| 5974 | lpfc_mbx_unreg_vpi(phba->pport); |
| 5975 | shost = lpfc_shost_from_vport(phba->pport); |
| 5976 | spin_lock_irq(shost->host_lock); |
| 5977 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 5978 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; |
| 5979 | spin_unlock_irq(shost->host_lock); |
| 5980 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5981 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5982 | /* Cleanup any outstanding ELS commands */ |
| 5983 | lpfc_els_flush_all_cmd(phba); |
| 5984 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5985 | /* Unregister the physical port VFI */ |
| 5986 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 5987 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
| 5991 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5992 | * @phba: Pointer to hba context object. |
| 5993 | * |
| 5994 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5995 | * unregister the currently registered FCF record. The driver does not reset |
| 5996 | * the driver FCF usage state flags. |
| 5997 | * |
| 5998 | * Return 0 if successfully issued, none-zero otherwise. |
| 5999 | */ |
| 6000 | int |
| 6001 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 6002 | { |
| 6003 | LPFC_MBOXQ_t *mbox; |
| 6004 | int rc; |
| 6005 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6006 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6007 | if (!mbox) { |
| 6008 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6009 | "2551 UNREG_FCFI mbox allocation failed" |
| 6010 | "HBA state x%x\n", phba->pport->port_state); |
| 6011 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6012 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6013 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 6014 | mbox->vport = phba->pport; |
| 6015 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 6016 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6017 | |
| 6018 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6019 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6020 | "2552 Unregister FCFI command failed rc x%x " |
| 6021 | "HBA state x%x\n", |
| 6022 | rc, phba->pport->port_state); |
| 6023 | return -EINVAL; |
| 6024 | } |
| 6025 | return 0; |
| 6026 | } |
| 6027 | |
| 6028 | /** |
| 6029 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 6030 | * @phba: Pointer to hba context object. |
| 6031 | * |
| 6032 | * This function unregisters the currently reigstered FCF. This function |
| 6033 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 6034 | */ |
| 6035 | void |
| 6036 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 6037 | { |
| 6038 | int rc; |
| 6039 | |
| 6040 | /* Preparation for unregistering fcf */ |
| 6041 | rc = lpfc_unregister_fcf_prep(phba); |
| 6042 | if (rc) { |
| 6043 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6044 | "2748 Failed to prepare for unregistering " |
| 6045 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6046 | return; |
| 6047 | } |
| 6048 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6049 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6050 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6051 | if (rc) |
| 6052 | return; |
| 6053 | /* Reset HBA FCF states after successful unregister FCF */ |
| 6054 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6055 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6056 | |
| 6057 | /* |
| 6058 | * If driver is not unloading, check if there is any other |
| 6059 | * FCF record that can be used for discovery. |
| 6060 | */ |
| 6061 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6062 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6063 | return; |
| 6064 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6065 | /* This is considered as the initial FCF discovery scan */ |
| 6066 | spin_lock_irq(&phba->hbalock); |
| 6067 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 6068 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6069 | |
| 6070 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6071 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6072 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6073 | 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] | 6074 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6075 | if (rc) { |
| 6076 | spin_lock_irq(&phba->hbalock); |
| 6077 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 6078 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6079 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6080 | "2553 lpfc_unregister_unused_fcf failed " |
| 6081 | "to read FCF record HBA state x%x\n", |
| 6082 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6083 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | /** |
| 6087 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6088 | * @phba: Pointer to hba context object. |
| 6089 | * |
| 6090 | * This function just unregisters the currently reigstered FCF. It does not |
| 6091 | * try to find another FCF for discovery. |
| 6092 | */ |
| 6093 | void |
| 6094 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6095 | { |
| 6096 | int rc; |
| 6097 | |
| 6098 | /* Preparation for unregistering fcf */ |
| 6099 | rc = lpfc_unregister_fcf_prep(phba); |
| 6100 | if (rc) { |
| 6101 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6102 | "2749 Failed to prepare for unregistering " |
| 6103 | "HBA's FCF record: rc=%d\n", rc); |
| 6104 | return; |
| 6105 | } |
| 6106 | |
| 6107 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6108 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6109 | if (rc) |
| 6110 | return; |
| 6111 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6112 | spin_lock_irq(&phba->hbalock); |
| 6113 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6114 | spin_unlock_irq(&phba->hbalock); |
| 6115 | } |
| 6116 | |
| 6117 | /** |
| 6118 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6119 | * @phba: Pointer to hba context object. |
| 6120 | * |
| 6121 | * This function check if there are any connected remote port for the FCF and |
| 6122 | * if all the devices are disconnected, this function unregister FCFI. |
| 6123 | * This function also tries to use another FCF for discovery. |
| 6124 | */ |
| 6125 | void |
| 6126 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6127 | { |
| 6128 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6129 | * If HBA is not running in FIP mode, if HBA does not support |
| 6130 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6131 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6132 | */ |
| 6133 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6134 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6135 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6136 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6137 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6138 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6139 | spin_unlock_irq(&phba->hbalock); |
| 6140 | return; |
| 6141 | } |
| 6142 | spin_unlock_irq(&phba->hbalock); |
| 6143 | |
| 6144 | if (lpfc_fcf_inuse(phba)) |
| 6145 | return; |
| 6146 | |
| 6147 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | /** |
| 6151 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6152 | * @phba: Pointer to hba context object. |
| 6153 | * @buff: Buffer containing the FCF connection table as in the config |
| 6154 | * region. |
| 6155 | * This function create driver data structure for the FCF connection |
| 6156 | * record table read from config region 23. |
| 6157 | */ |
| 6158 | static void |
| 6159 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6160 | uint8_t *buff) |
| 6161 | { |
| 6162 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6163 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6164 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6165 | uint32_t record_count; |
| 6166 | int i; |
| 6167 | |
| 6168 | /* Free the current connect table */ |
| 6169 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6170 | &phba->fcf_conn_rec_list, list) { |
| 6171 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6172 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6173 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6174 | |
| 6175 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6176 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6177 | sizeof(struct lpfc_fcf_conn_rec); |
| 6178 | |
| 6179 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6180 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6181 | |
| 6182 | for (i = 0; i < record_count; i++) { |
| 6183 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6184 | continue; |
| 6185 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6186 | GFP_KERNEL); |
| 6187 | if (!conn_entry) { |
| 6188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6189 | "2566 Failed to allocate connection" |
| 6190 | " table entry\n"); |
| 6191 | return; |
| 6192 | } |
| 6193 | |
| 6194 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6195 | sizeof(struct lpfc_fcf_conn_rec)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6196 | list_add_tail(&conn_entry->list, |
| 6197 | &phba->fcf_conn_rec_list); |
| 6198 | } |
James Smart | df0d085 | 2013-05-31 17:05:08 -0400 | [diff] [blame] | 6199 | |
| 6200 | if (!list_empty(&phba->fcf_conn_rec_list)) { |
| 6201 | i = 0; |
| 6202 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, |
| 6203 | list) { |
| 6204 | conn_rec = &conn_entry->conn_rec; |
| 6205 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6206 | "3345 FCF connection list rec[%02d]: " |
| 6207 | "flags:x%04x, vtag:x%04x, " |
| 6208 | "fabric_name:x%02x:%02x:%02x:%02x:" |
| 6209 | "%02x:%02x:%02x:%02x, " |
| 6210 | "switch_name:x%02x:%02x:%02x:%02x:" |
| 6211 | "%02x:%02x:%02x:%02x\n", i++, |
| 6212 | conn_rec->flags, conn_rec->vlan_tag, |
| 6213 | conn_rec->fabric_name[0], |
| 6214 | conn_rec->fabric_name[1], |
| 6215 | conn_rec->fabric_name[2], |
| 6216 | conn_rec->fabric_name[3], |
| 6217 | conn_rec->fabric_name[4], |
| 6218 | conn_rec->fabric_name[5], |
| 6219 | conn_rec->fabric_name[6], |
| 6220 | conn_rec->fabric_name[7], |
| 6221 | conn_rec->switch_name[0], |
| 6222 | conn_rec->switch_name[1], |
| 6223 | conn_rec->switch_name[2], |
| 6224 | conn_rec->switch_name[3], |
| 6225 | conn_rec->switch_name[4], |
| 6226 | conn_rec->switch_name[5], |
| 6227 | conn_rec->switch_name[6], |
| 6228 | conn_rec->switch_name[7]); |
| 6229 | } |
| 6230 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | /** |
| 6234 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6235 | * @phba: Pointer to hba context object. |
| 6236 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6237 | * |
| 6238 | * This function update driver data structure with config |
| 6239 | * parameters read from config region 23. |
| 6240 | */ |
| 6241 | static void |
| 6242 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6243 | uint8_t *buff) |
| 6244 | { |
| 6245 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6246 | struct lpfc_fcoe_params *fcoe_param; |
| 6247 | |
| 6248 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6249 | buff; |
| 6250 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6251 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6252 | |
| 6253 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6254 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6255 | return; |
| 6256 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6257 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6258 | phba->valid_vlan = 1; |
| 6259 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6260 | 0xFFF; |
| 6261 | } |
| 6262 | |
| 6263 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6264 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6265 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6266 | return; |
| 6267 | } |
| 6268 | |
| 6269 | /** |
| 6270 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6271 | * @buff: Buffer containing config region 23 data. |
| 6272 | * @size: Size of the data buffer. |
| 6273 | * @rec_type: Record type to be searched. |
| 6274 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6275 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6276 | * of the record specified by record_type. If record found, this |
| 6277 | * function return pointer to the record else return NULL. |
| 6278 | */ |
| 6279 | static uint8_t * |
| 6280 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6281 | { |
| 6282 | uint32_t offset = 0, rec_length; |
| 6283 | |
| 6284 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6285 | (size < sizeof(uint32_t))) |
| 6286 | return NULL; |
| 6287 | |
| 6288 | rec_length = buff[offset + 1]; |
| 6289 | |
| 6290 | /* |
| 6291 | * One TLV record has one word header and number of data words |
| 6292 | * specified in the rec_length field of the record header. |
| 6293 | */ |
| 6294 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6295 | <= size) { |
| 6296 | if (buff[offset] == rec_type) |
| 6297 | return &buff[offset]; |
| 6298 | |
| 6299 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6300 | return NULL; |
| 6301 | |
| 6302 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6303 | rec_length = buff[offset + 1]; |
| 6304 | } |
| 6305 | return NULL; |
| 6306 | } |
| 6307 | |
| 6308 | /** |
| 6309 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6310 | * @phba: Pointer to lpfc_hba data structure. |
| 6311 | * @buff: Buffer containing config region 23 data. |
| 6312 | * @size: Size of the data buffer. |
| 6313 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6314 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6315 | * populate driver data structure with the parameters. |
| 6316 | */ |
| 6317 | void |
| 6318 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6319 | uint8_t *buff, |
| 6320 | uint32_t size) |
| 6321 | { |
| 6322 | uint32_t offset = 0, rec_length; |
| 6323 | uint8_t *rec_ptr; |
| 6324 | |
| 6325 | /* |
| 6326 | * If data size is less than 2 words signature and version cannot be |
| 6327 | * verified. |
| 6328 | */ |
| 6329 | if (size < 2*sizeof(uint32_t)) |
| 6330 | return; |
| 6331 | |
| 6332 | /* Check the region signature first */ |
| 6333 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6335 | "2567 Config region 23 has bad signature\n"); |
| 6336 | return; |
| 6337 | } |
| 6338 | |
| 6339 | offset += 4; |
| 6340 | |
| 6341 | /* Check the data structure version */ |
| 6342 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6343 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6344 | "2568 Config region 23 has bad version\n"); |
| 6345 | return; |
| 6346 | } |
| 6347 | offset += 4; |
| 6348 | |
| 6349 | rec_length = buff[offset + 1]; |
| 6350 | |
| 6351 | /* Read FCoE param record */ |
| 6352 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6353 | size - offset, FCOE_PARAM_TYPE); |
| 6354 | if (rec_ptr) |
| 6355 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6356 | |
| 6357 | /* Read FCF connection table */ |
| 6358 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6359 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6360 | if (rec_ptr) |
| 6361 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6362 | |
| 6363 | } |