| 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 | d4379ac | 2012-03-01 22:37:07 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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 | |
| 163 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 164 | /* We need to hold the node by incrementing the reference |
| 165 | * count until this queued work is done |
| 166 | */ |
| 167 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 168 | if (evtp->evt_arg1) { |
| 169 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 170 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 171 | lpfc_worker_wake_up(phba); |
| 172 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 173 | spin_unlock_irq(&phba->hbalock); |
| 174 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 178 | /** |
| 179 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler |
| 180 | * @ndlp: Pointer to remote node object. |
| 181 | * |
| 182 | * This function is called from the worker thread when devloss timeout timer |
| 183 | * expires. For SLI4 host, this routine shall return 1 when at lease one |
| 184 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this |
| 185 | * routine shall return 0 when there is no remote node is still in use of FCF |
| 186 | * when devloss timeout happened to this @ndlp. |
| 187 | **/ |
| 188 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 189 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 190 | { |
| 191 | struct lpfc_rport_data *rdata; |
| 192 | struct fc_rport *rport; |
| 193 | struct lpfc_vport *vport; |
| 194 | struct lpfc_hba *phba; |
| 195 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 196 | int put_node; |
| 197 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 198 | int warn_on = 0; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 199 | int fcf_inuse = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 200 | |
| 201 | rport = ndlp->rport; |
| 202 | |
| 203 | if (!rport) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 204 | return fcf_inuse; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 205 | |
| 206 | rdata = rport->dd_data; |
| 207 | name = (uint8_t *) &ndlp->nlp_portname; |
| 208 | vport = ndlp->vport; |
| 209 | phba = vport->phba; |
| 210 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 211 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 212 | fcf_inuse = lpfc_fcf_inuse(phba); |
| 213 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 214 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 215 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 216 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 217 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 218 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 219 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", |
| 220 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); |
| 221 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 222 | /* Don't defer this if we are in the process of deleting the vport |
| 223 | * or unloading the driver. The unload will cleanup the node |
| 224 | * appropriately we just need to cleanup the ndlp rport info here. |
| 225 | */ |
| 226 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 227 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 228 | /* flush the target */ |
| 229 | lpfc_sli_abort_iocb(vport, |
| 230 | &phba->sli.ring[phba->sli.fcp_ring], |
| 231 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 232 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 233 | put_node = rdata->pnode != NULL; |
| 234 | put_rport = ndlp->rport != NULL; |
| 235 | rdata->pnode = NULL; |
| 236 | ndlp->rport = NULL; |
| 237 | if (put_node) |
| 238 | lpfc_nlp_put(ndlp); |
| 239 | if (put_rport) |
| 240 | put_device(&rport->dev); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 241 | return fcf_inuse; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 242 | } |
| 243 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 244 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 245 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 246 | "0284 Devloss timeout Ignored on " |
| 247 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 248 | "NPort x%x\n", |
| 249 | *name, *(name+1), *(name+2), *(name+3), |
| 250 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 251 | ndlp->nlp_DID); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 252 | return fcf_inuse; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 253 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 254 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 255 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 256 | /* We will clean up these Nodes in linkup */ |
| 257 | put_node = rdata->pnode != NULL; |
| 258 | put_rport = ndlp->rport != NULL; |
| 259 | rdata->pnode = NULL; |
| 260 | ndlp->rport = NULL; |
| 261 | if (put_node) |
| 262 | lpfc_nlp_put(ndlp); |
| 263 | if (put_rport) |
| 264 | put_device(&rport->dev); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 265 | return fcf_inuse; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 266 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 267 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 269 | warn_on = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | /* flush the target */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 271 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 272 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 273 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 274 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 275 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 276 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 277 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 278 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 279 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 280 | *name, *(name+1), *(name+2), *(name+3), |
| 281 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 282 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 283 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 284 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 285 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 286 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 287 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 288 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 289 | *name, *(name+1), *(name+2), *(name+3), |
| 290 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 291 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 292 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 293 | } |
| 294 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 295 | put_node = rdata->pnode != NULL; |
| 296 | put_rport = ndlp->rport != NULL; |
| 297 | rdata->pnode = NULL; |
| 298 | ndlp->rport = NULL; |
| 299 | if (put_node) |
| 300 | lpfc_nlp_put(ndlp); |
| 301 | if (put_rport) |
| 302 | put_device(&rport->dev); |
| 303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 304 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 305 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 306 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 307 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 308 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 309 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 310 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 311 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 312 | return fcf_inuse; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler |
| 317 | * @phba: Pointer to hba context object. |
| 318 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. |
| 319 | * @nlp_did: remote node identifer with devloss timeout. |
| 320 | * |
| 321 | * This function is called from the worker thread after invoking devloss |
| 322 | * timeout handler and releasing the reference count for the ndlp with |
| 323 | * which the devloss timeout was handled for SLI4 host. For the devloss |
| 324 | * timeout of the last remote node which had been in use of FCF, when this |
| 325 | * routine is invoked, it shall be guaranteed that none of the remote are |
| 326 | * in-use of FCF. When devloss timeout to the last remote using the FCF, |
| 327 | * if the FIP engine is neither in FCF table scan process nor roundrobin |
| 328 | * failover process, the in-use FCF shall be unregistered. If the FIP |
| 329 | * engine is in FCF discovery process, the devloss timeout state shall |
| 330 | * be set for either the FCF table scan process or roundrobin failover |
| 331 | * process to unregister the in-use FCF. |
| 332 | **/ |
| 333 | static void |
| 334 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, |
| 335 | uint32_t nlp_did) |
| 336 | { |
| 337 | /* If devloss timeout happened to a remote node when FCF had no |
| 338 | * longer been in-use, do nothing. |
| 339 | */ |
| 340 | if (!fcf_inuse) |
| 341 | return; |
| 342 | |
| 343 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { |
| 344 | spin_lock_irq(&phba->hbalock); |
| 345 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 346 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 347 | spin_unlock_irq(&phba->hbalock); |
| 348 | return; |
| 349 | } |
| 350 | phba->hba_flag |= HBA_DEVLOSS_TMO; |
| 351 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 352 | "2847 Last remote node (x%x) using " |
| 353 | "FCF devloss tmo\n", nlp_did); |
| 354 | } |
| 355 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { |
| 356 | spin_unlock_irq(&phba->hbalock); |
| 357 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 358 | "2868 Devloss tmo to FCF rediscovery " |
| 359 | "in progress\n"); |
| 360 | return; |
| 361 | } |
| 362 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { |
| 363 | spin_unlock_irq(&phba->hbalock); |
| 364 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 365 | "2869 Devloss tmo to idle FIP engine, " |
| 366 | "unreg in-use FCF and rescan.\n"); |
| 367 | /* Unregister in-use FCF and rescan */ |
| 368 | lpfc_unregister_fcf_rescan(phba); |
| 369 | return; |
| 370 | } |
| 371 | spin_unlock_irq(&phba->hbalock); |
| 372 | if (phba->hba_flag & FCF_TS_INPROG) |
| 373 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 374 | "2870 FCF table scan in progress\n"); |
| 375 | if (phba->hba_flag & FCF_RR_INPROG) |
| 376 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 377 | "2871 FLOGI roundrobin FCF failover " |
| 378 | "in progress\n"); |
| 379 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 380 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 382 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 384 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 385 | * @phba: Pointer to hba context object. |
| 386 | * |
| 387 | * This function is called from the functions which need to post |
| 388 | * events from interrupt context. This function allocates data |
| 389 | * structure required for posting event. It also keeps track of |
| 390 | * number of events pending and prevent event storm when there are |
| 391 | * too many events. |
| 392 | **/ |
| 393 | struct lpfc_fast_path_event * |
| 394 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 395 | struct lpfc_fast_path_event *ret; |
| 396 | |
| 397 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 398 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 399 | return NULL; |
| 400 | |
| 401 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 402 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 403 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 404 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 405 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 406 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 407 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 412 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 413 | * @phba: Pointer to hba context object. |
| 414 | * @evt: Event object which need to be freed. |
| 415 | * |
| 416 | * This function frees the data structure required for posting |
| 417 | * events. |
| 418 | **/ |
| 419 | void |
| 420 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 421 | struct lpfc_fast_path_event *evt) { |
| 422 | |
| 423 | atomic_dec(&phba->fast_event_count); |
| 424 | kfree(evt); |
| 425 | } |
| 426 | |
| 427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 428 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 429 | * @phba: Pointer to hba context object. |
| 430 | * @evtp: Event data structure. |
| 431 | * |
| 432 | * This function is called from worker thread, when the interrupt |
| 433 | * context need to post an event. This function posts the event |
| 434 | * to fc transport netlink interface. |
| 435 | **/ |
| 436 | static void |
| 437 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 438 | struct lpfc_work_evt *evtp) |
| 439 | { |
| 440 | unsigned long evt_category, evt_sub_category; |
| 441 | struct lpfc_fast_path_event *fast_evt_data; |
| 442 | char *evt_data; |
| 443 | uint32_t evt_data_size; |
| 444 | struct Scsi_Host *shost; |
| 445 | |
| 446 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 447 | work_evt); |
| 448 | |
| 449 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 450 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 451 | fabric_evt.subcategory; |
| 452 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 453 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 454 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 455 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 456 | evt_data_size = sizeof(fast_evt_data->un. |
| 457 | read_check_error); |
| 458 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 459 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 460 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 461 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 462 | } else { |
| 463 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 464 | return; |
| 465 | } |
| 466 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 467 | switch (evt_sub_category) { |
| 468 | case LPFC_EVENT_QFULL: |
| 469 | case LPFC_EVENT_DEVBSY: |
| 470 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 471 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 472 | break; |
| 473 | case LPFC_EVENT_CHECK_COND: |
| 474 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 475 | evt_data_size = sizeof(fast_evt_data->un. |
| 476 | check_cond_evt); |
| 477 | break; |
| 478 | case LPFC_EVENT_VARQUEDEPTH: |
| 479 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 480 | evt_data_size = sizeof(fast_evt_data->un. |
| 481 | queue_depth_evt); |
| 482 | break; |
| 483 | default: |
| 484 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 485 | return; |
| 486 | } |
| 487 | } else { |
| 488 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | fc_host_post_vendor_event(shost, |
| 493 | fc_get_event_number(), |
| 494 | evt_data_size, |
| 495 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 496 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 497 | |
| 498 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 499 | return; |
| 500 | } |
| 501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 503 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | { |
| 505 | struct lpfc_work_evt *evtp = NULL; |
| 506 | struct lpfc_nodelist *ndlp; |
| 507 | int free_evt; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 508 | int fcf_inuse; |
| 509 | uint32_t nlp_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | spin_lock_irq(&phba->hbalock); |
| 512 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 514 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 517 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 519 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 520 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 521 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 522 | /* decrement the node reference count held |
| 523 | * for this queued work |
| 524 | */ |
| 525 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 527 | case LPFC_EVT_DEV_LOSS: |
| 528 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 529 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 530 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 531 | /* decrement the node reference count held for |
| 532 | * this queued work |
| 533 | */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 534 | nlp_did = ndlp->nlp_DID; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 535 | lpfc_nlp_put(ndlp); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 536 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 537 | lpfc_sli4_post_dev_loss_tmo_handler(phba, |
| 538 | fcf_inuse, |
| 539 | nlp_did); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 540 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 542 | if (phba->link_state < LPFC_LINK_DOWN) |
| 543 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 544 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 545 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 546 | complete((struct completion *)(evtp->evt_arg2)); |
| 547 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 548 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 549 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 550 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 551 | *(int *)(evtp->evt_arg1) = 0; |
| 552 | complete((struct completion *)(evtp->evt_arg2)); |
| 553 | break; |
| 554 | case LPFC_EVT_OFFLINE: |
| 555 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 556 | lpfc_sli_brdrestart(phba); |
| 557 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 558 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 559 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 560 | complete((struct completion *)(evtp->evt_arg2)); |
| 561 | break; |
| 562 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 563 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 564 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 565 | lpfc_sli_brdreset(phba); |
| 566 | lpfc_hba_down_post(phba); |
| 567 | *(int *)(evtp->evt_arg1) = |
| 568 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 569 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 570 | complete((struct completion *)(evtp->evt_arg2)); |
| 571 | break; |
| 572 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 573 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 574 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 575 | = (phba->pport->stopped) |
| 576 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 577 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 578 | complete((struct completion *)(evtp->evt_arg2)); |
| 579 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 580 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 581 | lpfc_send_fastpath_evt(phba, evtp); |
| 582 | free_evt = 0; |
| 583 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 584 | case LPFC_EVT_RESET_HBA: |
| 585 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 586 | lpfc_reset_hba(phba); |
| 587 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | } |
| 589 | if (free_evt) |
| 590 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 591 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 593 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | |
| 595 | } |
| 596 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 597 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 598 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | { |
| 600 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 601 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 602 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 603 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 604 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | ha_copy = phba->work_ha; |
| 608 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 609 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 610 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 611 | /* First, try to post the next mailbox command to SLI4 device */ |
| 612 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 613 | lpfc_sli4_post_async_mbox(phba); |
| 614 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 615 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 616 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | lpfc_handle_eratt(phba); |
| 618 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 619 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | lpfc_sli_handle_mb_event(phba); |
| 621 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 622 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 624 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 625 | /* Process SLI4 events */ |
| 626 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 627 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
| 628 | lpfc_handle_rrq_active(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 629 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 630 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 631 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 632 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 633 | if (phba->hba_flag & ASYNC_EVENT) |
| 634 | lpfc_sli4_async_event_proc(phba); |
| 635 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 636 | spin_lock_irq(&phba->hbalock); |
| 637 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 638 | spin_unlock_irq(&phba->hbalock); |
| 639 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 640 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 641 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 642 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 643 | } |
| 644 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 645 | vports = lpfc_create_vport_work_array(phba); |
| 646 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 647 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 648 | /* |
| 649 | * We could have no vports in array if unloading, so if |
| 650 | * this happens then just use the pport |
| 651 | */ |
| 652 | if (vports[i] == NULL && i == 0) |
| 653 | vport = phba->pport; |
| 654 | else |
| 655 | vport = vports[i]; |
| 656 | if (vport == NULL) |
| 657 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 658 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 659 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 660 | vport->work_port_events &= ~work_port_events; |
| 661 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 662 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 663 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 664 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 665 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 666 | if (work_port_events & WORKER_HB_TMO) |
| 667 | lpfc_hb_timeout_handler(phba); |
| 668 | if (work_port_events & WORKER_MBOX_TMO) |
| 669 | lpfc_mbox_timeout_handler(phba); |
| 670 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 671 | lpfc_unblock_fabric_iocbs(phba); |
| 672 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 673 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 674 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 675 | lpfc_ramp_down_queue_handler(phba); |
| 676 | if (work_port_events & WORKER_RAMP_UP_QUEUE) |
| 677 | lpfc_ramp_up_queue_handler(phba); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 678 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
| 679 | lpfc_delayed_disc_timeout_handler(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 680 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 681 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 683 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 684 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 685 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 686 | if ((status & HA_RXMASK) || |
| 687 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 688 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 689 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 690 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 691 | /* Set the lpfc data pending flag */ |
| 692 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 693 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 694 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 695 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 696 | (status & |
| 697 | HA_RXMASK)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 698 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 699 | if ((phba->sli_rev == LPFC_SLI_REV4) & |
| 700 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 701 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 702 | /* |
| 703 | * Turn on Ring interrupts |
| 704 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 705 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 706 | spin_lock_irq(&phba->hbalock); |
| 707 | control = readl(phba->HCregaddr); |
| 708 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 709 | lpfc_debugfs_slow_ring_trc(phba, |
| 710 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 711 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 712 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 713 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 714 | writel(control, phba->HCregaddr); |
| 715 | readl(phba->HCregaddr); /* flush */ |
| 716 | } else { |
| 717 | lpfc_debugfs_slow_ring_trc(phba, |
| 718 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 719 | control, ha_copy, 0); |
| 720 | } |
| 721 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | } |
| 723 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | } |
| 726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | int |
| 728 | lpfc_do_work(void *p) |
| 729 | { |
| 730 | struct lpfc_hba *phba = p; |
| 731 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | |
| 733 | set_user_nice(current, -20); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 734 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 735 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 737 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 738 | /* wait and check worker queue activities */ |
| 739 | rc = wait_event_interruptible(phba->work_waitq, |
| 740 | (test_and_clear_bit(LPFC_DATA_READY, |
| 741 | &phba->data_flags) |
| 742 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 743 | /* Signal wakeup shall terminate the worker thread */ |
| 744 | if (rc) { |
| 745 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 746 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 750 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 753 | phba->worker_thread = NULL; |
| 754 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 755 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | * 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] | 761 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | * embedding it in the IOCB. |
| 763 | */ |
| 764 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 765 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | uint32_t evt) |
| 767 | { |
| 768 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 769 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | |
| 771 | /* |
| 772 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 773 | * be queued to worker thread for processing |
| 774 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 775 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | if (!evtp) |
| 777 | return 0; |
| 778 | |
| 779 | evtp->evt_arg1 = arg1; |
| 780 | evtp->evt_arg2 = arg2; |
| 781 | evtp->evt = evt; |
| 782 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 783 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 784 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 785 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 786 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 787 | lpfc_worker_wake_up(phba); |
| 788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | return 1; |
| 790 | } |
| 791 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 792 | void |
| 793 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 794 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 795 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | struct lpfc_hba *phba = vport->phba; |
| 797 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 798 | int rc; |
| 799 | |
| 800 | 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] | 801 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 802 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 804 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 805 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 806 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 807 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 808 | lpfc_unreg_rpi(vport, ndlp); |
| 809 | |
| 810 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 811 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 812 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | continue; |
| 814 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 815 | remove |
| 816 | ? NLP_EVT_DEVICE_RM |
| 817 | : NLP_EVT_DEVICE_RECOVERY); |
| 818 | } |
| 819 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 820 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 821 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 822 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 823 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 825 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 829 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 830 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 831 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 832 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 833 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 834 | /* Cleanup any outstanding received buffers */ |
| 835 | lpfc_cleanup_rcv_buffers(vport); |
| 836 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | /* Cleanup any outstanding RSCN activity */ |
| 838 | lpfc_els_flush_rscn(vport); |
| 839 | |
| 840 | /* Cleanup any outstanding ELS commands */ |
| 841 | lpfc_els_flush_cmd(vport); |
| 842 | |
| 843 | lpfc_cleanup_rpis(vport, 0); |
| 844 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | /* Turn off discovery timer if its running */ |
| 846 | lpfc_can_disctmo(vport); |
| 847 | } |
| 848 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 849 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 850 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 851 | { |
| 852 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 853 | |
| 854 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 855 | |
| 856 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 857 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 858 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 859 | |
| 860 | lpfc_port_link_failure(vport); |
| 861 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 862 | /* Stop delayed Nport discovery */ |
| 863 | spin_lock_irq(shost->host_lock); |
| 864 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 865 | spin_unlock_irq(shost->host_lock); |
| 866 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 867 | } |
| 868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 870 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 872 | struct lpfc_vport *vport = phba->pport; |
| 873 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 874 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 875 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 876 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 877 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 878 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 879 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 880 | |
| 881 | /* Block all SCSI stack I/Os */ |
| 882 | lpfc_scsi_dev_block(phba); |
| 883 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 885 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 886 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 887 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 888 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 889 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 890 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 891 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 892 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 893 | vports = lpfc_create_vport_work_array(phba); |
| 894 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 895 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 896 | /* Issue a LINK DOWN event to all nodes */ |
| 897 | lpfc_linkdown_port(vports[i]); |
| 898 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 899 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 902 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 903 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 904 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 905 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 906 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 907 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 908 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 912 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 913 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 914 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 916 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 918 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 919 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 920 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 922 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | } |
| 924 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 925 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 926 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 929 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 930 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | } |
| 932 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 933 | static void |
| 934 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 936 | struct lpfc_nodelist *ndlp; |
| 937 | |
| 938 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 939 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 940 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 941 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 942 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 943 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 944 | /* On Linkup its safe to clean up the ndlp |
| 945 | * from Fabric connections. |
| 946 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | if (ndlp->nlp_DID != Fabric_DID) |
| 948 | lpfc_unreg_rpi(vport, ndlp); |
| 949 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 950 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 951 | /* Fail outstanding IO now since device is |
| 952 | * marked for PLOGI. |
| 953 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 954 | lpfc_unreg_rpi(vport, ndlp); |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | static void |
| 960 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 961 | { |
| 962 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | struct lpfc_hba *phba = vport->phba; |
| 964 | |
| 965 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 966 | return; |
| 967 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 968 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 969 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 970 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 972 | /* If NPIV is not enabled, only bring the physical port up */ |
| 973 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 974 | (vport != phba->pport)) |
| 975 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 977 | 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] | 978 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 979 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 981 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 982 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 983 | vport->fc_ns_retry = 0; |
| 984 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 986 | if (vport->fc_flag & FC_LBIT) |
| 987 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static int |
| 992 | lpfc_linkup(struct lpfc_hba *phba) |
| 993 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 994 | struct lpfc_vport **vports; |
| 995 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 997 | lpfc_cleanup_wt_rrqs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 998 | phba->link_state = LPFC_LINK_UP; |
| 999 | |
| 1000 | /* Unblock fabric iocbs if they are blocked */ |
| 1001 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1002 | del_timer_sync(&phba->fabric_block_timer); |
| 1003 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1004 | vports = lpfc_create_vport_work_array(phba); |
| 1005 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1006 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1007 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1008 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1009 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1010 | (phba->sli_rev < LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1011 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | /* |
| 1017 | * This routine handles processing a CLEAR_LA mailbox |
| 1018 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1019 | * as the completion routine when the command is |
| 1020 | * handed off to the SLI layer. |
| 1021 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1022 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1023 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1025 | struct lpfc_vport *vport = pmb->vport; |
| 1026 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1027 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1028 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | uint32_t control; |
| 1030 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1032 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1034 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1035 | |
| 1036 | /* Check for error */ |
| 1037 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1038 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1039 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1040 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1041 | "state x%x\n", |
| 1042 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1043 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1044 | goto out; |
| 1045 | } |
| 1046 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1047 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1048 | phba->link_state = LPFC_HBA_READY; |
| 1049 | |
| 1050 | spin_lock_irq(&phba->hbalock); |
| 1051 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1052 | control = readl(phba->HCregaddr); |
| 1053 | control |= HC_LAINT_ENA; |
| 1054 | writel(control, phba->HCregaddr); |
| 1055 | readl(phba->HCregaddr); /* flush */ |
| 1056 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1057 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1058 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1059 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | out: |
| 1061 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1062 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1063 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1064 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1066 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1067 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1070 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | |
| 1072 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1073 | |
| 1074 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1076 | control = readl(phba->HCregaddr); |
| 1077 | control |= HC_LAINT_ENA; |
| 1078 | writel(control, phba->HCregaddr); |
| 1079 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1080 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | return; |
| 1083 | } |
| 1084 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1085 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1087 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1089 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1091 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1094 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1095 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1096 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1097 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1098 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1099 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1100 | return; |
| 1101 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1102 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1104 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1105 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1107 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1108 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1109 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1110 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1111 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1114 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1115 | */ |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 1116 | if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1117 | lpfc_initial_flogi(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1118 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1119 | |
| 1120 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1121 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1122 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1123 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1124 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1125 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1126 | |
| 1127 | lpfc_linkdown(phba); |
| 1128 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1129 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1130 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1131 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1133 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1137 | /** |
| 1138 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1139 | * @phba pointer to the struct lpfc_hba for this port. |
| 1140 | * This fucnction resets the round robin bit mask and clears the |
| 1141 | * fcf priority list. The list deletions are done while holding the |
| 1142 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1143 | * from the lpfc_fcf_pri record. |
| 1144 | **/ |
| 1145 | void |
| 1146 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1147 | { |
| 1148 | struct lpfc_fcf_pri *fcf_pri; |
| 1149 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1150 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1151 | spin_lock_irq(&phba->hbalock); |
| 1152 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1153 | &phba->fcf.fcf_pri_list, list) { |
| 1154 | list_del_init(&fcf_pri->list); |
| 1155 | fcf_pri->fcf_rec.flag = 0; |
| 1156 | } |
| 1157 | spin_unlock_irq(&phba->hbalock); |
| 1158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1160 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1161 | { |
| 1162 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1163 | |
| 1164 | if (mboxq->u.mb.mbxStatus) { |
| 1165 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1166 | "2017 REG_FCFI mbxStatus error x%x " |
| 1167 | "HBA state x%x\n", |
| 1168 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1169 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1173 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1174 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1175 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1176 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1177 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1178 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1179 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1180 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1181 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1182 | goto fail_out; |
| 1183 | |
| 1184 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1185 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1186 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1187 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1188 | if (vport->port_state != LPFC_FLOGI) { |
| 1189 | phba->hba_flag |= FCF_RR_INPROG; |
| 1190 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1191 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1192 | goto out; |
| 1193 | } |
| 1194 | spin_unlock_irq(&phba->hbalock); |
| 1195 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1196 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1197 | fail_out: |
| 1198 | spin_lock_irq(&phba->hbalock); |
| 1199 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1200 | spin_unlock_irq(&phba->hbalock); |
| 1201 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1202 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /** |
| 1206 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1207 | * @fab_name: pointer to fabric name. |
| 1208 | * @new_fcf_record: pointer to fcf record. |
| 1209 | * |
| 1210 | * This routine compare the fcf record's fabric name with provided |
| 1211 | * fabric name. If the fabric name are identical this function |
| 1212 | * returns 1 else return 0. |
| 1213 | **/ |
| 1214 | static uint32_t |
| 1215 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1216 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1217 | 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] | 1218 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1219 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1220 | return 0; |
| 1221 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1222 | return 0; |
| 1223 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1224 | return 0; |
| 1225 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1226 | return 0; |
| 1227 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1228 | return 0; |
| 1229 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1230 | return 0; |
| 1231 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1232 | return 0; |
| 1233 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1237 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1238 | * @fab_name: pointer to fabric name. |
| 1239 | * @new_fcf_record: pointer to fcf record. |
| 1240 | * |
| 1241 | * This routine compare the fcf record's switch name with provided |
| 1242 | * switch name. If the switch name are identical this function |
| 1243 | * returns 1 else return 0. |
| 1244 | **/ |
| 1245 | static uint32_t |
| 1246 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1247 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1248 | 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] | 1249 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1250 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1251 | return 0; |
| 1252 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1253 | return 0; |
| 1254 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1255 | return 0; |
| 1256 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1257 | return 0; |
| 1258 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1259 | return 0; |
| 1260 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1261 | return 0; |
| 1262 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1263 | return 0; |
| 1264 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1268 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1269 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1270 | * @new_fcf_record: pointer to fcf record. |
| 1271 | * |
| 1272 | * This routine compare the fcf record's mac address with HBA's |
| 1273 | * FCF mac address. If the mac addresses are identical this function |
| 1274 | * returns 1 else return 0. |
| 1275 | **/ |
| 1276 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1277 | 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] | 1278 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1279 | 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] | 1280 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1281 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1282 | return 0; |
| 1283 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1284 | return 0; |
| 1285 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1286 | return 0; |
| 1287 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1288 | return 0; |
| 1289 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1290 | return 0; |
| 1291 | return 1; |
| 1292 | } |
| 1293 | |
| 1294 | static bool |
| 1295 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1296 | { |
| 1297 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1301 | * lpfc_update_fcf_record - Update driver fcf record |
| 1302 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1303 | * @phba: pointer to lpfc hba data structure. |
| 1304 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1305 | * @new_fcf_record: pointer to hba fcf record. |
| 1306 | * |
| 1307 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1308 | * record. This routine is called with the host lock held. |
| 1309 | **/ |
| 1310 | static void |
| 1311 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1312 | struct fcf_record *new_fcf_record |
| 1313 | ) |
| 1314 | { |
| 1315 | struct lpfc_fcf_pri *fcf_pri; |
| 1316 | |
| 1317 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1318 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1319 | /* FCF record priority */ |
| 1320 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1321 | |
| 1322 | } |
| 1323 | |
| 1324 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1325 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1326 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1327 | * @new_fcf_record: pointer to fcf record. |
| 1328 | * |
| 1329 | * This routine copies the FCF information from the FCF |
| 1330 | * record to lpfc_hba data structure. |
| 1331 | **/ |
| 1332 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1333 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1334 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1335 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1336 | /* Fabric name */ |
| 1337 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1338 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1339 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1340 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1341 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1342 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1343 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1344 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1345 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1346 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1347 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1348 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1349 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1350 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1351 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1352 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1353 | /* Mac address */ |
| 1354 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1355 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1356 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1357 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1358 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1359 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1360 | /* FCF record index */ |
| 1361 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1362 | /* FCF record priority */ |
| 1363 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1364 | /* Switch name */ |
| 1365 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1366 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1367 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1368 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1370 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1371 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1372 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1373 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1374 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1375 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1376 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1377 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1378 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1379 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1380 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1384 | * lpfc_update_fcf_record - Update driver fcf record |
| 1385 | * @phba: pointer to lpfc hba data structure. |
| 1386 | * @fcf_rec: pointer to driver fcf record. |
| 1387 | * @new_fcf_record: pointer to hba fcf record. |
| 1388 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1389 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1390 | * @flag: flag bits to be set to the driver fcf record. |
| 1391 | * |
| 1392 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1393 | * together with the address mode, vlan_id, and other informations. This |
| 1394 | * routine is called with the host lock held. |
| 1395 | **/ |
| 1396 | static void |
| 1397 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1398 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1399 | uint16_t vlan_id, uint32_t flag) |
| 1400 | { |
| 1401 | /* Copy the fields from the HBA's FCF record */ |
| 1402 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1403 | /* Update other fields of driver FCF record */ |
| 1404 | fcf_rec->addr_mode = addr_mode; |
| 1405 | fcf_rec->vlan_id = vlan_id; |
| 1406 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1407 | __lpfc_update_fcf_record_pri(phba, |
| 1408 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1409 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1413 | * lpfc_register_fcf - Register the FCF with hba. |
| 1414 | * @phba: pointer to lpfc hba data structure. |
| 1415 | * |
| 1416 | * This routine issues a register fcfi mailbox command to register |
| 1417 | * the fcf with HBA. |
| 1418 | **/ |
| 1419 | static void |
| 1420 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1421 | { |
| 1422 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1423 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1424 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1425 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1426 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1427 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1428 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1429 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | /* The FCF is already registered, start discovery */ |
| 1434 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1435 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1436 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1437 | if (phba->pport->port_state != LPFC_FLOGI) { |
| 1438 | phba->hba_flag |= FCF_RR_INPROG; |
| 1439 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1440 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1444 | return; |
| 1445 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1446 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1447 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1448 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1449 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1450 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1451 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1452 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1453 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1454 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1455 | |
| 1456 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1457 | fcf_mbxq->vport = phba->pport; |
| 1458 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1459 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1460 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1461 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1462 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1463 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1464 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1465 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1466 | |
| 1467 | return; |
| 1468 | } |
| 1469 | |
| 1470 | /** |
| 1471 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1472 | * @phba: pointer to lpfc hba data structure. |
| 1473 | * @new_fcf_record: pointer to fcf record. |
| 1474 | * @boot_flag: Indicates if this record used by boot bios. |
| 1475 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1476 | * @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] | 1477 | * |
| 1478 | * This routine compare the fcf record with connect list obtained from the |
| 1479 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1480 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1481 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1482 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1483 | * used for this FCF when the function returns. |
| 1484 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1485 | * 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] | 1486 | * 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] | 1487 | **/ |
| 1488 | static int |
| 1489 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1490 | struct fcf_record *new_fcf_record, |
| 1491 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1492 | uint16_t *vlan_id) |
| 1493 | { |
| 1494 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1495 | int i, j, fcf_vlan_id = 0; |
| 1496 | |
| 1497 | /* Find the lowest VLAN id in the FCF record */ |
| 1498 | for (i = 0; i < 512; i++) { |
| 1499 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1500 | fcf_vlan_id = i * 8; |
| 1501 | j = 0; |
| 1502 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1503 | j++; |
| 1504 | fcf_vlan_id++; |
| 1505 | } |
| 1506 | break; |
| 1507 | } |
| 1508 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1509 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1510 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1511 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1512 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1513 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1514 | return 0; |
| 1515 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1516 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1517 | *boot_flag = 0; |
| 1518 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1519 | new_fcf_record); |
| 1520 | if (phba->valid_vlan) |
| 1521 | *vlan_id = phba->vlan_id; |
| 1522 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1523 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1524 | return 1; |
| 1525 | } |
| 1526 | |
| 1527 | /* |
| 1528 | * If there are no FCF connection table entry, driver connect to all |
| 1529 | * FCFs. |
| 1530 | */ |
| 1531 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1532 | *boot_flag = 0; |
| 1533 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1534 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1535 | |
| 1536 | /* |
| 1537 | * When there are no FCF connect entries, use driver's default |
| 1538 | * addressing mode - FPMA. |
| 1539 | */ |
| 1540 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1541 | *addr_mode = LPFC_FCF_FPMA; |
| 1542 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1543 | /* If FCF record report a vlan id use that vlan id */ |
| 1544 | if (fcf_vlan_id) |
| 1545 | *vlan_id = fcf_vlan_id; |
| 1546 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1547 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1548 | return 1; |
| 1549 | } |
| 1550 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1551 | list_for_each_entry(conn_entry, |
| 1552 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1553 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1554 | continue; |
| 1555 | |
| 1556 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1557 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1558 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1559 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1560 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1561 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1562 | new_fcf_record)) |
| 1563 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1564 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1565 | /* |
| 1566 | * If the vlan bit map does not have the bit set for the |
| 1567 | * vlan id to be used, then it is not a match. |
| 1568 | */ |
| 1569 | if (!(new_fcf_record->vlan_bitmap |
| 1570 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1571 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1572 | continue; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1576 | * If connection record does not support any addressing mode, |
| 1577 | * skip the FCF record. |
| 1578 | */ |
| 1579 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1580 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1581 | continue; |
| 1582 | |
| 1583 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1584 | * Check if the connection record specifies a required |
| 1585 | * addressing mode. |
| 1586 | */ |
| 1587 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1588 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1589 | |
| 1590 | /* |
| 1591 | * If SPMA required but FCF not support this continue. |
| 1592 | */ |
| 1593 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1594 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1595 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1596 | continue; |
| 1597 | |
| 1598 | /* |
| 1599 | * If FPMA required but FCF not support this continue. |
| 1600 | */ |
| 1601 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1602 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1603 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1604 | continue; |
| 1605 | } |
| 1606 | |
| 1607 | /* |
| 1608 | * This fcf record matches filtering criteria. |
| 1609 | */ |
| 1610 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1611 | *boot_flag = 1; |
| 1612 | else |
| 1613 | *boot_flag = 0; |
| 1614 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1615 | /* |
| 1616 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1617 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1618 | * by FCF, allow fabric to pick the addressing mode. |
| 1619 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1620 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1621 | new_fcf_record); |
| 1622 | /* |
| 1623 | * If the user specified a required address mode, assign that |
| 1624 | * address mode |
| 1625 | */ |
| 1626 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1627 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1628 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1629 | FCFCNCT_AM_SPMA) ? |
| 1630 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1631 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1632 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1633 | * addr mode only if FCF support the addr_mode. |
| 1634 | */ |
| 1635 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1636 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1637 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1638 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1639 | *addr_mode = LPFC_FCF_SPMA; |
| 1640 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1641 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1642 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1643 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1644 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1645 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1646 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1647 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1648 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1649 | /* |
| 1650 | * If no vlan id is specified in connect list, use the vlan id |
| 1651 | * in the FCF record |
| 1652 | */ |
| 1653 | else if (fcf_vlan_id) |
| 1654 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1655 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1656 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1657 | |
| 1658 | return 1; |
| 1659 | } |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1665 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1666 | * @phba: pointer to lpfc hba data structure. |
| 1667 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1668 | * |
| 1669 | * This function check if there is any fcoe event pending while driver |
| 1670 | * scan FCF entries. If there is any pending event, it will restart the |
| 1671 | * FCF saning and return 1 else return 0. |
| 1672 | */ |
| 1673 | int |
| 1674 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1675 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1676 | /* |
| 1677 | * If the Link is up and no FCoE events while in the |
| 1678 | * FCF discovery, no need to restart FCF discovery. |
| 1679 | */ |
| 1680 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1681 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1682 | return 0; |
| 1683 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1684 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1685 | "2768 Pending link or FCF event during current " |
| 1686 | "handling of the previous event: link_state:x%x, " |
| 1687 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1688 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1689 | phba->fcoe_eventtag); |
| 1690 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1691 | spin_lock_irq(&phba->hbalock); |
| 1692 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1693 | spin_unlock_irq(&phba->hbalock); |
| 1694 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1695 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1696 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1697 | "2780 Restart FCF table scan due to " |
| 1698 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1699 | "evt_tag_current:x%x\n", |
| 1700 | phba->fcoe_eventtag_at_fcf_scan, |
| 1701 | phba->fcoe_eventtag); |
| 1702 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1703 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1704 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1705 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1706 | * flag |
| 1707 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1708 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1709 | "2833 Stop FCF discovery process due to link " |
| 1710 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1711 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1712 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1713 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1714 | spin_unlock_irq(&phba->hbalock); |
| 1715 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1716 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1717 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1718 | if (unreg_fcf) { |
| 1719 | spin_lock_irq(&phba->hbalock); |
| 1720 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1721 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1722 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1723 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1724 | return 1; |
| 1725 | } |
| 1726 | |
| 1727 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1728 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1729 | * @phba: pointer to lpfc hba data structure. |
| 1730 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1731 | * |
| 1732 | * This function makes an running random selection decision on FCF record to |
| 1733 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1734 | * probability. To perform integer manunipulation of random numbers with |
| 1735 | * size unit32_t, the lower 16 bits of the 32-bit random number returned |
| 1736 | * from random32() are taken as the random random number generated. |
| 1737 | * |
| 1738 | * Returns true when outcome is for the newly read FCF record should be |
| 1739 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1740 | * chosen FCF record. |
| 1741 | **/ |
| 1742 | static bool |
| 1743 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1744 | { |
| 1745 | uint32_t rand_num; |
| 1746 | |
| 1747 | /* Get 16-bit uniform random number */ |
| 1748 | rand_num = (0xFFFF & random32()); |
| 1749 | |
| 1750 | /* Decision with probability 1/fcf_cnt */ |
| 1751 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1752 | return true; |
| 1753 | else |
| 1754 | return false; |
| 1755 | } |
| 1756 | |
| 1757 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1758 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1759 | * @phba: pointer to lpfc hba data structure. |
| 1760 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1761 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1762 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1763 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1764 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1765 | * SGE parsing, and endianness swapping. |
| 1766 | * |
| 1767 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1768 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1769 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1770 | static struct fcf_record * |
| 1771 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1772 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1773 | { |
| 1774 | void *virt_addr; |
| 1775 | dma_addr_t phys_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1776 | struct lpfc_mbx_sge sge; |
| 1777 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1778 | uint32_t shdr_status, shdr_add_status; |
| 1779 | union lpfc_sli4_cfg_shdr *shdr; |
| 1780 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1781 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1782 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1783 | * routine only uses a single SGE. |
| 1784 | */ |
| 1785 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1786 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1787 | if (unlikely(!mboxq->sge_array)) { |
| 1788 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1789 | "2524 Failed to get the non-embedded SGE " |
| 1790 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1791 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1792 | } |
| 1793 | virt_addr = mboxq->sge_array->addr[0]; |
| 1794 | |
| 1795 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1796 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1797 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1798 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1799 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1800 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1801 | if (shdr_status == STATUS_FCF_TABLE_EMPTY) |
| 1802 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1803 | "2726 READ_FCF_RECORD Indicates empty " |
| 1804 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1805 | else |
| 1806 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1807 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1808 | "with status x%x add_status x%x, " |
| 1809 | "mbx\n", shdr_status, shdr_add_status); |
| 1810 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1811 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1812 | |
| 1813 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1814 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1815 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1816 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1817 | *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] | 1818 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1819 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1820 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1821 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1822 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1823 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1824 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1825 | return new_fcf_record; |
| 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1830 | * @phba: pointer to lpfc hba data structure. |
| 1831 | * @fcf_record: pointer to the fcf record. |
| 1832 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1833 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1834 | * |
| 1835 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1836 | * enabled. |
| 1837 | **/ |
| 1838 | static void |
| 1839 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1840 | struct fcf_record *fcf_record, |
| 1841 | uint16_t vlan_id, |
| 1842 | uint16_t next_fcf_index) |
| 1843 | { |
| 1844 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1845 | "2764 READ_FCF_RECORD:\n" |
| 1846 | "\tFCF_Index : x%x\n" |
| 1847 | "\tFCF_Avail : x%x\n" |
| 1848 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1849 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1850 | "\tFIP_Priority : x%x\n" |
| 1851 | "\tMAC_Provider : x%x\n" |
| 1852 | "\tLowest VLANID : x%x\n" |
| 1853 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1854 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1855 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1856 | "\tNext_FCF_Index: x%x\n", |
| 1857 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1858 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1859 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1860 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1861 | fcf_record->fip_priority, |
| 1862 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1863 | vlan_id, |
| 1864 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1865 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1866 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1867 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1868 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1869 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1870 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1871 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1872 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1873 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1874 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1875 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1876 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1877 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1878 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1879 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1880 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1881 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1882 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1883 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1884 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1885 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1886 | next_fcf_index); |
| 1887 | } |
| 1888 | |
| 1889 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1890 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1891 | * @phba: pointer to lpfc hba data structure. |
| 1892 | * @fcf_rec: pointer to an existing FCF record. |
| 1893 | * @new_fcf_record: pointer to a new FCF record. |
| 1894 | * @new_vlan_id: vlan id from the new FCF record. |
| 1895 | * |
| 1896 | * This function performs matching test of a new FCF record against an existing |
| 1897 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1898 | * will not be used as part of the FCF record matching criteria. |
| 1899 | * |
| 1900 | * Returns true if all the fields matching, otherwise returns false. |
| 1901 | */ |
| 1902 | static bool |
| 1903 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1904 | struct lpfc_fcf_rec *fcf_rec, |
| 1905 | struct fcf_record *new_fcf_record, |
| 1906 | uint16_t new_vlan_id) |
| 1907 | { |
| 1908 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1909 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1910 | return false; |
| 1911 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1912 | return false; |
| 1913 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1914 | return false; |
| 1915 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1916 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1917 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1918 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1919 | return true; |
| 1920 | } |
| 1921 | |
| 1922 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1923 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1924 | * @vport: Pointer to vport object. |
| 1925 | * @fcf_index: index to next fcf. |
| 1926 | * |
| 1927 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1928 | * When this function is invoked, there will be a current fcf registered |
| 1929 | * for flogi. |
| 1930 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1931 | * 1 for stop flogi on currently registered fcf; |
| 1932 | */ |
| 1933 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1934 | { |
| 1935 | struct lpfc_hba *phba = vport->phba; |
| 1936 | int rc; |
| 1937 | |
| 1938 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1939 | spin_lock_irq(&phba->hbalock); |
| 1940 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1941 | spin_unlock_irq(&phba->hbalock); |
| 1942 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1943 | "2872 Devloss tmo with no eligible " |
| 1944 | "FCF, unregister in-use FCF (x%x) " |
| 1945 | "and rescan FCF table\n", |
| 1946 | phba->fcf.current_rec.fcf_indx); |
| 1947 | lpfc_unregister_fcf_rescan(phba); |
| 1948 | goto stop_flogi_current_fcf; |
| 1949 | } |
| 1950 | /* Mark the end to FLOGI roundrobin failover */ |
| 1951 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1952 | /* Allow action to new fcf asynchronous event */ |
| 1953 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1954 | spin_unlock_irq(&phba->hbalock); |
| 1955 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1956 | "2865 No FCF available, stop roundrobin FCF " |
| 1957 | "failover and change port state:x%x/x%x\n", |
| 1958 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1959 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1960 | goto stop_flogi_current_fcf; |
| 1961 | } else { |
| 1962 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1963 | "2794 Try FLOGI roundrobin FCF failover to " |
| 1964 | "(x%x)\n", fcf_index); |
| 1965 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 1966 | if (rc) |
| 1967 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 1968 | "2761 FLOGI roundrobin FCF failover " |
| 1969 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 1970 | rc, phba->fcf.current_rec.fcf_indx); |
| 1971 | else |
| 1972 | goto stop_flogi_current_fcf; |
| 1973 | } |
| 1974 | return 0; |
| 1975 | |
| 1976 | stop_flogi_current_fcf: |
| 1977 | lpfc_can_disctmo(vport); |
| 1978 | return 1; |
| 1979 | } |
| 1980 | |
| 1981 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1982 | * lpfc_sli4_fcf_pri_list_del |
| 1983 | * @phba: pointer to lpfc hba data structure. |
| 1984 | * @fcf_index the index of the fcf record to delete |
| 1985 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 1986 | * If it is one the list then it is removed from the list, and the flag |
| 1987 | * is cleared. This routine grab the hbalock before removing the fcf |
| 1988 | * record from the list. |
| 1989 | **/ |
| 1990 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 1991 | uint16_t fcf_index) |
| 1992 | { |
| 1993 | struct lpfc_fcf_pri *new_fcf_pri; |
| 1994 | |
| 1995 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1996 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1997 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 1998 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 1999 | new_fcf_pri->fcf_rec.flag); |
| 2000 | spin_lock_irq(&phba->hbalock); |
| 2001 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2002 | if (phba->fcf.current_rec.priority == |
| 2003 | new_fcf_pri->fcf_rec.priority) |
| 2004 | phba->fcf.eligible_fcf_cnt--; |
| 2005 | list_del_init(&new_fcf_pri->list); |
| 2006 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2007 | } |
| 2008 | spin_unlock_irq(&phba->hbalock); |
| 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * lpfc_sli4_set_fcf_flogi_fail |
| 2013 | * @phba: pointer to lpfc hba data structure. |
| 2014 | * @fcf_index the index of the fcf record to update |
| 2015 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2016 | * flag so the the round robin slection for the particular priority level |
| 2017 | * will try a different fcf record that does not have this bit set. |
| 2018 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2019 | * adding it to the priority list. |
| 2020 | **/ |
| 2021 | void |
| 2022 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2023 | { |
| 2024 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2025 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2026 | spin_lock_irq(&phba->hbalock); |
| 2027 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2028 | spin_unlock_irq(&phba->hbalock); |
| 2029 | } |
| 2030 | |
| 2031 | /** |
| 2032 | * lpfc_sli4_fcf_pri_list_add |
| 2033 | * @phba: pointer to lpfc hba data structure. |
| 2034 | * @fcf_index the index of the fcf record to add |
| 2035 | * This routine checks the priority of the fcf_index to be added. |
| 2036 | * If it is a lower priority than the current head of the fcf_pri list |
| 2037 | * then it is added to the list in the right order. |
| 2038 | * If it is the same priority as the current head of the list then it |
| 2039 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2040 | * If the fcf_index to be added is of a higher priority than the current |
| 2041 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2042 | * rr_bmask and it is added to the head of the list. |
| 2043 | * returns: |
| 2044 | * 0=success 1=failure |
| 2045 | **/ |
| 2046 | int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, uint16_t fcf_index, |
| 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 " |
| 2271 | "FCF (x%x)\n", |
| 2272 | phba->fcf.current_rec.fcf_indx); |
| 2273 | goto out; |
| 2274 | } else |
| 2275 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2276 | "2863 New FCF (x%x) matches " |
| 2277 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2278 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2279 | new_fcf_record), |
| 2280 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2281 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2282 | /* |
| 2283 | * Read next FCF record from HBA searching for the matching |
| 2284 | * with in-use record only if not during the fast failover |
| 2285 | * period. In case of fast failover period, it shall try to |
| 2286 | * determine whether the FCF record just read should be the |
| 2287 | * next candidate. |
| 2288 | */ |
| 2289 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2290 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2291 | goto read_next_fcf; |
| 2292 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2293 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2294 | /* |
| 2295 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2296 | * period; otherwise, update on current FCF record. |
| 2297 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2298 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2299 | fcf_rec = &phba->fcf.failover_rec; |
| 2300 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2301 | fcf_rec = &phba->fcf.current_rec; |
| 2302 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2303 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2304 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2305 | * If the driver FCF record does not have boot flag |
| 2306 | * set and new hba fcf record has boot flag set, use |
| 2307 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2308 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2309 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2310 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2311 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2312 | "2837 Update current FCF record " |
| 2313 | "(x%x) with new FCF record (x%x)\n", |
| 2314 | fcf_rec->fcf_indx, |
| 2315 | bf_get(lpfc_fcf_record_fcf_index, |
| 2316 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2317 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2318 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2319 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2320 | goto read_next_fcf; |
| 2321 | } |
| 2322 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2323 | * If the driver FCF record has boot flag set and the |
| 2324 | * new hba FCF record does not have boot flag, read |
| 2325 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2326 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2327 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2328 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2329 | goto read_next_fcf; |
| 2330 | } |
| 2331 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2332 | * If the new hba FCF record has lower priority value |
| 2333 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2334 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2335 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2336 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2337 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2338 | "2838 Update current FCF record " |
| 2339 | "(x%x) with new FCF record (x%x)\n", |
| 2340 | fcf_rec->fcf_indx, |
| 2341 | bf_get(lpfc_fcf_record_fcf_index, |
| 2342 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2343 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2344 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2345 | /* Reset running random FCF selection count */ |
| 2346 | phba->fcf.eligible_fcf_cnt = 1; |
| 2347 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2348 | /* Update running random FCF selection count */ |
| 2349 | phba->fcf.eligible_fcf_cnt++; |
| 2350 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2351 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2352 | if (select_new_fcf) { |
| 2353 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2354 | "2839 Update current FCF record " |
| 2355 | "(x%x) with new FCF record (x%x)\n", |
| 2356 | fcf_rec->fcf_indx, |
| 2357 | bf_get(lpfc_fcf_record_fcf_index, |
| 2358 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2359 | /* Choose the new FCF by random selection */ |
| 2360 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2361 | new_fcf_record, |
| 2362 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2363 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2364 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2365 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2366 | goto read_next_fcf; |
| 2367 | } |
| 2368 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2369 | * This is the first suitable FCF record, choose this record for |
| 2370 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2371 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2372 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2373 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2374 | "2840 Update initial FCF candidate " |
| 2375 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2376 | bf_get(lpfc_fcf_record_fcf_index, |
| 2377 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2378 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2379 | addr_mode, vlan_id, (boot_flag ? |
| 2380 | BOOT_ENABLE : 0)); |
| 2381 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2382 | /* Setup initial running random FCF selection count */ |
| 2383 | phba->fcf.eligible_fcf_cnt = 1; |
| 2384 | /* Seeding the random number generator for random selection */ |
| 2385 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
| 2386 | srandom32(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2387 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2388 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2389 | goto read_next_fcf; |
| 2390 | |
| 2391 | read_next_fcf: |
| 2392 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2393 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2394 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2395 | /* |
| 2396 | * Case of FCF fast failover scan |
| 2397 | */ |
| 2398 | |
| 2399 | /* |
| 2400 | * It has not found any suitable FCF record, cancel |
| 2401 | * FCF scan inprogress, and do nothing |
| 2402 | */ |
| 2403 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2404 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2405 | "2782 No suitable FCF found: " |
| 2406 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2407 | phba->fcoe_eventtag_at_fcf_scan, |
| 2408 | bf_get(lpfc_fcf_record_fcf_index, |
| 2409 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2410 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2411 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2412 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2413 | spin_unlock_irq(&phba->hbalock); |
| 2414 | /* Unregister in-use FCF and rescan */ |
| 2415 | lpfc_printf_log(phba, KERN_INFO, |
| 2416 | LOG_FIP, |
| 2417 | "2864 On devloss tmo " |
| 2418 | "unreg in-use FCF and " |
| 2419 | "rescan FCF table\n"); |
| 2420 | lpfc_unregister_fcf_rescan(phba); |
| 2421 | return; |
| 2422 | } |
| 2423 | /* |
| 2424 | * Let next new FCF event trigger fast failover |
| 2425 | */ |
| 2426 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2427 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2428 | return; |
| 2429 | } |
| 2430 | /* |
| 2431 | * It has found a suitable FCF record that is not |
| 2432 | * the same as in-use FCF record, unregister the |
| 2433 | * in-use FCF record, replace the in-use FCF record |
| 2434 | * with the new FCF record, mark FCF fast failover |
| 2435 | * completed, and then start register the new FCF |
| 2436 | * record. |
| 2437 | */ |
| 2438 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2439 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2440 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2441 | |
| 2442 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2443 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2444 | "2842 Replace in-use FCF (x%x) " |
| 2445 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2446 | phba->fcf.current_rec.fcf_indx, |
| 2447 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2448 | memcpy(&phba->fcf.current_rec, |
| 2449 | &phba->fcf.failover_rec, |
| 2450 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2451 | /* |
| 2452 | * Mark the fast FCF failover rediscovery completed |
| 2453 | * and the start of the first round of the roundrobin |
| 2454 | * FCF failover. |
| 2455 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2456 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2457 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2458 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2459 | /* Register to the new FCF record */ |
| 2460 | lpfc_register_fcf(phba); |
| 2461 | } else { |
| 2462 | /* |
| 2463 | * In case of transaction period to fast FCF failover, |
| 2464 | * do nothing when search to the end of the FCF table. |
| 2465 | */ |
| 2466 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2467 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2468 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2469 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2470 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2471 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2472 | /* |
| 2473 | * In case the current in-use FCF record no |
| 2474 | * longer existed during FCF discovery that |
| 2475 | * was not triggered by fast FCF failover |
| 2476 | * process, treat it as fast FCF failover. |
| 2477 | */ |
| 2478 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2479 | "2841 In-use FCF record (x%x) " |
| 2480 | "not reported, entering fast " |
| 2481 | "FCF failover mode scanning.\n", |
| 2482 | phba->fcf.current_rec.fcf_indx); |
| 2483 | spin_lock_irq(&phba->hbalock); |
| 2484 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2485 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2486 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2487 | LPFC_FCOE_FCF_GET_FIRST); |
| 2488 | return; |
| 2489 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2490 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2491 | lpfc_register_fcf(phba); |
| 2492 | } |
| 2493 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2494 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2495 | return; |
| 2496 | |
| 2497 | out: |
| 2498 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2499 | lpfc_register_fcf(phba); |
| 2500 | |
| 2501 | return; |
| 2502 | } |
| 2503 | |
| 2504 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2505 | * 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] | 2506 | * @phba: pointer to lpfc hba data structure. |
| 2507 | * @mboxq: pointer to mailbox object. |
| 2508 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2509 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2510 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2511 | * performing the failover. If the FCF read back is not valid/available, it |
| 2512 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2513 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2514 | * newly read FCF record to the failover FCF record, unregister currently |
| 2515 | * registered FCF record, copy the failover FCF record to the current |
| 2516 | * FCF record, and then register the current FCF record before proceeding |
| 2517 | * to trying FLOGI on the new failover FCF. |
| 2518 | */ |
| 2519 | void |
| 2520 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2521 | { |
| 2522 | struct fcf_record *new_fcf_record; |
| 2523 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2524 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2525 | uint16_t current_fcf_index; |
| 2526 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2527 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2528 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2529 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2530 | if (phba->link_state < LPFC_LINK_UP) { |
| 2531 | spin_lock_irq(&phba->hbalock); |
| 2532 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2533 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2534 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2535 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2539 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2540 | &next_fcf_index); |
| 2541 | if (!new_fcf_record) { |
| 2542 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2543 | "2766 Mailbox command READ_FCF_RECORD " |
| 2544 | "failed to retrieve a FCF record.\n"); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2545 | goto error_out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2549 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2550 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2551 | |
| 2552 | /* Log the FCF record information if turned on */ |
| 2553 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2554 | next_fcf_index); |
| 2555 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2556 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2557 | if (!rc) { |
| 2558 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2559 | "2848 Remove ineligible FCF (x%x) from " |
| 2560 | "from roundrobin bmask\n", fcf_index); |
| 2561 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2562 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2563 | /* Perform next round of roundrobin FCF failover */ |
| 2564 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2565 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2566 | if (rc) |
| 2567 | goto out; |
| 2568 | goto error_out; |
| 2569 | } |
| 2570 | |
| 2571 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2572 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2573 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2574 | "FCF (x%x) back to FCF (x%x)\n", |
| 2575 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2576 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2577 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2578 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2579 | goto out; |
| 2580 | } |
| 2581 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2582 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2583 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2584 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2585 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2586 | spin_lock_irq(&phba->hbalock); |
| 2587 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2588 | new_fcf_record, addr_mode, vlan_id, |
| 2589 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2590 | spin_unlock_irq(&phba->hbalock); |
| 2591 | |
| 2592 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2593 | |
| 2594 | /* Unregister the current in-use FCF record */ |
| 2595 | lpfc_unregister_fcf(phba); |
| 2596 | |
| 2597 | /* Replace in-use record with the new record */ |
| 2598 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2599 | sizeof(struct lpfc_fcf_rec)); |
| 2600 | |
| 2601 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2602 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2603 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2604 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2605 | error_out: |
| 2606 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2607 | out: |
| 2608 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | /** |
| 2612 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2613 | * @phba: pointer to lpfc hba data structure. |
| 2614 | * @mboxq: pointer to mailbox object. |
| 2615 | * |
| 2616 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2617 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2618 | * failover when a new FCF event happened. If the FCF read back is |
| 2619 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2620 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2621 | */ |
| 2622 | void |
| 2623 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2624 | { |
| 2625 | struct fcf_record *new_fcf_record; |
| 2626 | uint32_t boot_flag, addr_mode; |
| 2627 | uint16_t fcf_index, next_fcf_index; |
| 2628 | uint16_t vlan_id; |
| 2629 | int rc; |
| 2630 | |
| 2631 | /* If link state is not up, no need to proceed */ |
| 2632 | if (phba->link_state < LPFC_LINK_UP) |
| 2633 | goto out; |
| 2634 | |
| 2635 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2636 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2637 | goto out; |
| 2638 | |
| 2639 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2640 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2641 | &next_fcf_index); |
| 2642 | if (!new_fcf_record) { |
| 2643 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2644 | "2767 Mailbox command READ_FCF_RECORD " |
| 2645 | "failed to retrieve a FCF record.\n"); |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
| 2649 | /* Check the connection list for eligibility */ |
| 2650 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2651 | &addr_mode, &vlan_id); |
| 2652 | |
| 2653 | /* Log the FCF record information if turned on */ |
| 2654 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2655 | next_fcf_index); |
| 2656 | |
| 2657 | if (!rc) |
| 2658 | goto out; |
| 2659 | |
| 2660 | /* Update the eligible FCF record index bmask */ |
| 2661 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2662 | |
| 2663 | 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] | 2664 | |
| 2665 | out: |
| 2666 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2667 | } |
| 2668 | |
| 2669 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2670 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2671 | * @phba: pointer to lpfc hba data structure. |
| 2672 | * @mboxq: pointer to mailbox data structure. |
| 2673 | * |
| 2674 | * This function handles completion of init vfi mailbox command. |
| 2675 | */ |
| 2676 | void |
| 2677 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2678 | { |
| 2679 | struct lpfc_vport *vport = mboxq->vport; |
| 2680 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2681 | /* |
| 2682 | * VFI not supported on interface type 0, just do the flogi |
| 2683 | * Also continue if the VFI is in use - just use the same one. |
| 2684 | */ |
| 2685 | if (mboxq->u.mb.mbxStatus && |
| 2686 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2687 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2688 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2689 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2690 | LOG_MBOX, |
| 2691 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2692 | mboxq->u.mb.mbxStatus); |
| 2693 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2694 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2695 | return; |
| 2696 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2697 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2698 | lpfc_initial_flogi(vport); |
| 2699 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2700 | return; |
| 2701 | } |
| 2702 | |
| 2703 | /** |
| 2704 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2705 | * @vport: pointer to lpfc_vport data structure. |
| 2706 | * |
| 2707 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2708 | * VPI for the physical port. |
| 2709 | */ |
| 2710 | void |
| 2711 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2712 | { |
| 2713 | LPFC_MBOXQ_t *mboxq; |
| 2714 | int rc; |
| 2715 | struct lpfc_hba *phba = vport->phba; |
| 2716 | |
| 2717 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2718 | if (!mboxq) { |
| 2719 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2720 | LOG_MBOX, "2892 Failed to allocate " |
| 2721 | "init_vfi mailbox\n"); |
| 2722 | return; |
| 2723 | } |
| 2724 | lpfc_init_vfi(mboxq, vport); |
| 2725 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2726 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2727 | if (rc == MBX_NOT_FINISHED) { |
| 2728 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2729 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2730 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2735 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2736 | * @phba: pointer to lpfc hba data structure. |
| 2737 | * @mboxq: pointer to mailbox data structure. |
| 2738 | * |
| 2739 | * This function handles completion of init vpi mailbox command. |
| 2740 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2741 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2742 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2743 | { |
| 2744 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2745 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2746 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2747 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2748 | if (mboxq->u.mb.mbxStatus) { |
| 2749 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2750 | LOG_MBOX, |
| 2751 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2752 | mboxq->u.mb.mbxStatus); |
| 2753 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2754 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2755 | return; |
| 2756 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2757 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2758 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2759 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2760 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2761 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2762 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2763 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2764 | if (!ndlp) |
| 2765 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2766 | LOG_DISCOVERY, |
| 2767 | "2731 Cannot find fabric " |
| 2768 | "controller node\n"); |
| 2769 | else |
| 2770 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2771 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2772 | return; |
| 2773 | } |
| 2774 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2775 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2776 | lpfc_initial_fdisc(vport); |
| 2777 | else { |
| 2778 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2779 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2780 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2781 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2782 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2783 | return; |
| 2784 | } |
| 2785 | |
| 2786 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2787 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2788 | * @vport: pointer to lpfc_vport data structure. |
| 2789 | * |
| 2790 | * This function issue a init_vpi mailbox command to initialize |
| 2791 | * VPI for the vport. |
| 2792 | */ |
| 2793 | void |
| 2794 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2795 | { |
| 2796 | LPFC_MBOXQ_t *mboxq; |
| 2797 | int rc; |
| 2798 | |
| 2799 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2800 | if (!mboxq) { |
| 2801 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2802 | LOG_MBOX, "2607 Failed to allocate " |
| 2803 | "init_vpi mailbox\n"); |
| 2804 | return; |
| 2805 | } |
| 2806 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2807 | mboxq->vport = vport; |
| 2808 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2809 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2810 | if (rc == MBX_NOT_FINISHED) { |
| 2811 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2812 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2813 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2818 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2819 | * @phba: pointer to lpfc hba data structure. |
| 2820 | * |
| 2821 | * This function loops through the list of vports on the @phba and issues an |
| 2822 | * FDISC if possible. |
| 2823 | */ |
| 2824 | void |
| 2825 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2826 | { |
| 2827 | struct lpfc_vport **vports; |
| 2828 | int i; |
| 2829 | |
| 2830 | vports = lpfc_create_vport_work_array(phba); |
| 2831 | if (vports != NULL) { |
| 2832 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2833 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2834 | continue; |
| 2835 | /* There are no vpi for this vport */ |
| 2836 | if (vports[i]->vpi > phba->max_vpi) { |
| 2837 | lpfc_vport_set_state(vports[i], |
| 2838 | FC_VPORT_FAILED); |
| 2839 | continue; |
| 2840 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2841 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2842 | lpfc_vport_set_state(vports[i], |
| 2843 | FC_VPORT_LINKDOWN); |
| 2844 | continue; |
| 2845 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2846 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2847 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2848 | continue; |
| 2849 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2850 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2851 | lpfc_initial_fdisc(vports[i]); |
| 2852 | else { |
| 2853 | lpfc_vport_set_state(vports[i], |
| 2854 | FC_VPORT_NO_FABRIC_SUPP); |
| 2855 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2856 | LOG_ELS, |
| 2857 | "0259 No NPIV " |
| 2858 | "Fabric support\n"); |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | lpfc_destroy_vport_work_array(phba, vports); |
| 2863 | } |
| 2864 | |
| 2865 | void |
| 2866 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2867 | { |
| 2868 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2869 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2870 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2871 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2872 | /* |
| 2873 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2874 | * error (except VFI in use) and continue with the discovery. |
| 2875 | */ |
| 2876 | if (mboxq->u.mb.mbxStatus && |
| 2877 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2878 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2879 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2880 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2881 | "2018 REG_VFI mbxStatus error x%x " |
| 2882 | "HBA state x%x\n", |
| 2883 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2884 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2885 | /* FLOGI failed, use loop map to make discovery list */ |
| 2886 | lpfc_disc_list_loopmap(vport); |
| 2887 | /* Start discovery */ |
| 2888 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2889 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2890 | } |
| 2891 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2892 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2893 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2894 | |
| 2895 | /* If the VFI is already registered, there is nothing else to do */ |
| 2896 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 2897 | goto out_free_mem; |
| 2898 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2899 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2900 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2901 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2902 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2903 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2904 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2905 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2906 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2907 | /* In case SLI4 FC loopback test, we are ready */ |
| 2908 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2909 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2910 | phba->link_state = LPFC_HBA_READY; |
| 2911 | goto out_free_mem; |
| 2912 | } |
| 2913 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2914 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2915 | /* |
| 2916 | * For private loop or for NPort pt2pt, |
| 2917 | * just start discovery and we are done. |
| 2918 | */ |
| 2919 | if ((vport->fc_flag & FC_PT2PT) || |
| 2920 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2921 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2922 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2923 | /* Use loop map to make discovery list */ |
| 2924 | lpfc_disc_list_loopmap(vport); |
| 2925 | /* Start discovery */ |
| 2926 | lpfc_disc_start(vport); |
| 2927 | } else { |
| 2928 | lpfc_start_fdiscs(phba); |
| 2929 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2930 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2931 | } |
| 2932 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2933 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2934 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2935 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2936 | kfree(dmabuf); |
| 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2941 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2943 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2945 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | |
| 2947 | |
| 2948 | /* Check for error */ |
| 2949 | if (mb->mbxStatus) { |
| 2950 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2951 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2952 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2953 | "hba state x%x>\n", |
| 2954 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | goto out; |
| 2957 | } |
| 2958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2959 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2960 | sizeof (struct serv_parm)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 2961 | lpfc_update_vport_wwn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2962 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2963 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2964 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2965 | } |
| 2966 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2968 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | return; |
| 2971 | |
| 2972 | out: |
| 2973 | pmb->context1 = NULL; |
| 2974 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2975 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2976 | lpfc_issue_clear_la(phba, vport); |
| 2977 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | return; |
| 2979 | } |
| 2980 | |
| 2981 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2982 | 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] | 2983 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2984 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2985 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2986 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2987 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2988 | struct lpfc_dmabuf *mp; |
| 2989 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2990 | struct fcf_record *fcf_record; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2991 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2992 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2993 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 2994 | case LPFC_LINK_SPEED_1GHZ: |
| 2995 | case LPFC_LINK_SPEED_2GHZ: |
| 2996 | case LPFC_LINK_SPEED_4GHZ: |
| 2997 | case LPFC_LINK_SPEED_8GHZ: |
| 2998 | case LPFC_LINK_SPEED_10GHZ: |
| 2999 | case LPFC_LINK_SPEED_16GHZ: |
| 3000 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3001 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3002 | default: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3003 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3004 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | } |
| 3006 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3007 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3008 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3010 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3011 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3012 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3014 | /* if npiv is enabled and this adapter supports npiv log |
| 3015 | * a message that npiv is not supported in this topology |
| 3016 | */ |
| 3017 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3018 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3019 | "1309 Link Up Event npiv not supported in loop " |
| 3020 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3021 | /* Get Loop Map information */ |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3022 | if (bf_get(lpfc_mbx_read_top_il, la)) { |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 3023 | spin_lock(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3024 | vport->fc_flag |= FC_LBIT; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 3025 | spin_unlock(shost->host_lock); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3026 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3027 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3028 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3029 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | |
| 3031 | if (i == 0) { |
| 3032 | phba->alpa_map[0] = 0; |
| 3033 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3034 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | int numalpa, j, k; |
| 3036 | union { |
| 3037 | uint8_t pamap[16]; |
| 3038 | struct { |
| 3039 | uint32_t wd1; |
| 3040 | uint32_t wd2; |
| 3041 | uint32_t wd3; |
| 3042 | uint32_t wd4; |
| 3043 | } pa; |
| 3044 | } un; |
| 3045 | numalpa = phba->alpa_map[0]; |
| 3046 | j = 0; |
| 3047 | while (j < numalpa) { |
| 3048 | memset(un.pamap, 0, 16); |
| 3049 | for (k = 1; j < numalpa; k++) { |
| 3050 | un.pamap[k - 1] = |
| 3051 | phba->alpa_map[j + 1]; |
| 3052 | j++; |
| 3053 | if (k == 16) |
| 3054 | break; |
| 3055 | } |
| 3056 | /* Link Up Event ALPA map */ |
| 3057 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3058 | KERN_WARNING, |
| 3059 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3060 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | "ALPA map Data: x%x " |
| 3062 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3063 | un.pa.wd1, un.pa.wd2, |
| 3064 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | } |
| 3066 | } |
| 3067 | } |
| 3068 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3070 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3071 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3072 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3073 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3074 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 3075 | spin_lock(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3076 | vport->fc_flag |= FC_LBIT; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 3077 | spin_unlock(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3079 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | |
| 3081 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3082 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3083 | if (!sparam_mbox) |
| 3084 | goto out; |
| 3085 | |
| 3086 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3087 | if (rc) { |
| 3088 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3089 | goto out; |
| 3090 | } |
| 3091 | sparam_mbox->vport = vport; |
| 3092 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3093 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3094 | if (rc == MBX_NOT_FINISHED) { |
| 3095 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3096 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3097 | kfree(mp); |
| 3098 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3099 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | } |
| 3101 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3102 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3103 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3104 | if (!cfglink_mbox) |
| 3105 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3106 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3109 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3110 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3111 | if (rc == MBX_NOT_FINISHED) { |
| 3112 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3113 | goto out; |
| 3114 | } |
| 3115 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3116 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3117 | /* |
| 3118 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3119 | * is phase 1 implementation that support FCF index 0 and driver |
| 3120 | * defaults. |
| 3121 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3122 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3123 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3124 | GFP_KERNEL); |
| 3125 | if (unlikely(!fcf_record)) { |
| 3126 | lpfc_printf_log(phba, KERN_ERR, |
| 3127 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3128 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3129 | "fcf record\n"); |
| 3130 | rc = -ENODEV; |
| 3131 | goto out; |
| 3132 | } |
| 3133 | |
| 3134 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3135 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3136 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3137 | if (unlikely(rc)) { |
| 3138 | lpfc_printf_log(phba, KERN_ERR, |
| 3139 | LOG_MBOX | LOG_SLI, |
| 3140 | "2013 Could not manually add FCF " |
| 3141 | "record 0, status %d\n", rc); |
| 3142 | rc = -ENODEV; |
| 3143 | kfree(fcf_record); |
| 3144 | goto out; |
| 3145 | } |
| 3146 | kfree(fcf_record); |
| 3147 | } |
| 3148 | /* |
| 3149 | * The driver is expected to do FIP/FCF. Call the port |
| 3150 | * and get the FCF Table. |
| 3151 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3152 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3153 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3154 | spin_unlock_irq(&phba->hbalock); |
| 3155 | return; |
| 3156 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3157 | /* This is the initial FCF discovery scan */ |
| 3158 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3159 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3160 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3161 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3162 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3163 | LPFC_FCOE_FCF_GET_FIRST); |
| 3164 | if (rc) { |
| 3165 | spin_lock_irq(&phba->hbalock); |
| 3166 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3167 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3168 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3169 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3170 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3171 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3173 | |
| 3174 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3175 | out: |
| 3176 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3177 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3178 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3179 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3180 | lpfc_issue_clear_la(phba, vport); |
| 3181 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3185 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3186 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | uint32_t control; |
| 3188 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3189 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3191 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3192 | control = readl(phba->HCregaddr); |
| 3193 | control |= HC_LAINT_ENA; |
| 3194 | writel(control, phba->HCregaddr); |
| 3195 | readl(phba->HCregaddr); /* flush */ |
| 3196 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3197 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | } |
| 3199 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3200 | static void |
| 3201 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3202 | { |
| 3203 | lpfc_linkdown(phba); |
| 3204 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3205 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3206 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3207 | } |
| 3208 | |
| 3209 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3210 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3211 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3213 | * as the completion routine when the command is |
| 3214 | * handed off to the SLI layer. |
| 3215 | */ |
| 3216 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3217 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3219 | struct lpfc_vport *vport = pmb->vport; |
| 3220 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3221 | struct lpfc_mbx_read_top *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3222 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3224 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3225 | /* Unblock ELS traffic */ |
| 3226 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | /* Check for error */ |
| 3228 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3229 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3230 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3231 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3233 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3234 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | } |
| 3236 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3237 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3238 | |
| 3239 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3240 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3241 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3242 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3243 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3244 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3246 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3247 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 3248 | if ((phba->fc_eventTag < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3249 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3251 | if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | if (phba->fc_eventTag != 0) |
| 3253 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3254 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | |
| 3256 | phba->fc_eventTag = la->eventTag; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3257 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3258 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3259 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3260 | else |
| 3261 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3262 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3263 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3264 | phba->link_events++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3265 | if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) && |
| 3266 | (!bf_get(lpfc_mbx_read_top_mm, la))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3268 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3269 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3270 | "1306 Link Up Event in loop back mode " |
| 3271 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3272 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3273 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3274 | la), |
| 3275 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3276 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3277 | } else { |
| 3278 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3279 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3280 | "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] | 3281 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3282 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3283 | la), |
| 3284 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3285 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3286 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3287 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3288 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3289 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3290 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3291 | } else if (bf_get(lpfc_mbx_read_top_att_type, la) == |
| 3292 | LPFC_ATT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3294 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3295 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3296 | "1308 Link Down Event in loop back mode " |
| 3297 | "x%x received " |
| 3298 | "Data: x%x x%x x%x\n", |
| 3299 | la->eventTag, phba->fc_eventTag, |
| 3300 | phba->pport->port_state, vport->fc_flag); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3301 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3302 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3303 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3304 | "Data: x%x x%x x%x x%x x%x\n", |
| 3305 | la->eventTag, phba->fc_eventTag, |
| 3306 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3307 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3308 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3309 | lpfc_mbx_issue_link_down(phba); |
| 3310 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3311 | if ((bf_get(lpfc_mbx_read_top_mm, la)) && |
| 3312 | (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] | 3313 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3314 | phba->fc_stat.LinkDown++; |
| 3315 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3316 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3318 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3319 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3320 | lpfc_mbx_issue_link_down(phba); |
| 3321 | } else |
| 3322 | lpfc_enable_la(phba); |
| 3323 | |
| 3324 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3325 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3326 | "Data: x%x x%x x%x\n", |
| 3327 | la->eventTag, phba->fc_eventTag, |
| 3328 | phba->pport->port_state, vport->fc_flag); |
| 3329 | /* |
| 3330 | * The cmnd that triggered this will be waiting for this |
| 3331 | * signal. |
| 3332 | */ |
| 3333 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3334 | if (phba->wait_4_mlo_maint_flg) { |
| 3335 | phba->wait_4_mlo_maint_flg = 0; |
| 3336 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3337 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3338 | } |
| 3339 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3340 | if (bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3341 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3342 | lpfc_issue_clear_la(phba, vport); |
| 3343 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3344 | "1311 fa %d\n", |
| 3345 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | } |
| 3347 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3348 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3350 | kfree(mp); |
| 3351 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3352 | return; |
| 3353 | } |
| 3354 | |
| 3355 | /* |
| 3356 | * This routine handles processing a REG_LOGIN mailbox |
| 3357 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3358 | * as the completion routine when the command is |
| 3359 | * handed off to the SLI layer. |
| 3360 | */ |
| 3361 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3365 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3366 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3370 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3372 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3373 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3374 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3375 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3376 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3377 | /* We rcvd a rscn after issuing this |
| 3378 | * mbox reg login, we may have cycled |
| 3379 | * back through the state and be |
| 3380 | * back at reg login state so this |
| 3381 | * mbox needs to be ignored becase |
| 3382 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3383 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3384 | */ |
| 3385 | spin_lock_irq(shost->host_lock); |
| 3386 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3387 | spin_unlock_irq(shost->host_lock); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3388 | } else |
| 3389 | /* Good status, call state machine */ |
| 3390 | lpfc_disc_state_machine(vport, ndlp, pmb, |
| 3391 | NLP_EVT_CMPL_REG_LOGIN); |
| 3392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3394 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3395 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3396 | /* decrement the node reference count held for this callback |
| 3397 | * function. |
| 3398 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3399 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | |
| 3401 | return; |
| 3402 | } |
| 3403 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3404 | static void |
| 3405 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3406 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3407 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3408 | struct lpfc_vport *vport = pmb->vport; |
| 3409 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3410 | |
| 3411 | switch (mb->mbxStatus) { |
| 3412 | case 0x0011: |
| 3413 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3414 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3415 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3416 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3417 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3418 | /* If VPI is busy, reset the HBA */ |
| 3419 | case 0x9700: |
| 3420 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3421 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3422 | vport->vpi, mb->mbxStatus); |
| 3423 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3424 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3425 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3426 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3427 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3428 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3429 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3430 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3431 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3432 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3433 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3434 | /* |
| 3435 | * This shost reference might have been taken at the beginning of |
| 3436 | * lpfc_vport_delete() |
| 3437 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3438 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3439 | scsi_host_put(shost); |
| 3440 | } |
| 3441 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3442 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3443 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3444 | { |
| 3445 | struct lpfc_hba *phba = vport->phba; |
| 3446 | LPFC_MBOXQ_t *mbox; |
| 3447 | int rc; |
| 3448 | |
| 3449 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3450 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3451 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3452 | |
| 3453 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3454 | mbox->vport = vport; |
| 3455 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3456 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3457 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3458 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3459 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3460 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3461 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3462 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3463 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3464 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | static void |
| 3468 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3469 | { |
| 3470 | struct lpfc_vport *vport = pmb->vport; |
| 3471 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3472 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3473 | |
| 3474 | switch (mb->mbxStatus) { |
| 3475 | case 0x0011: |
| 3476 | case 0x9601: |
| 3477 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3478 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3479 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3480 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3481 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3482 | spin_lock_irq(shost->host_lock); |
| 3483 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3484 | spin_unlock_irq(shost->host_lock); |
| 3485 | vport->fc_myDID = 0; |
| 3486 | goto out; |
| 3487 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3488 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3489 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3490 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3491 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3492 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3493 | vport->num_disc_nodes = 0; |
| 3494 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3495 | if (vport->fc_npr_cnt) |
| 3496 | lpfc_els_disc_plogi(vport); |
| 3497 | |
| 3498 | if (!vport->num_disc_nodes) { |
| 3499 | spin_lock_irq(shost->host_lock); |
| 3500 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3501 | spin_unlock_irq(shost->host_lock); |
| 3502 | lpfc_can_disctmo(vport); |
| 3503 | } |
| 3504 | vport->port_state = LPFC_VPORT_READY; |
| 3505 | |
| 3506 | out: |
| 3507 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3508 | return; |
| 3509 | } |
| 3510 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3511 | /** |
| 3512 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3513 | * @phba: pointer to lpfc hba data structure. |
| 3514 | * |
| 3515 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3516 | * the list of static vports to be created. The function create vports |
| 3517 | * based on the information returned from the HBA. |
| 3518 | **/ |
| 3519 | void |
| 3520 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3521 | { |
| 3522 | LPFC_MBOXQ_t *pmb = NULL; |
| 3523 | MAILBOX_t *mb; |
| 3524 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3525 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3526 | struct fc_vport_identifiers vport_id; |
| 3527 | struct fc_vport *new_fc_vport; |
| 3528 | struct Scsi_Host *shost; |
| 3529 | struct lpfc_vport *vport; |
| 3530 | uint16_t offset = 0; |
| 3531 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3532 | struct lpfc_dmabuf *mp; |
| 3533 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3534 | |
| 3535 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3536 | if (!pmb) { |
| 3537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3538 | "0542 lpfc_create_static_vport failed to" |
| 3539 | " allocate mailbox memory\n"); |
| 3540 | return; |
| 3541 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3542 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3543 | mb = &pmb->u.mb; |
| 3544 | |
| 3545 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3546 | if (!vport_info) { |
| 3547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3548 | "0543 lpfc_create_static_vport failed to" |
| 3549 | " allocate vport_info\n"); |
| 3550 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3551 | return; |
| 3552 | } |
| 3553 | |
| 3554 | vport_buff = (uint8_t *) vport_info; |
| 3555 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3556 | /* free dma buffer from previous round */ |
| 3557 | if (pmb->context1) { |
| 3558 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3559 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3560 | kfree(mp); |
| 3561 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3562 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3563 | goto out; |
| 3564 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3565 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3566 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3567 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3568 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3569 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3570 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3571 | "0544 lpfc_create_static_vport failed to" |
| 3572 | " issue dump mailbox command ret 0x%x " |
| 3573 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3574 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3575 | goto out; |
| 3576 | } |
| 3577 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3578 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3579 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3580 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3581 | if (byte_count > sizeof(struct static_vport_info) - |
| 3582 | offset) |
| 3583 | byte_count = sizeof(struct static_vport_info) |
| 3584 | - offset; |
| 3585 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3586 | offset += byte_count; |
| 3587 | } else { |
| 3588 | if (mb->un.varDmp.word_cnt > |
| 3589 | sizeof(struct static_vport_info) - offset) |
| 3590 | mb->un.varDmp.word_cnt = |
| 3591 | sizeof(struct static_vport_info) |
| 3592 | - offset; |
| 3593 | byte_count = mb->un.varDmp.word_cnt; |
| 3594 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3595 | vport_buff + offset, |
| 3596 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3597 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3598 | offset += byte_count; |
| 3599 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3600 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3601 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3602 | offset < sizeof(struct static_vport_info)); |
| 3603 | |
| 3604 | |
| 3605 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3606 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3607 | != VPORT_INFO_REV)) { |
| 3608 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3609 | "0545 lpfc_create_static_vport bad" |
| 3610 | " information header 0x%x 0x%x\n", |
| 3611 | le32_to_cpu(vport_info->signature), |
| 3612 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3613 | |
| 3614 | goto out; |
| 3615 | } |
| 3616 | |
| 3617 | shost = lpfc_shost_from_vport(phba->pport); |
| 3618 | |
| 3619 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3620 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3621 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3622 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3623 | if (!vport_id.port_name || !vport_id.node_name) |
| 3624 | continue; |
| 3625 | |
| 3626 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3627 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3628 | vport_id.disable = false; |
| 3629 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3630 | |
| 3631 | if (!new_fc_vport) { |
| 3632 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3633 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3634 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3635 | continue; |
| 3636 | } |
| 3637 | |
| 3638 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3639 | vport->vport_flag |= STATIC_VPORT; |
| 3640 | } |
| 3641 | |
| 3642 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3643 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3644 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3645 | if (pmb->context1) { |
| 3646 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3647 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3648 | kfree(mp); |
| 3649 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3650 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3651 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3652 | |
| 3653 | return; |
| 3654 | } |
| 3655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | /* |
| 3657 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3658 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3659 | * as the completion routine when the command is |
| 3660 | * handed off to the SLI layer. |
| 3661 | */ |
| 3662 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3665 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3666 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3667 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3668 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3669 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3671 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3672 | pmb->context1 = NULL; |
| 3673 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3674 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3676 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3677 | "0258 Register Fabric login error: 0x%x\n", |
| 3678 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3680 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3681 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3683 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3684 | /* FLOGI failed, use loop map to make discovery list */ |
| 3685 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3687 | /* Start discovery */ |
| 3688 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3689 | /* Decrement the reference count to ndlp after the |
| 3690 | * reference to the ndlp are done. |
| 3691 | */ |
| 3692 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3693 | return; |
| 3694 | } |
| 3695 | |
| 3696 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3697 | /* Decrement the reference count to ndlp after the reference |
| 3698 | * to the ndlp are done. |
| 3699 | */ |
| 3700 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | return; |
| 3702 | } |
| 3703 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3704 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3705 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3706 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3707 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3708 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3710 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3711 | /* when physical port receive logo donot start |
| 3712 | * vport discovery */ |
| 3713 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3714 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3715 | else { |
| 3716 | shost = lpfc_shost_from_vport(vport); |
| 3717 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3718 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3719 | spin_unlock_irq(shost->host_lock); |
| 3720 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3721 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3725 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3726 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3727 | |
| 3728 | /* Drop the reference count from the mbox at the end after |
| 3729 | * all the current reference to the ndlp have been done. |
| 3730 | */ |
| 3731 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | return; |
| 3733 | } |
| 3734 | |
| 3735 | /* |
| 3736 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3737 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3738 | * as the completion routine when the command is |
| 3739 | * handed off to the SLI layer. |
| 3740 | */ |
| 3741 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3742 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3744 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3745 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3746 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3747 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3749 | pmb->context1 = NULL; |
| 3750 | pmb->context2 = NULL; |
| 3751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3753 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3754 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3755 | "0260 Register NameServer error: 0x%x\n", |
| 3756 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3757 | /* decrement the node reference count held for this |
| 3758 | * callback function. |
| 3759 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3760 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3762 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3763 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3764 | |
| 3765 | /* If no other thread is using the ndlp, free it */ |
| 3766 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3768 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3769 | /* |
| 3770 | * RegLogin failed, use loop map to make discovery |
| 3771 | * list |
| 3772 | */ |
| 3773 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3775 | /* Start discovery */ |
| 3776 | lpfc_disc_start(vport); |
| 3777 | return; |
| 3778 | } |
| 3779 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | return; |
| 3781 | } |
| 3782 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3783 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3784 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3785 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3787 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3789 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3790 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3791 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3792 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3793 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3794 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3795 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3796 | |
| 3797 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3798 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | } |
| 3800 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3803 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3805 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | } |
| 3807 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3808 | /* decrement the node reference count held for this |
| 3809 | * callback function. |
| 3810 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3811 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3813 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3814 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | |
| 3816 | return; |
| 3817 | } |
| 3818 | |
| 3819 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3820 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3822 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3823 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | struct lpfc_rport_data *rdata; |
| 3825 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3826 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | |
| 3828 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3829 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3830 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | rport_ids.port_id = ndlp->nlp_DID; |
| 3832 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3834 | /* |
| 3835 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3836 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3837 | * rport->dd_data points. So, if we're reusing a previously |
| 3838 | * registered port, drop the reference that we took the last time we |
| 3839 | * registered the port. |
| 3840 | */ |
| 3841 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3842 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3843 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3844 | |
| 3845 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3846 | "rport add: did:x%x flg:x%x type x%x", |
| 3847 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3848 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 3849 | /* Don't add the remote port if unloading. */ |
| 3850 | if (vport->load_flag & FC_UNLOADING) |
| 3851 | return; |
| 3852 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3853 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3854 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3855 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3856 | "Warning: fc_remote_port_add failed\n"); |
| 3857 | return; |
| 3858 | } |
| 3859 | |
| 3860 | /* initialize static port data */ |
| 3861 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3862 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3864 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3865 | |
| 3866 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3867 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3868 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3869 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3870 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3871 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3872 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3873 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3874 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3875 | "3183 rport register x%06x, rport %p role x%x\n", |
| 3876 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 3877 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3878 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3879 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3880 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3881 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3882 | return; |
| 3883 | } |
| 3884 | |
| 3885 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3887 | { |
| 3888 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3889 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3890 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3891 | "rport delete: did:x%x flg:x%x type x%x", |
| 3892 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3893 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3894 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3895 | "3184 rport unregister x%06x, rport %p\n", |
| 3896 | ndlp->nlp_DID, rport); |
| 3897 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3898 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | |
| 3900 | return; |
| 3901 | } |
| 3902 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3903 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3904 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3905 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3906 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3907 | |
| 3908 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3909 | switch (state) { |
| 3910 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3911 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3912 | break; |
| 3913 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3914 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3915 | break; |
| 3916 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3918 | break; |
| 3919 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3920 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3921 | break; |
| 3922 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3923 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3924 | break; |
| 3925 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3926 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3927 | break; |
| 3928 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3929 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3930 | break; |
| 3931 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3933 | break; |
| 3934 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3936 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3937 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3938 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3939 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3940 | int old_state, int new_state) |
| 3941 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3942 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3943 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3944 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3945 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3946 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3947 | } |
| 3948 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3949 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3950 | if (new_state == NLP_STE_NPR_NODE) |
| 3951 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3953 | /* Transport interface */ |
| 3954 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 3955 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3956 | vport->phba->nport_event_cnt++; |
| 3957 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3958 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3959 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3960 | if (new_state == NLP_STE_MAPPED_NODE || |
| 3961 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3962 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3963 | /* |
| 3964 | * Tell the fc transport about the port, if we haven't |
| 3965 | * already. If we have, and it's a scsi entity, be |
| 3966 | * sure to unblock any attached scsi devices |
| 3967 | */ |
| 3968 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3969 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3970 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 3971 | (vport->stat_data_enabled)) { |
| 3972 | /* |
| 3973 | * A new target is discovered, if there is no buffer for |
| 3974 | * statistical data collection allocate buffer. |
| 3975 | */ |
| 3976 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 3977 | sizeof(struct lpfc_scsicmd_bkt), |
| 3978 | GFP_KERNEL); |
| 3979 | |
| 3980 | if (!ndlp->lat_data) |
| 3981 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3982 | "0286 lpfc_nlp_state_cleanup failed to " |
| 3983 | "allocate statistical data buffer DID " |
| 3984 | "0x%x\n", ndlp->nlp_DID); |
| 3985 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3986 | /* |
| 3987 | * if we added to Mapped list, but the remote port |
| 3988 | * registration failed or assigned a target id outside |
| 3989 | * our presentable range - move the node to the |
| 3990 | * Unmapped List |
| 3991 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3992 | if (new_state == NLP_STE_MAPPED_NODE && |
| 3993 | (!ndlp->rport || |
| 3994 | ndlp->rport->scsi_target_id == -1 || |
| 3995 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3996 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3997 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3998 | spin_unlock_irq(shost->host_lock); |
| 3999 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4001 | } |
| 4002 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4003 | static char * |
| 4004 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4005 | { |
| 4006 | static char *states[] = { |
| 4007 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4008 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4009 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4010 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4011 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4012 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4013 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4014 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4015 | [NLP_STE_NPR_NODE] = "NPR", |
| 4016 | }; |
| 4017 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4018 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4019 | strlcpy(buffer, states[state], size); |
| 4020 | else |
| 4021 | snprintf(buffer, size, "unknown (%d)", state); |
| 4022 | return buffer; |
| 4023 | } |
| 4024 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4025 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4026 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4027 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4028 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4029 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4030 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4031 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4032 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4033 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4034 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4035 | ndlp->nlp_DID, |
| 4036 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4037 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4038 | |
| 4039 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4040 | "node statechg did:x%x old:%d ste:%d", |
| 4041 | ndlp->nlp_DID, old_state, state); |
| 4042 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4043 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4044 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4045 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4046 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4047 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4048 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4049 | } |
| 4050 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4051 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4052 | spin_lock_irq(shost->host_lock); |
| 4053 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4054 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4055 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4056 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4057 | |
| 4058 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4059 | lpfc_nlp_counters(vport, state, 1); |
| 4060 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4064 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4065 | { |
| 4066 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4067 | |
| 4068 | if (list_empty(&ndlp->nlp_listp)) { |
| 4069 | spin_lock_irq(shost->host_lock); |
| 4070 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4071 | spin_unlock_irq(shost->host_lock); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4076 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
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); |
| 4079 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4080 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4081 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4082 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4083 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4084 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4085 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4086 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4087 | NLP_STE_UNUSED_NODE); |
| 4088 | } |
| 4089 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4090 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4091 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4092 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4093 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4094 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4095 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4096 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4097 | NLP_STE_UNUSED_NODE); |
| 4098 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4100 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4101 | * @vport: Pointer to Virtual Port object. |
| 4102 | * @ndlp: Pointer to FC node object. |
| 4103 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4104 | * |
| 4105 | * This function is always called when node object need to be initialized. |
| 4106 | * It initializes all the fields of the node object. Although the reference |
| 4107 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4108 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4109 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4110 | * the final release of ndlp is determined by its reference count. And, the |
| 4111 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4112 | **/ |
| 4113 | static inline void |
| 4114 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4115 | uint32_t did) |
| 4116 | { |
| 4117 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4118 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 4119 | init_timer(&ndlp->nlp_delayfunc); |
| 4120 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 4121 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 4122 | ndlp->nlp_DID = did; |
| 4123 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4124 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4125 | ndlp->nlp_sid = NLP_NO_SID; |
| 4126 | kref_init(&ndlp->kref); |
| 4127 | NLP_INT_NODE_ACT(ndlp); |
| 4128 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4129 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4130 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4131 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4132 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4133 | |
| 4134 | struct lpfc_nodelist * |
| 4135 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4136 | int state) |
| 4137 | { |
| 4138 | struct lpfc_hba *phba = vport->phba; |
| 4139 | uint32_t did; |
| 4140 | unsigned long flags; |
| 4141 | |
| 4142 | if (!ndlp) |
| 4143 | return NULL; |
| 4144 | |
| 4145 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4146 | /* The ndlp should not be in memory free mode */ |
| 4147 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4148 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4149 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4150 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4151 | "usgmap:x%x refcnt:%d\n", |
| 4152 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4153 | atomic_read(&ndlp->kref.refcount)); |
| 4154 | return NULL; |
| 4155 | } |
| 4156 | /* The ndlp should not already be in active mode */ |
| 4157 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4158 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4159 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4160 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4161 | "usgmap:x%x refcnt:%d\n", |
| 4162 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4163 | atomic_read(&ndlp->kref.refcount)); |
| 4164 | return NULL; |
| 4165 | } |
| 4166 | |
| 4167 | /* Keep the original DID */ |
| 4168 | did = ndlp->nlp_DID; |
| 4169 | |
| 4170 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4171 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4172 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4173 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4174 | |
| 4175 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4176 | |
| 4177 | if (state != NLP_STE_UNUSED_NODE) |
| 4178 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4179 | |
| 4180 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4181 | "node enable: did:x%x", |
| 4182 | ndlp->nlp_DID, 0, 0); |
| 4183 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4187 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4188 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4189 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4190 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4191 | * 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] | 4192 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4193 | * until ALL other outstanding threads have completed. We check |
| 4194 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4195 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4196 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4197 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4198 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4199 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4200 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4201 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4202 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | /* |
| 4206 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4207 | */ |
| 4208 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4209 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4212 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | uint32_t tmo; |
| 4214 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4215 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4216 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4217 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4218 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4219 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4220 | * FC spec states we need 3 * ratov for CT requests |
| 4221 | */ |
| 4222 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4223 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4224 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4225 | |
| 4226 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4227 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4228 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4229 | tmo, vport->port_state, vport->fc_flag); |
| 4230 | } |
| 4231 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4232 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 4233 | spin_lock_irq(shost->host_lock); |
| 4234 | vport->fc_flag |= FC_DISC_TMO; |
| 4235 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | |
| 4237 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4239 | "0247 Start Discovery Timer state x%x " |
| 4240 | "Data: x%x x%lx x%x x%x\n", |
| 4241 | vport->port_state, tmo, |
| 4242 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4243 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | |
| 4245 | return; |
| 4246 | } |
| 4247 | |
| 4248 | /* |
| 4249 | * Cancel rescue timer for Discovery / RSCN handling |
| 4250 | */ |
| 4251 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4252 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | unsigned long iflags; |
| 4256 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4257 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4258 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4259 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4262 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4263 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4264 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4265 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4266 | del_timer_sync(&vport->fc_disctmo); |
| 4267 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4268 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4269 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4273 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4274 | "0248 Cancel Discovery Timer state x%x " |
| 4275 | "Data: x%x x%x x%x\n", |
| 4276 | vport->port_state, vport->fc_flag, |
| 4277 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4278 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | /* |
| 4282 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4283 | * Return true if iocb matches the specified nport |
| 4284 | */ |
| 4285 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4286 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4287 | struct lpfc_sli_ring *pring, |
| 4288 | struct lpfc_iocbq *iocb, |
| 4289 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4290 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | struct lpfc_sli *psli = &phba->sli; |
| 4292 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4293 | struct lpfc_vport *vport = ndlp->vport; |
| 4294 | |
| 4295 | if (iocb->vport != vport) |
| 4296 | return 0; |
| 4297 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | if (pring->ringno == LPFC_ELS_RING) { |
| 4299 | switch (icmd->ulpCommand) { |
| 4300 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4301 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4302 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4304 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4305 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | case CMD_XMIT_ELS_RSP64_CX: |
| 4307 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4308 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4310 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | |
| 4312 | } else if (pring->ringno == psli->fcp_ring) { |
| 4313 | /* Skip match check if waiting to relogin to FCP target */ |
| 4314 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4315 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4316 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | } |
| 4318 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4319 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | } |
| 4321 | } else if (pring->ringno == psli->next_ring) { |
| 4322 | |
| 4323 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4324 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | /* |
| 4328 | * Free resources / clean up outstanding I/Os |
| 4329 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4330 | */ |
| 4331 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4334 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | struct lpfc_sli *psli; |
| 4336 | struct lpfc_sli_ring *pring; |
| 4337 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4338 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4340 | lpfc_fabric_abort_nport(ndlp); |
| 4341 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | /* |
| 4343 | * Everything that matches on txcmplq will be returned |
| 4344 | * by firmware with a no rpi error. |
| 4345 | */ |
| 4346 | psli = &phba->sli; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4347 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | /* Now process each ring */ |
| 4349 | for (i = 0; i < psli->num_rings; i++) { |
| 4350 | pring = &psli->ring[i]; |
| 4351 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4354 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | /* |
| 4356 | * Check to see if iocb matches the nport we are |
| 4357 | * looking for |
| 4358 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4359 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 4360 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | /* It matches, so deque and call compl |
| 4362 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4363 | list_move_tail(&iocb->list, |
| 4364 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | } |
| 4366 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | } |
| 4369 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4370 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4371 | /* Cancel all the IOCBs from the completions list */ |
| 4372 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4373 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4374 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4375 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4376 | } |
| 4377 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4378 | /** |
| 4379 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4380 | * @phba: Pointer to HBA context object. |
| 4381 | * @pmb: Pointer to mailbox object. |
| 4382 | * |
| 4383 | * This function will issue an ELS LOGO command after completing |
| 4384 | * the UNREG_RPI. |
| 4385 | **/ |
| 4386 | void |
| 4387 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4388 | { |
| 4389 | struct lpfc_vport *vport = pmb->vport; |
| 4390 | struct lpfc_nodelist *ndlp; |
| 4391 | |
| 4392 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4393 | if (!ndlp) |
| 4394 | return; |
| 4395 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 4396 | } |
| 4397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4398 | /* |
| 4399 | * Free rpi associated with LPFC_NODELIST entry. |
| 4400 | * This routine is called from lpfc_freenode(), when we are removing |
| 4401 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4402 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4403 | * to the remote NPort. In addition, it is called after we receive |
| 4404 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4405 | * we are waiting to PLOGI back to the remote NPort. |
| 4406 | */ |
| 4407 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4408 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | struct lpfc_hba *phba = vport->phba; |
| 4411 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | int rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4413 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4415 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4416 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4417 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4418 | /* SLI4 ports require the physical rpi value. */ |
| 4419 | rpi = ndlp->nlp_rpi; |
| 4420 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4421 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4422 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4423 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4424 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4425 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4426 | mbox->context1 = ndlp; |
| 4427 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4428 | } else { |
| 4429 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4430 | } |
| 4431 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4432 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4433 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4434 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4436 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4437 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4438 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4439 | ndlp->nlp_rpi = 0; |
| 4440 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4441 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | return 1; |
| 4443 | } |
| 4444 | return 0; |
| 4445 | } |
| 4446 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4447 | /** |
| 4448 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4449 | * @phba: pointer to lpfc hba data structure. |
| 4450 | * |
| 4451 | * This routine is invoked to unregister all the currently registered RPIs |
| 4452 | * to the HBA. |
| 4453 | **/ |
| 4454 | void |
| 4455 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4456 | { |
| 4457 | struct lpfc_vport **vports; |
| 4458 | struct lpfc_nodelist *ndlp; |
| 4459 | struct Scsi_Host *shost; |
| 4460 | int i; |
| 4461 | |
| 4462 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4463 | if (!vports) { |
| 4464 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4465 | "2884 Vport array allocation failed \n"); |
| 4466 | return; |
| 4467 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4468 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4469 | shost = lpfc_shost_from_vport(vports[i]); |
| 4470 | spin_lock_irq(shost->host_lock); |
| 4471 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4472 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4473 | /* The mempool_alloc might sleep */ |
| 4474 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4475 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4476 | spin_lock_irq(shost->host_lock); |
| 4477 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4478 | } |
| 4479 | spin_unlock_irq(shost->host_lock); |
| 4480 | } |
| 4481 | lpfc_destroy_vport_work_array(phba, vports); |
| 4482 | } |
| 4483 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4484 | void |
| 4485 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4486 | { |
| 4487 | struct lpfc_hba *phba = vport->phba; |
| 4488 | LPFC_MBOXQ_t *mbox; |
| 4489 | int rc; |
| 4490 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4491 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4492 | lpfc_sli4_unreg_all_rpis(vport); |
| 4493 | return; |
| 4494 | } |
| 4495 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4496 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4497 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4498 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4499 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4500 | mbox->vport = vport; |
| 4501 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4502 | mbox->context1 = NULL; |
| 4503 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4504 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4505 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4506 | |
| 4507 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4508 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4509 | "1836 Could not issue " |
| 4510 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | void |
| 4515 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4516 | { |
| 4517 | struct lpfc_hba *phba = vport->phba; |
| 4518 | LPFC_MBOXQ_t *mbox; |
| 4519 | int rc; |
| 4520 | |
| 4521 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4522 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4523 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4524 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4525 | mbox->vport = vport; |
| 4526 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4527 | mbox->context1 = NULL; |
| 4528 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4529 | if (rc != MBX_TIMEOUT) |
| 4530 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4531 | |
| 4532 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4533 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4534 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4535 | "unreg_did (default rpis) status %d\n", |
| 4536 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | /* |
| 4541 | * Free resources associated with LPFC_NODELIST entry |
| 4542 | * so it can be freed. |
| 4543 | */ |
| 4544 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4547 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4548 | struct lpfc_hba *phba = vport->phba; |
| 4549 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | |
| 4552 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4554 | "0900 Cleanup node for NPort x%x " |
| 4555 | "Data: x%x x%x x%x\n", |
| 4556 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4557 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4558 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4559 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4560 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4561 | "usgmap:x%x refcnt:%d\n", |
| 4562 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4563 | atomic_read(&ndlp->kref.refcount)); |
| 4564 | lpfc_dequeue_node(vport, ndlp); |
| 4565 | } else { |
| 4566 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4567 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4568 | "usgmap:x%x refcnt:%d\n", |
| 4569 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4570 | atomic_read(&ndlp->kref.refcount)); |
| 4571 | lpfc_disable_node(vport, ndlp); |
| 4572 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4574 | |
| 4575 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4576 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4578 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4579 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4580 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4581 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4582 | mb->context2 = NULL; |
| 4583 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4584 | } |
| 4585 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4588 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4589 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4590 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4591 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4592 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4593 | continue; |
| 4594 | |
| 4595 | mb->context2 = NULL; |
| 4596 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4597 | } |
| 4598 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4600 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4601 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4602 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4603 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4604 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | kfree(mp); |
| 4607 | } |
| 4608 | list_del(&mb->list); |
| 4609 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4610 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4611 | * the ndlp reference count as we are in the process |
| 4612 | * of lpfc_nlp_release. |
| 4613 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | } |
| 4615 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4616 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4618 | lpfc_els_abort(phba, ndlp); |
| 4619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4620 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4621 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4622 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4623 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4624 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4625 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4626 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4627 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4628 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4629 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4630 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4632 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | /* |
| 4636 | * Check to see if we can free the nlp back to the freelist. |
| 4637 | * If we are in the middle of using the nlp in the discovery state |
| 4638 | * machine, defer the free till we reach the end of the state machine. |
| 4639 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4640 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4643 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4644 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4645 | LPFC_MBOXQ_t *mbox; |
| 4646 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4648 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4649 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4650 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4651 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4652 | /* For this case we need to cleanup the default rpi |
| 4653 | * allocated by the firmware. |
| 4654 | */ |
| 4655 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4656 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4657 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4658 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4659 | if (rc) { |
| 4660 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4661 | } |
| 4662 | else { |
| 4663 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4664 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4665 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4666 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4667 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4668 | if (rc == MBX_NOT_FINISHED) { |
| 4669 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4670 | } |
| 4671 | } |
| 4672 | } |
| 4673 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4674 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4676 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4677 | * We can get here with a non-NULL ndlp->rport because when we |
| 4678 | * unregister a rport we don't break the rport/node linkage. So if we |
| 4679 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4680 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4681 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4682 | rdata = ndlp->rport->dd_data; |
| 4683 | rdata->pnode = NULL; |
| 4684 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4685 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4690 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | |
| 4694 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4695 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4696 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4697 | /* First check for Direct match */ |
| 4698 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4699 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4700 | |
| 4701 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4702 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4704 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | matchdid.un.word = did; |
| 4708 | ndlpdid.un.word = ndlp->nlp_DID; |
| 4709 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 4710 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 4711 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 4712 | if ((ndlpdid.un.b.domain == 0) && |
| 4713 | (ndlpdid.un.b.area == 0)) { |
| 4714 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4715 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4716 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4717 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | matchdid.un.word = ndlp->nlp_DID; |
| 4721 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 4722 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 4723 | if ((matchdid.un.b.domain == 0) && |
| 4724 | (matchdid.un.b.area == 0)) { |
| 4725 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4726 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4730 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4731 | } |
| 4732 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4733 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4734 | static struct lpfc_nodelist * |
| 4735 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 4737 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | uint32_t data1; |
| 4739 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 4741 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4742 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 4743 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 4744 | ((uint32_t) ndlp->nlp_type << 8) | |
| 4745 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4746 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4747 | "0929 FIND node DID " |
| 4748 | "Data: x%p x%x x%x x%x\n", |
| 4749 | ndlp, ndlp->nlp_DID, |
| 4750 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4751 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | } |
| 4753 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4754 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4756 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4757 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | return NULL; |
| 4759 | } |
| 4760 | |
| 4761 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4762 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4764 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4766 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4768 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4769 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4770 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | return ndlp; |
| 4772 | } |
| 4773 | |
| 4774 | struct lpfc_nodelist * |
| 4775 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 4776 | { |
| 4777 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4778 | struct lpfc_nodelist *ndlp; |
| 4779 | |
| 4780 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4781 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4783 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | return NULL; |
| 4785 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | if (!ndlp) |
| 4788 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4789 | lpfc_nlp_init(vport, ndlp, did); |
| 4790 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4791 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4793 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4794 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4795 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4796 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4797 | if (!ndlp) |
| 4798 | return NULL; |
| 4799 | spin_lock_irq(shost->host_lock); |
| 4800 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4801 | spin_unlock_irq(shost->host_lock); |
| 4802 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4803 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4804 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4805 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4806 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4807 | if (lpfc_rscn_payload_check(vport, did)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4808 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4809 | * we don't need to try to discover it again. |
| 4810 | */ |
| 4811 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4812 | return NULL; |
| 4813 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4814 | /* Since this node is marked for discovery, |
| 4815 | * delay timeout is not needed. |
| 4816 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4817 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4818 | spin_lock_irq(shost->host_lock); |
| 4819 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4820 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4821 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4823 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4824 | /* If we've already received a PLOGI from this NPort, |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4825 | * or we are already in the process of discovery on it, |
| 4826 | * we don't need to try to discover it again. |
| 4827 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4828 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4829 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4830 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4832 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4833 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4835 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | } |
| 4837 | return ndlp; |
| 4838 | } |
| 4839 | |
| 4840 | /* Build a list of nodes to discover based on the loopmap */ |
| 4841 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4842 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4843 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4844 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | int j; |
| 4846 | uint32_t alpa, index; |
| 4847 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4848 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4849 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4851 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | |
| 4854 | /* Check for loop map present or not */ |
| 4855 | if (phba->alpa_map[0]) { |
| 4856 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4857 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4858 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4859 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4860 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | } |
| 4862 | } else { |
| 4863 | /* No alpamap, so try all alpa's */ |
| 4864 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4865 | /* If cfg_scan_down is set, start from highest |
| 4866 | * ALPA (0xef) to lowest (0x1). |
| 4867 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4868 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | index = j; |
| 4870 | else |
| 4871 | index = FC_MAXLOOP - j - 1; |
| 4872 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4873 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4875 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | return; |
| 4879 | } |
| 4880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4885 | struct lpfc_sli *psli = &phba->sli; |
| 4886 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4887 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4888 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4889 | int rc; |
| 4890 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4891 | /* |
| 4892 | * if it's not a physical port or if we already send |
| 4893 | * clear_la then don't send it. |
| 4894 | */ |
| 4895 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4896 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4897 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4898 | return; |
| 4899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4900 | /* Link up discovery */ |
| 4901 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4902 | phba->link_state = LPFC_CLEAR_LA; |
| 4903 | lpfc_clear_la(phba, mbox); |
| 4904 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4905 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4906 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4907 | if (rc == MBX_NOT_FINISHED) { |
| 4908 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4909 | lpfc_disc_flush_list(vport); |
| 4910 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4911 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4912 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4913 | phba->link_state = LPFC_HBA_ERROR; |
| 4914 | } |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4919 | void |
| 4920 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4921 | { |
| 4922 | LPFC_MBOXQ_t *regvpimbox; |
| 4923 | |
| 4924 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4925 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4926 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4927 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4928 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4929 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4930 | == MBX_NOT_FINISHED) { |
| 4931 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 4937 | void |
| 4938 | lpfc_disc_start(struct lpfc_vport *vport) |
| 4939 | { |
| 4940 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4941 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4942 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4944 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4946 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4948 | |
| 4949 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4950 | clear_la_pending = 1; |
| 4951 | else |
| 4952 | clear_la_pending = 0; |
| 4953 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4954 | if (vport->port_state < LPFC_VPORT_READY) |
| 4955 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4957 | lpfc_set_disctmo(vport); |
| 4958 | |
| 4959 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4961 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4963 | |
| 4964 | vport->fc_prevDID = vport->fc_myDID; |
| 4965 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | |
| 4967 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4968 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4969 | "0202 Start Discovery hba state x%x " |
| 4970 | "Data: x%x x%x x%x\n", |
| 4971 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 4972 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | |
| 4974 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | |
| 4977 | if (num_sent) |
| 4978 | return; |
| 4979 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4980 | /* Register the VPI for SLI3, NON-NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4981 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4982 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4983 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 4984 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4985 | lpfc_issue_reg_vpi(phba, vport); |
| 4986 | return; |
| 4987 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4988 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4989 | /* |
| 4990 | * For SLI2, we need to set port_state to READY and continue |
| 4991 | * discovery. |
| 4992 | */ |
| 4993 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 4994 | /* If we get here, there is nothing to ADISC */ |
| 4995 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 4996 | lpfc_issue_clear_la(phba, vport); |
| 4997 | |
| 4998 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | vport->num_disc_nodes = 0; |
| 5000 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5001 | if (vport->fc_npr_cnt) |
| 5002 | lpfc_els_disc_plogi(vport); |
| 5003 | |
| 5004 | if (!vport->num_disc_nodes) { |
| 5005 | spin_lock_irq(shost->host_lock); |
| 5006 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5007 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5008 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | } |
| 5010 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5011 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | } else { |
| 5013 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5014 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5015 | |
| 5016 | if (num_sent) |
| 5017 | return; |
| 5018 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5019 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5020 | /* Check to see if more RSCNs came in while we |
| 5021 | * were processing this one. |
| 5022 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5023 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5024 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5025 | spin_lock_irq(shost->host_lock); |
| 5026 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5027 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5028 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5029 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5030 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | } |
| 5032 | } |
| 5033 | return; |
| 5034 | } |
| 5035 | |
| 5036 | /* |
| 5037 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5038 | * ring the match the sppecified nodelist. |
| 5039 | */ |
| 5040 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5041 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5043 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5044 | struct lpfc_sli *psli; |
| 5045 | IOCB_t *icmd; |
| 5046 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5047 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | |
| 5049 | psli = &phba->sli; |
| 5050 | pring = &psli->ring[LPFC_ELS_RING]; |
| 5051 | |
| 5052 | /* Error matching iocb on txq or txcmplq |
| 5053 | * First check the txq. |
| 5054 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5055 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5057 | if (iocb->context1 != ndlp) { |
| 5058 | continue; |
| 5059 | } |
| 5060 | icmd = &iocb->iocb; |
| 5061 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5062 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5063 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5064 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | /* Next check the txcmplq */ |
| 5069 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5070 | if (iocb->context1 != ndlp) { |
| 5071 | continue; |
| 5072 | } |
| 5073 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5074 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5075 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5076 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5077 | } |
| 5078 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5079 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5080 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5081 | /* Cancel all the IOCBs from the completions list */ |
| 5082 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5083 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | } |
| 5085 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5086 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5087 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5088 | { |
| 5089 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5090 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5091 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5092 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5093 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5094 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5095 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5096 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5097 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5098 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5099 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5101 | } |
| 5102 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5103 | } |
| 5104 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5105 | void |
| 5106 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5107 | { |
| 5108 | lpfc_els_flush_rscn(vport); |
| 5109 | lpfc_els_flush_cmd(vport); |
| 5110 | lpfc_disc_flush_list(vport); |
| 5111 | } |
| 5112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | /*****************************************************************************/ |
| 5114 | /* |
| 5115 | * NAME: lpfc_disc_timeout |
| 5116 | * |
| 5117 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5118 | * |
| 5119 | * EXECUTION ENVIRONMENT: interrupt only |
| 5120 | * |
| 5121 | * CALLED FROM: |
| 5122 | * Timer function |
| 5123 | * |
| 5124 | * RETURNS: |
| 5125 | * none |
| 5126 | */ |
| 5127 | /*****************************************************************************/ |
| 5128 | void |
| 5129 | lpfc_disc_timeout(unsigned long ptr) |
| 5130 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5131 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5132 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5133 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | unsigned long flags = 0; |
| 5135 | |
| 5136 | if (unlikely(!phba)) |
| 5137 | return; |
| 5138 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5139 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5140 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5141 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5142 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5143 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5144 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5145 | if (!tmo_posted) |
| 5146 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5147 | return; |
| 5148 | } |
| 5149 | |
| 5150 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5151 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5153 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5154 | struct lpfc_hba *phba = vport->phba; |
| 5155 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5156 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5157 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | int rc, clrlaerr = 0; |
| 5159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5160 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | return; |
| 5162 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5163 | spin_lock_irq(shost->host_lock); |
| 5164 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5165 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5166 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5167 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5168 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5169 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5170 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5171 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5172 | |
| 5173 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5174 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 5175 | * FAN |
| 5176 | */ |
| 5177 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5178 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5179 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5180 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5181 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5182 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5183 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5184 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5185 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5186 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5187 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5188 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5190 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5191 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5192 | /* Fail outstanding IO now since device |
| 5193 | * is marked for PLOGI. |
| 5194 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5195 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5196 | } |
| 5197 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5198 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5199 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5200 | lpfc_initial_flogi(vport); |
| 5201 | else |
| 5202 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5203 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5204 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5205 | break; |
| 5206 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5207 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5209 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5210 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5211 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5212 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5213 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | |
| 5215 | /* Assume no Fabric and go on with discovery. |
| 5216 | * Check for outstanding ELS FLOGI to abort. |
| 5217 | */ |
| 5218 | |
| 5219 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5220 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | |
| 5222 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | break; |
| 5225 | |
| 5226 | case LPFC_FABRIC_CFG_LINK: |
| 5227 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5228 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5229 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5230 | "0223 Timeout while waiting for " |
| 5231 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5234 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5235 | lpfc_els_abort(phba, ndlp); |
| 5236 | |
| 5237 | /* ReStart discovery */ |
| 5238 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | |
| 5240 | case LPFC_NS_QRY: |
| 5241 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5242 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5243 | "0224 NameServer Query timeout " |
| 5244 | "Data: x%x x%x\n", |
| 5245 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5246 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5247 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5248 | /* Try it one more time */ |
| 5249 | vport->fc_ns_retry++; |
| 5250 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 5251 | vport->fc_ns_retry, 0); |
| 5252 | if (rc == 0) |
| 5253 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5255 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5256 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5257 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5258 | /* |
| 5259 | * Discovery is over. |
| 5260 | * set port_state to PORT_READY if SLI2. |
| 5261 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5262 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5263 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5264 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5265 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5266 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5267 | lpfc_issue_clear_la(phba, vport); |
| 5268 | vport->port_state = LPFC_VPORT_READY; |
| 5269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5273 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5274 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5275 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5276 | "0206 Device Discovery " |
| 5277 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5278 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5279 | break; |
| 5280 | } |
| 5281 | |
| 5282 | lpfc_linkdown(phba); |
| 5283 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5284 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5285 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5286 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5287 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5288 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5289 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | if (rc == MBX_NOT_FINISHED) |
| 5291 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5292 | |
| 5293 | break; |
| 5294 | |
| 5295 | case LPFC_DISC_AUTH: |
| 5296 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5297 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5298 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5299 | lpfc_disc_flush_list(vport); |
| 5300 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5301 | /* |
| 5302 | * set port_state to PORT_READY if SLI2. |
| 5303 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5304 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5305 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5306 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5307 | lpfc_issue_reg_vpi(phba, vport); |
| 5308 | else { /* NPIV Not enabled */ |
| 5309 | lpfc_issue_clear_la(phba, vport); |
| 5310 | vport->port_state = LPFC_VPORT_READY; |
| 5311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5312 | } |
| 5313 | break; |
| 5314 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5315 | case LPFC_VPORT_READY: |
| 5316 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5317 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5318 | "0231 RSCN timeout Data: x%x " |
| 5319 | "x%x\n", |
| 5320 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5321 | |
| 5322 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5323 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5324 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5325 | lpfc_els_flush_rscn(vport); |
| 5326 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5327 | } |
| 5328 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5329 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5330 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5331 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5332 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5333 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5334 | break; |
| 5335 | } |
| 5336 | |
| 5337 | switch (phba->link_state) { |
| 5338 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5339 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5340 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5341 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5342 | clrlaerr = 1; |
| 5343 | break; |
| 5344 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5345 | case LPFC_LINK_UP: |
| 5346 | lpfc_issue_clear_la(phba, vport); |
| 5347 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5348 | case LPFC_LINK_UNKNOWN: |
| 5349 | case LPFC_WARM_START: |
| 5350 | case LPFC_INIT_START: |
| 5351 | case LPFC_INIT_MBX_CMDS: |
| 5352 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5353 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5354 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5355 | "0230 Unexpected timeout, hba link " |
| 5356 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5357 | clrlaerr = 1; |
| 5358 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5359 | |
| 5360 | case LPFC_HBA_READY: |
| 5361 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5365 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5366 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5367 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5368 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5369 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | return; |
| 5373 | } |
| 5374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5375 | /* |
| 5376 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5377 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5378 | * as the completion routine when the command is |
| 5379 | * handed off to the SLI layer. |
| 5380 | */ |
| 5381 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5382 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5383 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5384 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5385 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5386 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5387 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5388 | |
| 5389 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5390 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5391 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5392 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5393 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5394 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5395 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5398 | /* |
| 5399 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 5400 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 5401 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5402 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5403 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5404 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5405 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 5406 | else |
| 5407 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5408 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5409 | /* decrement the node reference count held for this callback |
| 5410 | * function. |
| 5411 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5412 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5414 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5415 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | |
| 5417 | return; |
| 5418 | } |
| 5419 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5420 | static int |
| 5421 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5422 | { |
| 5423 | uint16_t *rpi = param; |
| 5424 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5425 | /* check for active node */ |
| 5426 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5427 | return 0; |
| 5428 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5429 | return ndlp->nlp_rpi == *rpi; |
| 5430 | } |
| 5431 | |
| 5432 | static int |
| 5433 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5434 | { |
| 5435 | return memcmp(&ndlp->nlp_portname, param, |
| 5436 | sizeof(ndlp->nlp_portname)) == 0; |
| 5437 | } |
| 5438 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5439 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5440 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5442 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5444 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5445 | if (filter(ndlp, param)) { |
| 5446 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5447 | "3185 FIND node filter %p DID " |
| 5448 | "Data: x%p x%x x%x\n", |
| 5449 | filter, ndlp, ndlp->nlp_DID, |
| 5450 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5451 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5452 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5453 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5454 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5455 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5456 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5457 | } |
| 5458 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5459 | /* |
| 5460 | * 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] | 5461 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5462 | */ |
| 5463 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5464 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5465 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5466 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5467 | } |
| 5468 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5469 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5470 | * 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] | 5471 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5472 | */ |
| 5473 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5474 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5475 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5476 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5477 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5479 | spin_lock_irq(shost->host_lock); |
| 5480 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5481 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5482 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5483 | } |
| 5484 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5485 | /* |
| 5486 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5487 | * is found, the routine returns the node element list pointer else |
| 5488 | * return NULL. |
| 5489 | */ |
| 5490 | struct lpfc_nodelist * |
| 5491 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5492 | { |
| 5493 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5494 | struct lpfc_nodelist *ndlp; |
| 5495 | |
| 5496 | spin_lock_irq(shost->host_lock); |
| 5497 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5498 | spin_unlock_irq(shost->host_lock); |
| 5499 | return ndlp; |
| 5500 | } |
| 5501 | |
| 5502 | /** |
| 5503 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5504 | * @phba: pointer to lpfc hba data structure. |
| 5505 | * @vpi: the physical host virtual N_Port identifier. |
| 5506 | * |
| 5507 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5508 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5509 | * of the vport with the matching @vpi. |
| 5510 | * |
| 5511 | * Return code |
| 5512 | * NULL - No vport with the matching @vpi found |
| 5513 | * Otherwise - Address to the vport with the matching @vpi. |
| 5514 | **/ |
| 5515 | struct lpfc_vport * |
| 5516 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5517 | { |
| 5518 | struct lpfc_vport *vport; |
| 5519 | unsigned long flags; |
| 5520 | int i = 0; |
| 5521 | |
| 5522 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5523 | if (vpi > 0) { |
| 5524 | /* |
| 5525 | * Translate the physical vpi to the logical vpi. The |
| 5526 | * vport stores the logical vpi. |
| 5527 | */ |
| 5528 | for (i = 0; i < phba->max_vpi; i++) { |
| 5529 | if (vpi == phba->vpi_ids[i]) |
| 5530 | break; |
| 5531 | } |
| 5532 | |
| 5533 | if (i >= phba->max_vpi) { |
| 5534 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5535 | "2936 Could not find Vport mapped " |
| 5536 | "to vpi %d\n", vpi); |
| 5537 | return NULL; |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5542 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5543 | if (vport->vpi == i) { |
| 5544 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5545 | return vport; |
| 5546 | } |
| 5547 | } |
| 5548 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5549 | return NULL; |
| 5550 | } |
| 5551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5553 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5554 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | { |
| 5556 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5557 | |
| 5558 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5559 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5560 | |
| 5561 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5562 | "node init: did:x%x", |
| 5563 | ndlp->nlp_DID, 0, 0); |
| 5564 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | return; |
| 5566 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5567 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5568 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5569 | * and mempool_free's the nodelist. |
| 5570 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5571 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5572 | lpfc_nlp_release(struct kref *kref) |
| 5573 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5574 | struct lpfc_hba *phba; |
| 5575 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5576 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 5577 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5578 | |
| 5579 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5580 | "node release: did:x%x flg:x%x type:x%x", |
| 5581 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 5582 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5583 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5584 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5585 | "usgmap:x%x refcnt:%d\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5586 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5587 | atomic_read(&ndlp->kref.refcount)); |
| 5588 | |
| 5589 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5590 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5591 | |
| 5592 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5593 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5594 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5595 | NLP_CLR_NODE_ACT(ndlp); |
| 5596 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5597 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5598 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5599 | |
| 5600 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5601 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5602 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5603 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5604 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5605 | } |
| 5606 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5607 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 5608 | * that one discovery thread won't free a ndlp while another discovery thread |
| 5609 | * is using it. |
| 5610 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5611 | struct lpfc_nodelist * |
| 5612 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 5613 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5614 | struct lpfc_hba *phba; |
| 5615 | unsigned long flags; |
| 5616 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5617 | if (ndlp) { |
| 5618 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5619 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 5620 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5621 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5622 | /* The check of ndlp usage to prevent incrementing the |
| 5623 | * ndlp reference count that is in the process of being |
| 5624 | * released. |
| 5625 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5626 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5627 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5628 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 5629 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5630 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5631 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 5632 | "usgmap:x%x refcnt:%d\n", |
| 5633 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5634 | atomic_read(&ndlp->kref.refcount)); |
| 5635 | return NULL; |
| 5636 | } else |
| 5637 | kref_get(&ndlp->kref); |
| 5638 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5639 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5640 | return ndlp; |
| 5641 | } |
| 5642 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5643 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5644 | * count goes to 0, this indicates the the associated nodelist should be |
| 5645 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 5646 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 5647 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5648 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5649 | int |
| 5650 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 5651 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5652 | struct lpfc_hba *phba; |
| 5653 | unsigned long flags; |
| 5654 | |
| 5655 | if (!ndlp) |
| 5656 | return 1; |
| 5657 | |
| 5658 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5659 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 5660 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5661 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5662 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5663 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5664 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 5665 | * possible race condition that kref_put got invoked again |
| 5666 | * after previous one has done ndlp memory free. |
| 5667 | */ |
| 5668 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 5669 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5670 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5671 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 5672 | "usgmap:x%x refcnt:%d\n", |
| 5673 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5674 | atomic_read(&ndlp->kref.refcount)); |
| 5675 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5676 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5677 | /* Check the ndlp inactivate log flag to avoid the possible |
| 5678 | * race condition that kref_put got invoked again after ndlp |
| 5679 | * is already in inactivating state. |
| 5680 | */ |
| 5681 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 5682 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5683 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5684 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 5685 | "usgmap:x%x refcnt:%d\n", |
| 5686 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5687 | atomic_read(&ndlp->kref.refcount)); |
| 5688 | return 1; |
| 5689 | } |
| 5690 | /* For last put, mark the ndlp usage flags to make sure no |
| 5691 | * other kref_get and kref_put on the same ndlp shall get |
| 5692 | * in between the process when the final kref_put has been |
| 5693 | * invoked on this ndlp. |
| 5694 | */ |
| 5695 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 5696 | /* Indicate ndlp is put to inactive state. */ |
| 5697 | NLP_SET_IACT_REQ(ndlp); |
| 5698 | /* Acknowledge ndlp memory free has been seen. */ |
| 5699 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 5700 | NLP_SET_FREE_ACK(ndlp); |
| 5701 | } |
| 5702 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5703 | /* Note, the kref_put returns 1 when decrementing a reference |
| 5704 | * count that was 1, it invokes the release callback function, |
| 5705 | * but it still left the reference count as 1 (not actually |
| 5706 | * performs the last decrementation). Otherwise, it actually |
| 5707 | * decrements the reference count and returns 0. |
| 5708 | */ |
| 5709 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5710 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5711 | |
| 5712 | /* 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] | 5713 | * by any other discovery thread. This routine returns 1 if the |
| 5714 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 5715 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5716 | */ |
| 5717 | int |
| 5718 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 5719 | { |
| 5720 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5721 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 5722 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5723 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5724 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 5725 | if (lpfc_nlp_put(ndlp)) |
| 5726 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5727 | return 0; |
| 5728 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5729 | |
| 5730 | /** |
| 5731 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 5732 | * @phba: Pointer to hba context object. |
| 5733 | * |
| 5734 | * This function iterate through all FC nodes associated |
| 5735 | * will all vports to check if there is any node with |
| 5736 | * fc_rports associated with it. If there is an fc_rport |
| 5737 | * associated with the node, then the node is either in |
| 5738 | * discovered state or its devloss_timer is pending. |
| 5739 | */ |
| 5740 | static int |
| 5741 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 5742 | { |
| 5743 | struct lpfc_vport **vports; |
| 5744 | int i, ret = 0; |
| 5745 | struct lpfc_nodelist *ndlp; |
| 5746 | struct Scsi_Host *shost; |
| 5747 | |
| 5748 | vports = lpfc_create_vport_work_array(phba); |
| 5749 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5750 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 5751 | if (!vports) |
| 5752 | return 1; |
| 5753 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5754 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5755 | shost = lpfc_shost_from_vport(vports[i]); |
| 5756 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5757 | /* |
| 5758 | * IF the CVL_RCVD bit is not set then we have sent the |
| 5759 | * flogi. |
| 5760 | * If dev_loss fires while we are waiting we do not want to |
| 5761 | * unreg the fcf. |
| 5762 | */ |
| 5763 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 5764 | spin_unlock_irq(shost->host_lock); |
| 5765 | ret = 1; |
| 5766 | goto out; |
| 5767 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5768 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 5769 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 5770 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 5771 | ret = 1; |
| 5772 | spin_unlock_irq(shost->host_lock); |
| 5773 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5774 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 5775 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5776 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5777 | "2624 RPI %x DID %x flag %x " |
| 5778 | "still logged in\n", |
| 5779 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5780 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5781 | } |
| 5782 | } |
| 5783 | spin_unlock_irq(shost->host_lock); |
| 5784 | } |
| 5785 | out: |
| 5786 | lpfc_destroy_vport_work_array(phba, vports); |
| 5787 | return ret; |
| 5788 | } |
| 5789 | |
| 5790 | /** |
| 5791 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 5792 | * @phba: Pointer to hba context object. |
| 5793 | * @mboxq: Pointer to mailbox object. |
| 5794 | * |
| 5795 | * This function frees memory associated with the mailbox command. |
| 5796 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5797 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5798 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5799 | { |
| 5800 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5801 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5802 | |
| 5803 | if (mboxq->u.mb.mbxStatus) { |
| 5804 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5805 | "2555 UNREG_VFI mbxStatus error x%x " |
| 5806 | "HBA state x%x\n", |
| 5807 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5808 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5809 | spin_lock_irq(shost->host_lock); |
| 5810 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 5811 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5812 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5813 | return; |
| 5814 | } |
| 5815 | |
| 5816 | /** |
| 5817 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 5818 | * @phba: Pointer to hba context object. |
| 5819 | * @mboxq: Pointer to mailbox object. |
| 5820 | * |
| 5821 | * This function frees memory associated with the mailbox command. |
| 5822 | */ |
| 5823 | static void |
| 5824 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5825 | { |
| 5826 | struct lpfc_vport *vport = mboxq->vport; |
| 5827 | |
| 5828 | if (mboxq->u.mb.mbxStatus) { |
| 5829 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5830 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 5831 | "HBA state x%x\n", |
| 5832 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5833 | } |
| 5834 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5835 | return; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5839 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5840 | * @phba: Pointer to hba context object. |
| 5841 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5842 | * This function prepare the HBA for unregistering the currently registered |
| 5843 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 5844 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5845 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5846 | int |
| 5847 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5848 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5849 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5850 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5851 | struct Scsi_Host *shost; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5852 | int i, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5853 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5854 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5855 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5856 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5857 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5858 | /* At this point, all discovery is aborted */ |
| 5859 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5860 | |
| 5861 | /* Unregister VPIs */ |
| 5862 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5863 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5864 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5865 | /* Stop FLOGI/FDISC retries */ |
| 5866 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 5867 | if (ndlp) |
| 5868 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5869 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5870 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5871 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5872 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5873 | shost = lpfc_shost_from_vport(vports[i]); |
| 5874 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5875 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5876 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5877 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5878 | } |
| 5879 | lpfc_destroy_vport_work_array(phba, vports); |
| 5880 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5881 | /* Cleanup any outstanding ELS commands */ |
| 5882 | lpfc_els_flush_all_cmd(phba); |
| 5883 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5884 | /* Unregister the physical port VFI */ |
| 5885 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 5886 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | /** |
| 5890 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5891 | * @phba: Pointer to hba context object. |
| 5892 | * |
| 5893 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5894 | * unregister the currently registered FCF record. The driver does not reset |
| 5895 | * the driver FCF usage state flags. |
| 5896 | * |
| 5897 | * Return 0 if successfully issued, none-zero otherwise. |
| 5898 | */ |
| 5899 | int |
| 5900 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 5901 | { |
| 5902 | LPFC_MBOXQ_t *mbox; |
| 5903 | int rc; |
| 5904 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5905 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5906 | if (!mbox) { |
| 5907 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5908 | "2551 UNREG_FCFI mbox allocation failed" |
| 5909 | "HBA state x%x\n", phba->pport->port_state); |
| 5910 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5911 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5912 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 5913 | mbox->vport = phba->pport; |
| 5914 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 5915 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5916 | |
| 5917 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5918 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5919 | "2552 Unregister FCFI command failed rc x%x " |
| 5920 | "HBA state x%x\n", |
| 5921 | rc, phba->pport->port_state); |
| 5922 | return -EINVAL; |
| 5923 | } |
| 5924 | return 0; |
| 5925 | } |
| 5926 | |
| 5927 | /** |
| 5928 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 5929 | * @phba: Pointer to hba context object. |
| 5930 | * |
| 5931 | * This function unregisters the currently reigstered FCF. This function |
| 5932 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 5933 | */ |
| 5934 | void |
| 5935 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 5936 | { |
| 5937 | int rc; |
| 5938 | |
| 5939 | /* Preparation for unregistering fcf */ |
| 5940 | rc = lpfc_unregister_fcf_prep(phba); |
| 5941 | if (rc) { |
| 5942 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5943 | "2748 Failed to prepare for unregistering " |
| 5944 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5945 | return; |
| 5946 | } |
| 5947 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5948 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5949 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5950 | if (rc) |
| 5951 | return; |
| 5952 | /* Reset HBA FCF states after successful unregister FCF */ |
| 5953 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5954 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5955 | |
| 5956 | /* |
| 5957 | * If driver is not unloading, check if there is any other |
| 5958 | * FCF record that can be used for discovery. |
| 5959 | */ |
| 5960 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5961 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5962 | return; |
| 5963 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5964 | /* This is considered as the initial FCF discovery scan */ |
| 5965 | spin_lock_irq(&phba->hbalock); |
| 5966 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 5967 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5968 | |
| 5969 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5970 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5971 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5972 | 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] | 5973 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5974 | if (rc) { |
| 5975 | spin_lock_irq(&phba->hbalock); |
| 5976 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 5977 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5978 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5979 | "2553 lpfc_unregister_unused_fcf failed " |
| 5980 | "to read FCF record HBA state x%x\n", |
| 5981 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5982 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 5987 | * @phba: Pointer to hba context object. |
| 5988 | * |
| 5989 | * This function just unregisters the currently reigstered FCF. It does not |
| 5990 | * try to find another FCF for discovery. |
| 5991 | */ |
| 5992 | void |
| 5993 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 5994 | { |
| 5995 | int rc; |
| 5996 | |
| 5997 | /* Preparation for unregistering fcf */ |
| 5998 | rc = lpfc_unregister_fcf_prep(phba); |
| 5999 | if (rc) { |
| 6000 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6001 | "2749 Failed to prepare for unregistering " |
| 6002 | "HBA's FCF record: rc=%d\n", rc); |
| 6003 | return; |
| 6004 | } |
| 6005 | |
| 6006 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6007 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6008 | if (rc) |
| 6009 | return; |
| 6010 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6011 | spin_lock_irq(&phba->hbalock); |
| 6012 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6013 | spin_unlock_irq(&phba->hbalock); |
| 6014 | } |
| 6015 | |
| 6016 | /** |
| 6017 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6018 | * @phba: Pointer to hba context object. |
| 6019 | * |
| 6020 | * This function check if there are any connected remote port for the FCF and |
| 6021 | * if all the devices are disconnected, this function unregister FCFI. |
| 6022 | * This function also tries to use another FCF for discovery. |
| 6023 | */ |
| 6024 | void |
| 6025 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6026 | { |
| 6027 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6028 | * If HBA is not running in FIP mode, if HBA does not support |
| 6029 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6030 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6031 | */ |
| 6032 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6033 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6034 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6035 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6036 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6037 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6038 | spin_unlock_irq(&phba->hbalock); |
| 6039 | return; |
| 6040 | } |
| 6041 | spin_unlock_irq(&phba->hbalock); |
| 6042 | |
| 6043 | if (lpfc_fcf_inuse(phba)) |
| 6044 | return; |
| 6045 | |
| 6046 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | /** |
| 6050 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6051 | * @phba: Pointer to hba context object. |
| 6052 | * @buff: Buffer containing the FCF connection table as in the config |
| 6053 | * region. |
| 6054 | * This function create driver data structure for the FCF connection |
| 6055 | * record table read from config region 23. |
| 6056 | */ |
| 6057 | static void |
| 6058 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6059 | uint8_t *buff) |
| 6060 | { |
| 6061 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6062 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6063 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6064 | uint32_t record_count; |
| 6065 | int i; |
| 6066 | |
| 6067 | /* Free the current connect table */ |
| 6068 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6069 | &phba->fcf_conn_rec_list, list) { |
| 6070 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6071 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6072 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6073 | |
| 6074 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6075 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6076 | sizeof(struct lpfc_fcf_conn_rec); |
| 6077 | |
| 6078 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6079 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6080 | |
| 6081 | for (i = 0; i < record_count; i++) { |
| 6082 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6083 | continue; |
| 6084 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6085 | GFP_KERNEL); |
| 6086 | if (!conn_entry) { |
| 6087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6088 | "2566 Failed to allocate connection" |
| 6089 | " table entry\n"); |
| 6090 | return; |
| 6091 | } |
| 6092 | |
| 6093 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6094 | sizeof(struct lpfc_fcf_conn_rec)); |
| 6095 | conn_entry->conn_rec.vlan_tag = |
| 6096 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 6097 | conn_entry->conn_rec.flags = |
| 6098 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 6099 | list_add_tail(&conn_entry->list, |
| 6100 | &phba->fcf_conn_rec_list); |
| 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | /** |
| 6105 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6106 | * @phba: Pointer to hba context object. |
| 6107 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6108 | * |
| 6109 | * This function update driver data structure with config |
| 6110 | * parameters read from config region 23. |
| 6111 | */ |
| 6112 | static void |
| 6113 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6114 | uint8_t *buff) |
| 6115 | { |
| 6116 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6117 | struct lpfc_fcoe_params *fcoe_param; |
| 6118 | |
| 6119 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6120 | buff; |
| 6121 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6122 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6123 | |
| 6124 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6125 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6126 | return; |
| 6127 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6128 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6129 | phba->valid_vlan = 1; |
| 6130 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6131 | 0xFFF; |
| 6132 | } |
| 6133 | |
| 6134 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6135 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6136 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6137 | return; |
| 6138 | } |
| 6139 | |
| 6140 | /** |
| 6141 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6142 | * @buff: Buffer containing config region 23 data. |
| 6143 | * @size: Size of the data buffer. |
| 6144 | * @rec_type: Record type to be searched. |
| 6145 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6146 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6147 | * of the record specified by record_type. If record found, this |
| 6148 | * function return pointer to the record else return NULL. |
| 6149 | */ |
| 6150 | static uint8_t * |
| 6151 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6152 | { |
| 6153 | uint32_t offset = 0, rec_length; |
| 6154 | |
| 6155 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6156 | (size < sizeof(uint32_t))) |
| 6157 | return NULL; |
| 6158 | |
| 6159 | rec_length = buff[offset + 1]; |
| 6160 | |
| 6161 | /* |
| 6162 | * One TLV record has one word header and number of data words |
| 6163 | * specified in the rec_length field of the record header. |
| 6164 | */ |
| 6165 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6166 | <= size) { |
| 6167 | if (buff[offset] == rec_type) |
| 6168 | return &buff[offset]; |
| 6169 | |
| 6170 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6171 | return NULL; |
| 6172 | |
| 6173 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6174 | rec_length = buff[offset + 1]; |
| 6175 | } |
| 6176 | return NULL; |
| 6177 | } |
| 6178 | |
| 6179 | /** |
| 6180 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6181 | * @phba: Pointer to lpfc_hba data structure. |
| 6182 | * @buff: Buffer containing config region 23 data. |
| 6183 | * @size: Size of the data buffer. |
| 6184 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6185 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6186 | * populate driver data structure with the parameters. |
| 6187 | */ |
| 6188 | void |
| 6189 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6190 | uint8_t *buff, |
| 6191 | uint32_t size) |
| 6192 | { |
| 6193 | uint32_t offset = 0, rec_length; |
| 6194 | uint8_t *rec_ptr; |
| 6195 | |
| 6196 | /* |
| 6197 | * If data size is less than 2 words signature and version cannot be |
| 6198 | * verified. |
| 6199 | */ |
| 6200 | if (size < 2*sizeof(uint32_t)) |
| 6201 | return; |
| 6202 | |
| 6203 | /* Check the region signature first */ |
| 6204 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6205 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6206 | "2567 Config region 23 has bad signature\n"); |
| 6207 | return; |
| 6208 | } |
| 6209 | |
| 6210 | offset += 4; |
| 6211 | |
| 6212 | /* Check the data structure version */ |
| 6213 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6215 | "2568 Config region 23 has bad version\n"); |
| 6216 | return; |
| 6217 | } |
| 6218 | offset += 4; |
| 6219 | |
| 6220 | rec_length = buff[offset + 1]; |
| 6221 | |
| 6222 | /* Read FCoE param record */ |
| 6223 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6224 | size - offset, FCOE_PARAM_TYPE); |
| 6225 | if (rec_ptr) |
| 6226 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6227 | |
| 6228 | /* Read FCF connection table */ |
| 6229 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6230 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6231 | if (rec_ptr) |
| 6232 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6233 | |
| 6234 | } |