| 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 | 9466150 | 2013-03-01 16:37:29 -0500 | [diff] [blame] | 694 | if (phba->link_state >= LPFC_LINK_UP) { |
| 695 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
| 696 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 697 | (status & |
| 698 | HA_RXMASK)); |
| 699 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 700 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 701 | if ((phba->sli_rev == LPFC_SLI_REV4) & |
| 702 | (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 703 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 704 | /* |
| 705 | * Turn on Ring interrupts |
| 706 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 707 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 708 | spin_lock_irq(&phba->hbalock); |
| 709 | control = readl(phba->HCregaddr); |
| 710 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 711 | lpfc_debugfs_slow_ring_trc(phba, |
| 712 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 713 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 714 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 715 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 716 | writel(control, phba->HCregaddr); |
| 717 | readl(phba->HCregaddr); /* flush */ |
| 718 | } else { |
| 719 | lpfc_debugfs_slow_ring_trc(phba, |
| 720 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 721 | control, ha_copy, 0); |
| 722 | } |
| 723 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 724 | } |
| 725 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | } |
| 728 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 729 | int |
| 730 | lpfc_do_work(void *p) |
| 731 | { |
| 732 | struct lpfc_hba *phba = p; |
| 733 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | |
| 735 | set_user_nice(current, -20); |
James Smart | 043c956 | 2012-05-09 21:17:43 -0400 | [diff] [blame] | 736 | current->flags |= PF_NOFREEZE; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 737 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 739 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 740 | /* wait and check worker queue activities */ |
| 741 | rc = wait_event_interruptible(phba->work_waitq, |
| 742 | (test_and_clear_bit(LPFC_DATA_READY, |
| 743 | &phba->data_flags) |
| 744 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 745 | /* Signal wakeup shall terminate the worker thread */ |
| 746 | if (rc) { |
| 747 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 748 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 750 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 752 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 754 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 755 | phba->worker_thread = NULL; |
| 756 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 757 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * 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] | 763 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | * embedding it in the IOCB. |
| 765 | */ |
| 766 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 767 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | uint32_t evt) |
| 769 | { |
| 770 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 771 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | |
| 773 | /* |
| 774 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 775 | * be queued to worker thread for processing |
| 776 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 777 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | if (!evtp) |
| 779 | return 0; |
| 780 | |
| 781 | evtp->evt_arg1 = arg1; |
| 782 | evtp->evt_arg2 = arg2; |
| 783 | evtp->evt = evt; |
| 784 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 785 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 786 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 787 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 789 | lpfc_worker_wake_up(phba); |
| 790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | return 1; |
| 792 | } |
| 793 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | void |
| 795 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 796 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 797 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 798 | struct lpfc_hba *phba = vport->phba; |
| 799 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 800 | int rc; |
| 801 | |
| 802 | 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] | 803 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 804 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 806 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 807 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 808 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 809 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 810 | lpfc_unreg_rpi(vport, ndlp); |
| 811 | |
| 812 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 813 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 814 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 815 | continue; |
| 816 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 817 | remove |
| 818 | ? NLP_EVT_DEVICE_RM |
| 819 | : NLP_EVT_DEVICE_RECOVERY); |
| 820 | } |
| 821 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 822 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 823 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 825 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 826 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 827 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 831 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 832 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 833 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 834 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 835 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 836 | /* Cleanup any outstanding received buffers */ |
| 837 | lpfc_cleanup_rcv_buffers(vport); |
| 838 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 839 | /* Cleanup any outstanding RSCN activity */ |
| 840 | lpfc_els_flush_rscn(vport); |
| 841 | |
| 842 | /* Cleanup any outstanding ELS commands */ |
| 843 | lpfc_els_flush_cmd(vport); |
| 844 | |
| 845 | lpfc_cleanup_rpis(vport, 0); |
| 846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 847 | /* Turn off discovery timer if its running */ |
| 848 | lpfc_can_disctmo(vport); |
| 849 | } |
| 850 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 851 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 852 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 853 | { |
| 854 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 855 | |
| 856 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 857 | |
| 858 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 859 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 860 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 861 | |
| 862 | lpfc_port_link_failure(vport); |
| 863 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 864 | /* Stop delayed Nport discovery */ |
| 865 | spin_lock_irq(shost->host_lock); |
| 866 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 867 | spin_unlock_irq(shost->host_lock); |
| 868 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 869 | } |
| 870 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 872 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 873 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 874 | struct lpfc_vport *vport = phba->pport; |
| 875 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 876 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 877 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 878 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 880 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 881 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 882 | |
| 883 | /* Block all SCSI stack I/Os */ |
| 884 | lpfc_scsi_dev_block(phba); |
| 885 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 886 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 887 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 888 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 889 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 891 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 892 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 893 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 894 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 895 | vports = lpfc_create_vport_work_array(phba); |
| 896 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 897 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 898 | /* Issue a LINK DOWN event to all nodes */ |
| 899 | lpfc_linkdown_port(vports[i]); |
| 900 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 901 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 903 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 904 | if (mb) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 905 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 906 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 907 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 908 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 910 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 915 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 916 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 918 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 920 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 921 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 922 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 924 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | } |
| 926 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 928 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 929 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 931 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 932 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | } |
| 934 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 935 | static void |
| 936 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 938 | struct lpfc_nodelist *ndlp; |
| 939 | |
| 940 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 941 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 942 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 943 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 944 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 945 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 946 | /* On Linkup its safe to clean up the ndlp |
| 947 | * from Fabric connections. |
| 948 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 949 | if (ndlp->nlp_DID != Fabric_DID) |
| 950 | lpfc_unreg_rpi(vport, ndlp); |
| 951 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 952 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 953 | /* Fail outstanding IO now since device is |
| 954 | * marked for PLOGI. |
| 955 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 956 | lpfc_unreg_rpi(vport, ndlp); |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | static void |
| 962 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 963 | { |
| 964 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | struct lpfc_hba *phba = vport->phba; |
| 966 | |
| 967 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 968 | return; |
| 969 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 970 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 971 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 972 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 973 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 974 | /* If NPIV is not enabled, only bring the physical port up */ |
| 975 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 976 | (vport != phba->pport)) |
| 977 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 979 | 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] | 980 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 981 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 983 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 984 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 985 | vport->fc_ns_retry = 0; |
| 986 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | if (vport->fc_flag & FC_LBIT) |
| 989 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | static int |
| 994 | lpfc_linkup(struct lpfc_hba *phba) |
| 995 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 996 | struct lpfc_vport **vports; |
| 997 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 998 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 999 | lpfc_cleanup_wt_rrqs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1000 | phba->link_state = LPFC_LINK_UP; |
| 1001 | |
| 1002 | /* Unblock fabric iocbs if they are blocked */ |
| 1003 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 1004 | del_timer_sync(&phba->fabric_block_timer); |
| 1005 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1006 | vports = lpfc_create_vport_work_array(phba); |
| 1007 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1008 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1009 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1010 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1011 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1012 | (phba->sli_rev < LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1013 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
| 1018 | /* |
| 1019 | * This routine handles processing a CLEAR_LA mailbox |
| 1020 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1021 | * as the completion routine when the command is |
| 1022 | * handed off to the SLI layer. |
| 1023 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1024 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1025 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1027 | struct lpfc_vport *vport = pmb->vport; |
| 1028 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1029 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1030 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | uint32_t control; |
| 1032 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1034 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1036 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 1037 | |
| 1038 | /* Check for error */ |
| 1039 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1040 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1041 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1042 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 1043 | "state x%x\n", |
| 1044 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1045 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | goto out; |
| 1047 | } |
| 1048 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1049 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1050 | phba->link_state = LPFC_HBA_READY; |
| 1051 | |
| 1052 | spin_lock_irq(&phba->hbalock); |
| 1053 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1054 | control = readl(phba->HCregaddr); |
| 1055 | control |= HC_LAINT_ENA; |
| 1056 | writel(control, phba->HCregaddr); |
| 1057 | readl(phba->HCregaddr); /* flush */ |
| 1058 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 1059 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1060 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | out: |
| 1063 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1064 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1065 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1066 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1069 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1070 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1072 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | |
| 1074 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1075 | |
| 1076 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1078 | control = readl(phba->HCregaddr); |
| 1079 | control |= HC_LAINT_ENA; |
| 1080 | writel(control, phba->HCregaddr); |
| 1081 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1082 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1083 | |
| 1084 | return; |
| 1085 | } |
| 1086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1087 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1089 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1091 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1093 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1096 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1097 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1098 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
| 1099 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1100 | !(phba->hba_flag & HBA_FCOE_MODE) && |
| 1101 | (phba->link_flag & LS_LOOPBACK_MODE)) |
| 1102 | return; |
| 1103 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1104 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 1106 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1107 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1109 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 1110 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1112 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1113 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1115 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1116 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 1117 | */ |
James Smart | e644643 | 2012-05-09 21:16:42 -0400 | [diff] [blame] | 1118 | if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1119 | lpfc_initial_flogi(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1120 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | |
| 1122 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1123 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1124 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1125 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1126 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1127 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1128 | |
| 1129 | lpfc_linkdown(phba); |
| 1130 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1131 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1132 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1133 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1135 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | return; |
| 1137 | } |
| 1138 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1139 | /** |
| 1140 | * lpfc_sli4_clear_fcf_rr_bmask |
| 1141 | * @phba pointer to the struct lpfc_hba for this port. |
| 1142 | * This fucnction resets the round robin bit mask and clears the |
| 1143 | * fcf priority list. The list deletions are done while holding the |
| 1144 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared |
| 1145 | * from the lpfc_fcf_pri record. |
| 1146 | **/ |
| 1147 | void |
| 1148 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) |
| 1149 | { |
| 1150 | struct lpfc_fcf_pri *fcf_pri; |
| 1151 | struct lpfc_fcf_pri *next_fcf_pri; |
| 1152 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 1153 | spin_lock_irq(&phba->hbalock); |
| 1154 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 1155 | &phba->fcf.fcf_pri_list, list) { |
| 1156 | list_del_init(&fcf_pri->list); |
| 1157 | fcf_pri->fcf_rec.flag = 0; |
| 1158 | } |
| 1159 | spin_unlock_irq(&phba->hbalock); |
| 1160 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1162 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1163 | { |
| 1164 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1165 | |
| 1166 | if (mboxq->u.mb.mbxStatus) { |
| 1167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1168 | "2017 REG_FCFI mbxStatus error x%x " |
| 1169 | "HBA state x%x\n", |
| 1170 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1171 | goto fail_out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1175 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1176 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1177 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1178 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1179 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1180 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1181 | /* If there is a pending FCoE event, restart FCF table scan. */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1182 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
| 1183 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1184 | goto fail_out; |
| 1185 | |
| 1186 | /* Mark successful completion of FCF table scan */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1187 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1188 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1189 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1190 | if (vport->port_state != LPFC_FLOGI) { |
| 1191 | phba->hba_flag |= FCF_RR_INPROG; |
| 1192 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1193 | lpfc_issue_init_vfi(vport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1194 | goto out; |
| 1195 | } |
| 1196 | spin_unlock_irq(&phba->hbalock); |
| 1197 | goto out; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1198 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1199 | fail_out: |
| 1200 | spin_lock_irq(&phba->hbalock); |
| 1201 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1202 | spin_unlock_irq(&phba->hbalock); |
| 1203 | out: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1204 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /** |
| 1208 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1209 | * @fab_name: pointer to fabric name. |
| 1210 | * @new_fcf_record: pointer to fcf record. |
| 1211 | * |
| 1212 | * This routine compare the fcf record's fabric name with provided |
| 1213 | * fabric name. If the fabric name are identical this function |
| 1214 | * returns 1 else return 0. |
| 1215 | **/ |
| 1216 | static uint32_t |
| 1217 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1218 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1219 | 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] | 1220 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1221 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1222 | return 0; |
| 1223 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1224 | return 0; |
| 1225 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1226 | return 0; |
| 1227 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1228 | return 0; |
| 1229 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1230 | return 0; |
| 1231 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1232 | return 0; |
| 1233 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1234 | return 0; |
| 1235 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1239 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1240 | * @fab_name: pointer to fabric name. |
| 1241 | * @new_fcf_record: pointer to fcf record. |
| 1242 | * |
| 1243 | * This routine compare the fcf record's switch name with provided |
| 1244 | * switch name. If the switch name are identical this function |
| 1245 | * returns 1 else return 0. |
| 1246 | **/ |
| 1247 | static uint32_t |
| 1248 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1249 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1250 | 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] | 1251 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1252 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1253 | return 0; |
| 1254 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1255 | return 0; |
| 1256 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1257 | return 0; |
| 1258 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1259 | return 0; |
| 1260 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1261 | return 0; |
| 1262 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1263 | return 0; |
| 1264 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1265 | return 0; |
| 1266 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1270 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1271 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1272 | * @new_fcf_record: pointer to fcf record. |
| 1273 | * |
| 1274 | * This routine compare the fcf record's mac address with HBA's |
| 1275 | * FCF mac address. If the mac addresses are identical this function |
| 1276 | * returns 1 else return 0. |
| 1277 | **/ |
| 1278 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1279 | 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] | 1280 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1281 | 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] | 1282 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1283 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1284 | return 0; |
| 1285 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1286 | return 0; |
| 1287 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1288 | return 0; |
| 1289 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1290 | return 0; |
| 1291 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1292 | return 0; |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | static bool |
| 1297 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1298 | { |
| 1299 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1303 | * lpfc_update_fcf_record - Update driver fcf record |
| 1304 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. |
| 1305 | * @phba: pointer to lpfc hba data structure. |
| 1306 | * @fcf_index: Index for the lpfc_fcf_record. |
| 1307 | * @new_fcf_record: pointer to hba fcf record. |
| 1308 | * |
| 1309 | * This routine updates the driver FCF priority record from the new HBA FCF |
| 1310 | * record. This routine is called with the host lock held. |
| 1311 | **/ |
| 1312 | static void |
| 1313 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, |
| 1314 | struct fcf_record *new_fcf_record |
| 1315 | ) |
| 1316 | { |
| 1317 | struct lpfc_fcf_pri *fcf_pri; |
| 1318 | |
| 1319 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1320 | fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 1321 | /* FCF record priority */ |
| 1322 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 1323 | |
| 1324 | } |
| 1325 | |
| 1326 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1327 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1328 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1329 | * @new_fcf_record: pointer to fcf record. |
| 1330 | * |
| 1331 | * This routine copies the FCF information from the FCF |
| 1332 | * record to lpfc_hba data structure. |
| 1333 | **/ |
| 1334 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1335 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1336 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1337 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1338 | /* Fabric name */ |
| 1339 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1340 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1341 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1342 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1343 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1344 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1345 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1346 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1347 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1348 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1349 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1350 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1351 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1352 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1353 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1354 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1355 | /* Mac address */ |
| 1356 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1357 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1358 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1359 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1360 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1361 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1362 | /* FCF record index */ |
| 1363 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1364 | /* FCF record priority */ |
| 1365 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1366 | /* Switch name */ |
| 1367 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1368 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1369 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1370 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1371 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1372 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1373 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1374 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1375 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1376 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1377 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1378 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1379 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1380 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1381 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1382 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1386 | * lpfc_update_fcf_record - Update driver fcf record |
| 1387 | * @phba: pointer to lpfc hba data structure. |
| 1388 | * @fcf_rec: pointer to driver fcf record. |
| 1389 | * @new_fcf_record: pointer to hba fcf record. |
| 1390 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1391 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1392 | * @flag: flag bits to be set to the driver fcf record. |
| 1393 | * |
| 1394 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1395 | * together with the address mode, vlan_id, and other informations. This |
| 1396 | * routine is called with the host lock held. |
| 1397 | **/ |
| 1398 | static void |
| 1399 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1400 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1401 | uint16_t vlan_id, uint32_t flag) |
| 1402 | { |
| 1403 | /* Copy the fields from the HBA's FCF record */ |
| 1404 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1405 | /* Update other fields of driver FCF record */ |
| 1406 | fcf_rec->addr_mode = addr_mode; |
| 1407 | fcf_rec->vlan_id = vlan_id; |
| 1408 | fcf_rec->flag |= (flag | RECORD_VALID); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1409 | __lpfc_update_fcf_record_pri(phba, |
| 1410 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), |
| 1411 | new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1415 | * lpfc_register_fcf - Register the FCF with hba. |
| 1416 | * @phba: pointer to lpfc hba data structure. |
| 1417 | * |
| 1418 | * This routine issues a register fcfi mailbox command to register |
| 1419 | * the fcf with HBA. |
| 1420 | **/ |
| 1421 | static void |
| 1422 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1423 | { |
| 1424 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1425 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1426 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1427 | spin_lock_irq(&phba->hbalock); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1428 | /* If the FCF is not available do nothing. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1429 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1430 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1431 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1432 | return; |
| 1433 | } |
| 1434 | |
| 1435 | /* The FCF is already registered, start discovery */ |
| 1436 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1437 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1438 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 1439 | if (phba->pport->port_state != LPFC_FLOGI) { |
| 1440 | phba->hba_flag |= FCF_RR_INPROG; |
| 1441 | spin_unlock_irq(&phba->hbalock); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 1442 | lpfc_initial_flogi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1443 | return; |
| 1444 | } |
| 1445 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1448 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1449 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1450 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1451 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1452 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1453 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1454 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1455 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1456 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1457 | |
| 1458 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1459 | fcf_mbxq->vport = phba->pport; |
| 1460 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1461 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1462 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1463 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1464 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1465 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1466 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1467 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1468 | |
| 1469 | return; |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1474 | * @phba: pointer to lpfc hba data structure. |
| 1475 | * @new_fcf_record: pointer to fcf record. |
| 1476 | * @boot_flag: Indicates if this record used by boot bios. |
| 1477 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1478 | * @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] | 1479 | * |
| 1480 | * This routine compare the fcf record with connect list obtained from the |
| 1481 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1482 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1483 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1484 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1485 | * used for this FCF when the function returns. |
| 1486 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1487 | * 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] | 1488 | * 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] | 1489 | **/ |
| 1490 | static int |
| 1491 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1492 | struct fcf_record *new_fcf_record, |
| 1493 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1494 | uint16_t *vlan_id) |
| 1495 | { |
| 1496 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1497 | int i, j, fcf_vlan_id = 0; |
| 1498 | |
| 1499 | /* Find the lowest VLAN id in the FCF record */ |
| 1500 | for (i = 0; i < 512; i++) { |
| 1501 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1502 | fcf_vlan_id = i * 8; |
| 1503 | j = 0; |
| 1504 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1505 | j++; |
| 1506 | fcf_vlan_id++; |
| 1507 | } |
| 1508 | break; |
| 1509 | } |
| 1510 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1511 | |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1512 | /* FCF not valid/available or solicitation in progress */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1513 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1514 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
| 1515 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1516 | return 0; |
| 1517 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1518 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1519 | *boot_flag = 0; |
| 1520 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1521 | new_fcf_record); |
| 1522 | if (phba->valid_vlan) |
| 1523 | *vlan_id = phba->vlan_id; |
| 1524 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1525 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1526 | return 1; |
| 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | * If there are no FCF connection table entry, driver connect to all |
| 1531 | * FCFs. |
| 1532 | */ |
| 1533 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1534 | *boot_flag = 0; |
| 1535 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1536 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1537 | |
| 1538 | /* |
| 1539 | * When there are no FCF connect entries, use driver's default |
| 1540 | * addressing mode - FPMA. |
| 1541 | */ |
| 1542 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1543 | *addr_mode = LPFC_FCF_FPMA; |
| 1544 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1545 | /* If FCF record report a vlan id use that vlan id */ |
| 1546 | if (fcf_vlan_id) |
| 1547 | *vlan_id = fcf_vlan_id; |
| 1548 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1549 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1550 | return 1; |
| 1551 | } |
| 1552 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1553 | list_for_each_entry(conn_entry, |
| 1554 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1555 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1556 | continue; |
| 1557 | |
| 1558 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1559 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1560 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1561 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1562 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1563 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1564 | new_fcf_record)) |
| 1565 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1566 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1567 | /* |
| 1568 | * If the vlan bit map does not have the bit set for the |
| 1569 | * vlan id to be used, then it is not a match. |
| 1570 | */ |
| 1571 | if (!(new_fcf_record->vlan_bitmap |
| 1572 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1573 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1574 | continue; |
| 1575 | } |
| 1576 | |
| 1577 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1578 | * If connection record does not support any addressing mode, |
| 1579 | * skip the FCF record. |
| 1580 | */ |
| 1581 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1582 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1583 | continue; |
| 1584 | |
| 1585 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1586 | * Check if the connection record specifies a required |
| 1587 | * addressing mode. |
| 1588 | */ |
| 1589 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1590 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1591 | |
| 1592 | /* |
| 1593 | * If SPMA required but FCF not support this continue. |
| 1594 | */ |
| 1595 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1596 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1597 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1598 | continue; |
| 1599 | |
| 1600 | /* |
| 1601 | * If FPMA required but FCF not support this continue. |
| 1602 | */ |
| 1603 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1604 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1605 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1606 | continue; |
| 1607 | } |
| 1608 | |
| 1609 | /* |
| 1610 | * This fcf record matches filtering criteria. |
| 1611 | */ |
| 1612 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1613 | *boot_flag = 1; |
| 1614 | else |
| 1615 | *boot_flag = 0; |
| 1616 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1617 | /* |
| 1618 | * If user did not specify any addressing mode, or if the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1619 | * preferred addressing mode specified by user is not supported |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1620 | * by FCF, allow fabric to pick the addressing mode. |
| 1621 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1622 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1623 | new_fcf_record); |
| 1624 | /* |
| 1625 | * If the user specified a required address mode, assign that |
| 1626 | * address mode |
| 1627 | */ |
| 1628 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1629 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1630 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1631 | FCFCNCT_AM_SPMA) ? |
| 1632 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1633 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1634 | * If the user specified a preferred address mode, use the |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1635 | * addr mode only if FCF support the addr_mode. |
| 1636 | */ |
| 1637 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1638 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1639 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1640 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1641 | *addr_mode = LPFC_FCF_SPMA; |
| 1642 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1643 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1644 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1645 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1646 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1647 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1648 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1649 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1650 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1651 | /* |
| 1652 | * If no vlan id is specified in connect list, use the vlan id |
| 1653 | * in the FCF record |
| 1654 | */ |
| 1655 | else if (fcf_vlan_id) |
| 1656 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1657 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1658 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1659 | |
| 1660 | return 1; |
| 1661 | } |
| 1662 | |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1667 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1668 | * @phba: pointer to lpfc hba data structure. |
| 1669 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1670 | * |
| 1671 | * This function check if there is any fcoe event pending while driver |
| 1672 | * scan FCF entries. If there is any pending event, it will restart the |
| 1673 | * FCF saning and return 1 else return 0. |
| 1674 | */ |
| 1675 | int |
| 1676 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1677 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1678 | /* |
| 1679 | * If the Link is up and no FCoE events while in the |
| 1680 | * FCF discovery, no need to restart FCF discovery. |
| 1681 | */ |
| 1682 | if ((phba->link_state >= LPFC_LINK_UP) && |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1683 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1684 | return 0; |
| 1685 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1686 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1687 | "2768 Pending link or FCF event during current " |
| 1688 | "handling of the previous event: link_state:x%x, " |
| 1689 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1690 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1691 | phba->fcoe_eventtag); |
| 1692 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1693 | spin_lock_irq(&phba->hbalock); |
| 1694 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1695 | spin_unlock_irq(&phba->hbalock); |
| 1696 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1697 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1698 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1699 | "2780 Restart FCF table scan due to " |
| 1700 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1701 | "evt_tag_current:x%x\n", |
| 1702 | phba->fcoe_eventtag_at_fcf_scan, |
| 1703 | phba->fcoe_eventtag); |
| 1704 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1705 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1706 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1707 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1708 | * flag |
| 1709 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1710 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1711 | "2833 Stop FCF discovery process due to link " |
| 1712 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1713 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1714 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1715 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1716 | spin_unlock_irq(&phba->hbalock); |
| 1717 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1718 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1719 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1720 | if (unreg_fcf) { |
| 1721 | spin_lock_irq(&phba->hbalock); |
| 1722 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1723 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1724 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1725 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1726 | return 1; |
| 1727 | } |
| 1728 | |
| 1729 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1730 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1731 | * @phba: pointer to lpfc hba data structure. |
| 1732 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1733 | * |
| 1734 | * This function makes an running random selection decision on FCF record to |
| 1735 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1736 | * probability. To perform integer manunipulation of random numbers with |
| 1737 | * size unit32_t, the lower 16 bits of the 32-bit random number returned |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1738 | * from prandom_u32() are taken as the random random number generated. |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1739 | * |
| 1740 | * Returns true when outcome is for the newly read FCF record should be |
| 1741 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1742 | * chosen FCF record. |
| 1743 | **/ |
| 1744 | static bool |
| 1745 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1746 | { |
| 1747 | uint32_t rand_num; |
| 1748 | |
| 1749 | /* Get 16-bit uniform random number */ |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 1750 | rand_num = 0xFFFF & prandom_u32(); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1751 | |
| 1752 | /* Decision with probability 1/fcf_cnt */ |
| 1753 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1754 | return true; |
| 1755 | else |
| 1756 | return false; |
| 1757 | } |
| 1758 | |
| 1759 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1760 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1761 | * @phba: pointer to lpfc hba data structure. |
| 1762 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1763 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1764 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1765 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1766 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1767 | * SGE parsing, and endianness swapping. |
| 1768 | * |
| 1769 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1770 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1771 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1772 | static struct fcf_record * |
| 1773 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1774 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1775 | { |
| 1776 | void *virt_addr; |
| 1777 | dma_addr_t phys_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1778 | struct lpfc_mbx_sge sge; |
| 1779 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1780 | uint32_t shdr_status, shdr_add_status; |
| 1781 | union lpfc_sli4_cfg_shdr *shdr; |
| 1782 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1783 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1784 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1785 | * routine only uses a single SGE. |
| 1786 | */ |
| 1787 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1788 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1789 | if (unlikely(!mboxq->sge_array)) { |
| 1790 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1791 | "2524 Failed to get the non-embedded SGE " |
| 1792 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1793 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1794 | } |
| 1795 | virt_addr = mboxq->sge_array->addr[0]; |
| 1796 | |
| 1797 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 1798 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
| 1799 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1800 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1801 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1802 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1803 | if (shdr_status == STATUS_FCF_TABLE_EMPTY) |
| 1804 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1805 | "2726 READ_FCF_RECORD Indicates empty " |
| 1806 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1807 | else |
| 1808 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1809 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1810 | "with status x%x add_status x%x, " |
| 1811 | "mbx\n", shdr_status, shdr_add_status); |
| 1812 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1813 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1814 | |
| 1815 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1816 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1817 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1818 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1819 | *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] | 1820 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1821 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1822 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1823 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1824 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1825 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1826 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1827 | return new_fcf_record; |
| 1828 | } |
| 1829 | |
| 1830 | /** |
| 1831 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1832 | * @phba: pointer to lpfc hba data structure. |
| 1833 | * @fcf_record: pointer to the fcf record. |
| 1834 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1835 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1836 | * |
| 1837 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1838 | * enabled. |
| 1839 | **/ |
| 1840 | static void |
| 1841 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1842 | struct fcf_record *fcf_record, |
| 1843 | uint16_t vlan_id, |
| 1844 | uint16_t next_fcf_index) |
| 1845 | { |
| 1846 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1847 | "2764 READ_FCF_RECORD:\n" |
| 1848 | "\tFCF_Index : x%x\n" |
| 1849 | "\tFCF_Avail : x%x\n" |
| 1850 | "\tFCF_Valid : x%x\n" |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1851 | "\tFCF_SOL : x%x\n" |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1852 | "\tFIP_Priority : x%x\n" |
| 1853 | "\tMAC_Provider : x%x\n" |
| 1854 | "\tLowest VLANID : x%x\n" |
| 1855 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1856 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1857 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1858 | "\tNext_FCF_Index: x%x\n", |
| 1859 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1860 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1861 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 1862 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1863 | fcf_record->fip_priority, |
| 1864 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1865 | vlan_id, |
| 1866 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1867 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1868 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1869 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1870 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1871 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1872 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1873 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1874 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1875 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1876 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1877 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1878 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1879 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1880 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1881 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1882 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1883 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1884 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1885 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1886 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1887 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1888 | next_fcf_index); |
| 1889 | } |
| 1890 | |
| 1891 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1892 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1893 | * @phba: pointer to lpfc hba data structure. |
| 1894 | * @fcf_rec: pointer to an existing FCF record. |
| 1895 | * @new_fcf_record: pointer to a new FCF record. |
| 1896 | * @new_vlan_id: vlan id from the new FCF record. |
| 1897 | * |
| 1898 | * This function performs matching test of a new FCF record against an existing |
| 1899 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1900 | * will not be used as part of the FCF record matching criteria. |
| 1901 | * |
| 1902 | * Returns true if all the fields matching, otherwise returns false. |
| 1903 | */ |
| 1904 | static bool |
| 1905 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1906 | struct lpfc_fcf_rec *fcf_rec, |
| 1907 | struct fcf_record *new_fcf_record, |
| 1908 | uint16_t new_vlan_id) |
| 1909 | { |
| 1910 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1911 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1912 | return false; |
| 1913 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1914 | return false; |
| 1915 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1916 | return false; |
| 1917 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1918 | return false; |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1919 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
| 1920 | return false; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1921 | return true; |
| 1922 | } |
| 1923 | |
| 1924 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1925 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf |
| 1926 | * @vport: Pointer to vport object. |
| 1927 | * @fcf_index: index to next fcf. |
| 1928 | * |
| 1929 | * This function processing the roundrobin fcf failover to next fcf index. |
| 1930 | * When this function is invoked, there will be a current fcf registered |
| 1931 | * for flogi. |
| 1932 | * Return: 0 for continue retrying flogi on currently registered fcf; |
| 1933 | * 1 for stop flogi on currently registered fcf; |
| 1934 | */ |
| 1935 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) |
| 1936 | { |
| 1937 | struct lpfc_hba *phba = vport->phba; |
| 1938 | int rc; |
| 1939 | |
| 1940 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 1941 | spin_lock_irq(&phba->hbalock); |
| 1942 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 1943 | spin_unlock_irq(&phba->hbalock); |
| 1944 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1945 | "2872 Devloss tmo with no eligible " |
| 1946 | "FCF, unregister in-use FCF (x%x) " |
| 1947 | "and rescan FCF table\n", |
| 1948 | phba->fcf.current_rec.fcf_indx); |
| 1949 | lpfc_unregister_fcf_rescan(phba); |
| 1950 | goto stop_flogi_current_fcf; |
| 1951 | } |
| 1952 | /* Mark the end to FLOGI roundrobin failover */ |
| 1953 | phba->hba_flag &= ~FCF_RR_INPROG; |
| 1954 | /* Allow action to new fcf asynchronous event */ |
| 1955 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 1956 | spin_unlock_irq(&phba->hbalock); |
| 1957 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1958 | "2865 No FCF available, stop roundrobin FCF " |
| 1959 | "failover and change port state:x%x/x%x\n", |
| 1960 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); |
| 1961 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 1962 | goto stop_flogi_current_fcf; |
| 1963 | } else { |
| 1964 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, |
| 1965 | "2794 Try FLOGI roundrobin FCF failover to " |
| 1966 | "(x%x)\n", fcf_index); |
| 1967 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); |
| 1968 | if (rc) |
| 1969 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 1970 | "2761 FLOGI roundrobin FCF failover " |
| 1971 | "failed (rc:x%x) to read FCF (x%x)\n", |
| 1972 | rc, phba->fcf.current_rec.fcf_indx); |
| 1973 | else |
| 1974 | goto stop_flogi_current_fcf; |
| 1975 | } |
| 1976 | return 0; |
| 1977 | |
| 1978 | stop_flogi_current_fcf: |
| 1979 | lpfc_can_disctmo(vport); |
| 1980 | return 1; |
| 1981 | } |
| 1982 | |
| 1983 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 1984 | * lpfc_sli4_fcf_pri_list_del |
| 1985 | * @phba: pointer to lpfc hba data structure. |
| 1986 | * @fcf_index the index of the fcf record to delete |
| 1987 | * This routine checks the on list flag of the fcf_index to be deleted. |
| 1988 | * If it is one the list then it is removed from the list, and the flag |
| 1989 | * is cleared. This routine grab the hbalock before removing the fcf |
| 1990 | * record from the list. |
| 1991 | **/ |
| 1992 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, |
| 1993 | uint16_t fcf_index) |
| 1994 | { |
| 1995 | struct lpfc_fcf_pri *new_fcf_pri; |
| 1996 | |
| 1997 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 1998 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1999 | "3058 deleting idx x%x pri x%x flg x%x\n", |
| 2000 | fcf_index, new_fcf_pri->fcf_rec.priority, |
| 2001 | new_fcf_pri->fcf_rec.flag); |
| 2002 | spin_lock_irq(&phba->hbalock); |
| 2003 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { |
| 2004 | if (phba->fcf.current_rec.priority == |
| 2005 | new_fcf_pri->fcf_rec.priority) |
| 2006 | phba->fcf.eligible_fcf_cnt--; |
| 2007 | list_del_init(&new_fcf_pri->list); |
| 2008 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; |
| 2009 | } |
| 2010 | spin_unlock_irq(&phba->hbalock); |
| 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * lpfc_sli4_set_fcf_flogi_fail |
| 2015 | * @phba: pointer to lpfc hba data structure. |
| 2016 | * @fcf_index the index of the fcf record to update |
| 2017 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED |
| 2018 | * flag so the the round robin slection for the particular priority level |
| 2019 | * will try a different fcf record that does not have this bit set. |
| 2020 | * If the fcf record is re-read for any reason this flag is cleared brfore |
| 2021 | * adding it to the priority list. |
| 2022 | **/ |
| 2023 | void |
| 2024 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) |
| 2025 | { |
| 2026 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2027 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2028 | spin_lock_irq(&phba->hbalock); |
| 2029 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; |
| 2030 | spin_unlock_irq(&phba->hbalock); |
| 2031 | } |
| 2032 | |
| 2033 | /** |
| 2034 | * lpfc_sli4_fcf_pri_list_add |
| 2035 | * @phba: pointer to lpfc hba data structure. |
| 2036 | * @fcf_index the index of the fcf record to add |
| 2037 | * This routine checks the priority of the fcf_index to be added. |
| 2038 | * If it is a lower priority than the current head of the fcf_pri list |
| 2039 | * then it is added to the list in the right order. |
| 2040 | * If it is the same priority as the current head of the list then it |
| 2041 | * is added to the head of the list and its bit in the rr_bmask is set. |
| 2042 | * If the fcf_index to be added is of a higher priority than the current |
| 2043 | * head of the list then the rr_bmask is cleared, its bit is set in the |
| 2044 | * rr_bmask and it is added to the head of the list. |
| 2045 | * returns: |
| 2046 | * 0=success 1=failure |
| 2047 | **/ |
| 2048 | int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, uint16_t fcf_index, |
| 2049 | struct fcf_record *new_fcf_record) |
| 2050 | { |
| 2051 | uint16_t current_fcf_pri; |
| 2052 | uint16_t last_index; |
| 2053 | struct lpfc_fcf_pri *fcf_pri; |
| 2054 | struct lpfc_fcf_pri *next_fcf_pri; |
| 2055 | struct lpfc_fcf_pri *new_fcf_pri; |
| 2056 | int ret; |
| 2057 | |
| 2058 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
| 2059 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2060 | "3059 adding idx x%x pri x%x flg x%x\n", |
| 2061 | fcf_index, new_fcf_record->fip_priority, |
| 2062 | new_fcf_pri->fcf_rec.flag); |
| 2063 | spin_lock_irq(&phba->hbalock); |
| 2064 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) |
| 2065 | list_del_init(&new_fcf_pri->list); |
| 2066 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; |
| 2067 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; |
| 2068 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 2069 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2070 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2071 | new_fcf_pri->fcf_rec.fcf_index); |
| 2072 | goto out; |
| 2073 | } |
| 2074 | |
| 2075 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 2076 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 2077 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 2078 | ret = 0; /* Empty rr list */ |
| 2079 | goto out; |
| 2080 | } |
| 2081 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; |
| 2082 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { |
| 2083 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); |
| 2084 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { |
| 2085 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2086 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 2087 | /* fcfs_at_this_priority_level = 1; */ |
| 2088 | phba->fcf.eligible_fcf_cnt = 1; |
| 2089 | } else |
| 2090 | /* fcfs_at_this_priority_level++; */ |
| 2091 | phba->fcf.eligible_fcf_cnt++; |
| 2092 | ret = lpfc_sli4_fcf_rr_index_set(phba, |
| 2093 | new_fcf_pri->fcf_rec.fcf_index); |
| 2094 | goto out; |
| 2095 | } |
| 2096 | |
| 2097 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, |
| 2098 | &phba->fcf.fcf_pri_list, list) { |
| 2099 | if (new_fcf_pri->fcf_rec.priority <= |
| 2100 | fcf_pri->fcf_rec.priority) { |
| 2101 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) |
| 2102 | list_add(&new_fcf_pri->list, |
| 2103 | &phba->fcf.fcf_pri_list); |
| 2104 | else |
| 2105 | list_add(&new_fcf_pri->list, |
| 2106 | &((struct lpfc_fcf_pri *) |
| 2107 | fcf_pri->list.prev)->list); |
| 2108 | ret = 0; |
| 2109 | goto out; |
| 2110 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list |
| 2111 | || new_fcf_pri->fcf_rec.priority < |
| 2112 | next_fcf_pri->fcf_rec.priority) { |
| 2113 | list_add(&new_fcf_pri->list, &fcf_pri->list); |
| 2114 | ret = 0; |
| 2115 | goto out; |
| 2116 | } |
| 2117 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) |
| 2118 | continue; |
| 2119 | |
| 2120 | } |
| 2121 | ret = 1; |
| 2122 | out: |
| 2123 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ |
| 2124 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; |
| 2125 | spin_unlock_irq(&phba->hbalock); |
| 2126 | return ret; |
| 2127 | } |
| 2128 | |
| 2129 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2130 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 2131 | * @phba: pointer to lpfc hba data structure. |
| 2132 | * @mboxq: pointer to mailbox object. |
| 2133 | * |
| 2134 | * This function iterates through all the fcf records available in |
| 2135 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 2136 | * the FCF for discovery it registers the FCF record and kicks start |
| 2137 | * discovery. |
| 2138 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 2139 | * use an FCF record which matches fabric name and mac address of the |
| 2140 | * currently used FCF record. |
| 2141 | * If the driver supports only one FCF, it will try to use the FCF record |
| 2142 | * used by BOOT_BIOS. |
| 2143 | */ |
| 2144 | void |
| 2145 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2146 | { |
| 2147 | struct fcf_record *new_fcf_record; |
| 2148 | uint32_t boot_flag, addr_mode; |
| 2149 | uint16_t fcf_index, next_fcf_index; |
| 2150 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 2151 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2152 | uint32_t seed; |
| 2153 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2154 | int rc; |
| 2155 | |
| 2156 | /* If there is pending FCoE event restart FCF table scan */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2157 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2158 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2159 | return; |
| 2160 | } |
| 2161 | |
| 2162 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2163 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2164 | &next_fcf_index); |
| 2165 | if (!new_fcf_record) { |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2166 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2167 | "2765 Mailbox command READ_FCF_RECORD " |
| 2168 | "failed to retrieve a FCF record.\n"); |
| 2169 | /* Let next new FCF event trigger fast failover */ |
| 2170 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2171 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2172 | spin_unlock_irq(&phba->hbalock); |
| 2173 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2174 | return; |
| 2175 | } |
| 2176 | |
| 2177 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2178 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2179 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2180 | |
| 2181 | /* Log the FCF record information if turned on */ |
| 2182 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2183 | next_fcf_index); |
| 2184 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2185 | /* |
| 2186 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2187 | * read the next entry; otherwise, this is an eligible FCF |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2188 | * record for roundrobin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2189 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2190 | if (!rc) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2191 | lpfc_sli4_fcf_pri_list_del(phba, |
| 2192 | bf_get(lpfc_fcf_record_fcf_index, |
| 2193 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2194 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2195 | "2781 FCF (x%x) failed connection " |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2196 | "list check: (x%x/x%x/%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2197 | bf_get(lpfc_fcf_record_fcf_index, |
| 2198 | new_fcf_record), |
| 2199 | bf_get(lpfc_fcf_record_fcf_avail, |
| 2200 | new_fcf_record), |
| 2201 | bf_get(lpfc_fcf_record_fcf_valid, |
James Smart | 26979ce | 2012-09-29 11:31:55 -0400 | [diff] [blame] | 2202 | new_fcf_record), |
| 2203 | bf_get(lpfc_fcf_record_fcf_sol, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2204 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2205 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 2206 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 2207 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2208 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
| 2209 | phba->fcf.current_rec.fcf_indx) { |
| 2210 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2211 | "2862 FCF (x%x) matches property " |
| 2212 | "of in-use FCF (x%x)\n", |
| 2213 | bf_get(lpfc_fcf_record_fcf_index, |
| 2214 | new_fcf_record), |
| 2215 | phba->fcf.current_rec.fcf_indx); |
| 2216 | goto read_next_fcf; |
| 2217 | } |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2218 | /* |
| 2219 | * In case the current in-use FCF record becomes |
| 2220 | * invalid/unavailable during FCF discovery that |
| 2221 | * was not triggered by fast FCF failover process, |
| 2222 | * treat it as fast FCF failover. |
| 2223 | */ |
| 2224 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 2225 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 2226 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2227 | "2835 Invalid in-use FCF " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2228 | "(x%x), enter FCF failover " |
| 2229 | "table scan.\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2230 | phba->fcf.current_rec.fcf_indx); |
| 2231 | spin_lock_irq(&phba->hbalock); |
| 2232 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2233 | spin_unlock_irq(&phba->hbalock); |
| 2234 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2235 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2236 | LPFC_FCOE_FCF_GET_FIRST); |
| 2237 | return; |
| 2238 | } |
| 2239 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2240 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2241 | } else { |
| 2242 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2243 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
| 2244 | new_fcf_record); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2245 | if (rc) |
| 2246 | goto read_next_fcf; |
| 2247 | } |
| 2248 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2249 | /* |
| 2250 | * 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] | 2251 | * FCF record for the discovery. The condition that a rescan |
| 2252 | * matches the in-use FCF record: fabric name, switch name, mac |
| 2253 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2254 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2255 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2256 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2257 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2258 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2259 | new_fcf_record, vlan_id)) { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2260 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
| 2261 | phba->fcf.current_rec.fcf_indx) { |
| 2262 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 2263 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 2264 | /* Stop FCF redisc wait timer */ |
| 2265 | __lpfc_sli4_stop_fcf_redisc_wait_timer( |
| 2266 | phba); |
| 2267 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2268 | /* Fast failover, mark completed */ |
| 2269 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2270 | spin_unlock_irq(&phba->hbalock); |
| 2271 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2272 | "2836 New FCF matches in-use " |
| 2273 | "FCF (x%x)\n", |
| 2274 | phba->fcf.current_rec.fcf_indx); |
| 2275 | goto out; |
| 2276 | } else |
| 2277 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 2278 | "2863 New FCF (x%x) matches " |
| 2279 | "property of in-use FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2280 | bf_get(lpfc_fcf_record_fcf_index, |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2281 | new_fcf_record), |
| 2282 | phba->fcf.current_rec.fcf_indx); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2283 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2284 | /* |
| 2285 | * Read next FCF record from HBA searching for the matching |
| 2286 | * with in-use record only if not during the fast failover |
| 2287 | * period. In case of fast failover period, it shall try to |
| 2288 | * determine whether the FCF record just read should be the |
| 2289 | * next candidate. |
| 2290 | */ |
| 2291 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2292 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2293 | goto read_next_fcf; |
| 2294 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2295 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2296 | /* |
| 2297 | * Update on failover FCF record only if it's in FCF fast-failover |
| 2298 | * period; otherwise, update on current FCF record. |
| 2299 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2300 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 2301 | fcf_rec = &phba->fcf.failover_rec; |
| 2302 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2303 | fcf_rec = &phba->fcf.current_rec; |
| 2304 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2305 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 2306 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2307 | * If the driver FCF record does not have boot flag |
| 2308 | * set and new hba fcf record has boot flag set, use |
| 2309 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2310 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2311 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 2312 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2313 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2314 | "2837 Update current FCF record " |
| 2315 | "(x%x) with new FCF record (x%x)\n", |
| 2316 | fcf_rec->fcf_indx, |
| 2317 | bf_get(lpfc_fcf_record_fcf_index, |
| 2318 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2319 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2320 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2321 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2322 | goto read_next_fcf; |
| 2323 | } |
| 2324 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2325 | * If the driver FCF record has boot flag set and the |
| 2326 | * new hba FCF record does not have boot flag, read |
| 2327 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2328 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2329 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2330 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2331 | goto read_next_fcf; |
| 2332 | } |
| 2333 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2334 | * If the new hba FCF record has lower priority value |
| 2335 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2336 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 2337 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2338 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2339 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2340 | "2838 Update current FCF record " |
| 2341 | "(x%x) with new FCF record (x%x)\n", |
| 2342 | fcf_rec->fcf_indx, |
| 2343 | bf_get(lpfc_fcf_record_fcf_index, |
| 2344 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2345 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2346 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2347 | /* Reset running random FCF selection count */ |
| 2348 | phba->fcf.eligible_fcf_cnt = 1; |
| 2349 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 2350 | /* Update running random FCF selection count */ |
| 2351 | phba->fcf.eligible_fcf_cnt++; |
| 2352 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 2353 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2354 | if (select_new_fcf) { |
| 2355 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2356 | "2839 Update current FCF record " |
| 2357 | "(x%x) with new FCF record (x%x)\n", |
| 2358 | fcf_rec->fcf_indx, |
| 2359 | bf_get(lpfc_fcf_record_fcf_index, |
| 2360 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2361 | /* Choose the new FCF by random selection */ |
| 2362 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 2363 | new_fcf_record, |
| 2364 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2365 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2366 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2367 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2368 | goto read_next_fcf; |
| 2369 | } |
| 2370 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2371 | * This is the first suitable FCF record, choose this record for |
| 2372 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2373 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2374 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2375 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2376 | "2840 Update initial FCF candidate " |
| 2377 | "with FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2378 | bf_get(lpfc_fcf_record_fcf_index, |
| 2379 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2380 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 2381 | addr_mode, vlan_id, (boot_flag ? |
| 2382 | BOOT_ENABLE : 0)); |
| 2383 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 2384 | /* Setup initial running random FCF selection count */ |
| 2385 | phba->fcf.eligible_fcf_cnt = 1; |
| 2386 | /* Seeding the random number generator for random selection */ |
| 2387 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 2388 | prandom_seed(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2389 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2390 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2391 | goto read_next_fcf; |
| 2392 | |
| 2393 | read_next_fcf: |
| 2394 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2395 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 2396 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 2397 | /* |
| 2398 | * Case of FCF fast failover scan |
| 2399 | */ |
| 2400 | |
| 2401 | /* |
| 2402 | * It has not found any suitable FCF record, cancel |
| 2403 | * FCF scan inprogress, and do nothing |
| 2404 | */ |
| 2405 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2406 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2407 | "2782 No suitable FCF found: " |
| 2408 | "(x%x/x%x)\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2409 | phba->fcoe_eventtag_at_fcf_scan, |
| 2410 | bf_get(lpfc_fcf_record_fcf_index, |
| 2411 | new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2412 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2413 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { |
| 2414 | phba->hba_flag &= ~FCF_TS_INPROG; |
| 2415 | spin_unlock_irq(&phba->hbalock); |
| 2416 | /* Unregister in-use FCF and rescan */ |
| 2417 | lpfc_printf_log(phba, KERN_INFO, |
| 2418 | LOG_FIP, |
| 2419 | "2864 On devloss tmo " |
| 2420 | "unreg in-use FCF and " |
| 2421 | "rescan FCF table\n"); |
| 2422 | lpfc_unregister_fcf_rescan(phba); |
| 2423 | return; |
| 2424 | } |
| 2425 | /* |
| 2426 | * Let next new FCF event trigger fast failover |
| 2427 | */ |
| 2428 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2429 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2430 | return; |
| 2431 | } |
| 2432 | /* |
| 2433 | * It has found a suitable FCF record that is not |
| 2434 | * the same as in-use FCF record, unregister the |
| 2435 | * in-use FCF record, replace the in-use FCF record |
| 2436 | * with the new FCF record, mark FCF fast failover |
| 2437 | * completed, and then start register the new FCF |
| 2438 | * record. |
| 2439 | */ |
| 2440 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2441 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2442 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2443 | |
| 2444 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2445 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2446 | "2842 Replace in-use FCF (x%x) " |
| 2447 | "with failover FCF (x%x)\n", |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2448 | phba->fcf.current_rec.fcf_indx, |
| 2449 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2450 | memcpy(&phba->fcf.current_rec, |
| 2451 | &phba->fcf.failover_rec, |
| 2452 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2453 | /* |
| 2454 | * Mark the fast FCF failover rediscovery completed |
| 2455 | * and the start of the first round of the roundrobin |
| 2456 | * FCF failover. |
| 2457 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2458 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2459 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2460 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2461 | /* Register to the new FCF record */ |
| 2462 | lpfc_register_fcf(phba); |
| 2463 | } else { |
| 2464 | /* |
| 2465 | * In case of transaction period to fast FCF failover, |
| 2466 | * do nothing when search to the end of the FCF table. |
| 2467 | */ |
| 2468 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2469 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2470 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2471 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2472 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
| 2473 | phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2474 | /* |
| 2475 | * In case the current in-use FCF record no |
| 2476 | * longer existed during FCF discovery that |
| 2477 | * was not triggered by fast FCF failover |
| 2478 | * process, treat it as fast FCF failover. |
| 2479 | */ |
| 2480 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2481 | "2841 In-use FCF record (x%x) " |
| 2482 | "not reported, entering fast " |
| 2483 | "FCF failover mode scanning.\n", |
| 2484 | phba->fcf.current_rec.fcf_indx); |
| 2485 | spin_lock_irq(&phba->hbalock); |
| 2486 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2487 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2488 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2489 | LPFC_FCOE_FCF_GET_FIRST); |
| 2490 | return; |
| 2491 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2492 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2493 | lpfc_register_fcf(phba); |
| 2494 | } |
| 2495 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2496 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2497 | return; |
| 2498 | |
| 2499 | out: |
| 2500 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2501 | lpfc_register_fcf(phba); |
| 2502 | |
| 2503 | return; |
| 2504 | } |
| 2505 | |
| 2506 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2507 | * 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] | 2508 | * @phba: pointer to lpfc hba data structure. |
| 2509 | * @mboxq: pointer to mailbox object. |
| 2510 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2511 | * This is the callback function for FLOGI failure roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2512 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2513 | * performing the failover. If the FCF read back is not valid/available, it |
| 2514 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2515 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2516 | * newly read FCF record to the failover FCF record, unregister currently |
| 2517 | * registered FCF record, copy the failover FCF record to the current |
| 2518 | * FCF record, and then register the current FCF record before proceeding |
| 2519 | * to trying FLOGI on the new failover FCF. |
| 2520 | */ |
| 2521 | void |
| 2522 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2523 | { |
| 2524 | struct fcf_record *new_fcf_record; |
| 2525 | uint32_t boot_flag, addr_mode; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2526 | uint16_t next_fcf_index, fcf_index; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2527 | uint16_t current_fcf_index; |
| 2528 | uint16_t vlan_id; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2529 | int rc; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2530 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2531 | /* If link state is not up, stop the roundrobin failover process */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2532 | if (phba->link_state < LPFC_LINK_UP) { |
| 2533 | spin_lock_irq(&phba->hbalock); |
| 2534 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2535 | phba->hba_flag &= ~FCF_RR_INPROG; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2536 | spin_unlock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2537 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2541 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2542 | &next_fcf_index); |
| 2543 | if (!new_fcf_record) { |
| 2544 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2545 | "2766 Mailbox command READ_FCF_RECORD " |
| 2546 | "failed to retrieve a FCF record.\n"); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2547 | goto error_out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | /* Get the needed parameters from FCF record */ |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2551 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2552 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2553 | |
| 2554 | /* Log the FCF record information if turned on */ |
| 2555 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2556 | next_fcf_index); |
| 2557 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2558 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2559 | if (!rc) { |
| 2560 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2561 | "2848 Remove ineligible FCF (x%x) from " |
| 2562 | "from roundrobin bmask\n", fcf_index); |
| 2563 | /* Clear roundrobin bmask bit for ineligible FCF */ |
| 2564 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); |
| 2565 | /* Perform next round of roundrobin FCF failover */ |
| 2566 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 2567 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); |
| 2568 | if (rc) |
| 2569 | goto out; |
| 2570 | goto error_out; |
| 2571 | } |
| 2572 | |
| 2573 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 2574 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2575 | "2760 Perform FLOGI roundrobin FCF failover: " |
| 2576 | "FCF (x%x) back to FCF (x%x)\n", |
| 2577 | phba->fcf.current_rec.fcf_indx, fcf_index); |
| 2578 | /* Wait 500 ms before retrying FLOGI to current FCF */ |
| 2579 | msleep(500); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2580 | lpfc_issue_init_vfi(phba->pport); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2581 | goto out; |
| 2582 | } |
| 2583 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2584 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2585 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2586 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
| 2587 | phba->fcf.failover_rec.fcf_indx, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2588 | spin_lock_irq(&phba->hbalock); |
| 2589 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2590 | new_fcf_record, addr_mode, vlan_id, |
| 2591 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2592 | spin_unlock_irq(&phba->hbalock); |
| 2593 | |
| 2594 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2595 | |
| 2596 | /* Unregister the current in-use FCF record */ |
| 2597 | lpfc_unregister_fcf(phba); |
| 2598 | |
| 2599 | /* Replace in-use record with the new record */ |
| 2600 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2601 | sizeof(struct lpfc_fcf_rec)); |
| 2602 | |
| 2603 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2604 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
| 2605 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2606 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2607 | error_out: |
| 2608 | lpfc_register_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2609 | out: |
| 2610 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /** |
| 2614 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2615 | * @phba: pointer to lpfc hba data structure. |
| 2616 | * @mboxq: pointer to mailbox object. |
| 2617 | * |
| 2618 | * This is the callback function of read FCF record mailbox command for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2619 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2620 | * failover when a new FCF event happened. If the FCF read back is |
| 2621 | * valid/available and it passes the connection list check, it updates |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 2622 | * the bmask for the eligible FCF record for roundrobin failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2623 | */ |
| 2624 | void |
| 2625 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2626 | { |
| 2627 | struct fcf_record *new_fcf_record; |
| 2628 | uint32_t boot_flag, addr_mode; |
| 2629 | uint16_t fcf_index, next_fcf_index; |
| 2630 | uint16_t vlan_id; |
| 2631 | int rc; |
| 2632 | |
| 2633 | /* If link state is not up, no need to proceed */ |
| 2634 | if (phba->link_state < LPFC_LINK_UP) |
| 2635 | goto out; |
| 2636 | |
| 2637 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2638 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2639 | goto out; |
| 2640 | |
| 2641 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2642 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2643 | &next_fcf_index); |
| 2644 | if (!new_fcf_record) { |
| 2645 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2646 | "2767 Mailbox command READ_FCF_RECORD " |
| 2647 | "failed to retrieve a FCF record.\n"); |
| 2648 | goto out; |
| 2649 | } |
| 2650 | |
| 2651 | /* Check the connection list for eligibility */ |
| 2652 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2653 | &addr_mode, &vlan_id); |
| 2654 | |
| 2655 | /* Log the FCF record information if turned on */ |
| 2656 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2657 | next_fcf_index); |
| 2658 | |
| 2659 | if (!rc) |
| 2660 | goto out; |
| 2661 | |
| 2662 | /* Update the eligible FCF record index bmask */ |
| 2663 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 2664 | |
| 2665 | 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] | 2666 | |
| 2667 | out: |
| 2668 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2669 | } |
| 2670 | |
| 2671 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2672 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. |
| 2673 | * @phba: pointer to lpfc hba data structure. |
| 2674 | * @mboxq: pointer to mailbox data structure. |
| 2675 | * |
| 2676 | * This function handles completion of init vfi mailbox command. |
| 2677 | */ |
| 2678 | void |
| 2679 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2680 | { |
| 2681 | struct lpfc_vport *vport = mboxq->vport; |
| 2682 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 2683 | /* |
| 2684 | * VFI not supported on interface type 0, just do the flogi |
| 2685 | * Also continue if the VFI is in use - just use the same one. |
| 2686 | */ |
| 2687 | if (mboxq->u.mb.mbxStatus && |
| 2688 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2689 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2690 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2691 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2692 | LOG_MBOX, |
| 2693 | "2891 Init VFI mailbox failed 0x%x\n", |
| 2694 | mboxq->u.mb.mbxStatus); |
| 2695 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2696 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2697 | return; |
| 2698 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2699 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2700 | lpfc_initial_flogi(vport); |
| 2701 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2702 | return; |
| 2703 | } |
| 2704 | |
| 2705 | /** |
| 2706 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. |
| 2707 | * @vport: pointer to lpfc_vport data structure. |
| 2708 | * |
| 2709 | * This function issue a init_vfi mailbox command to initialize the VFI and |
| 2710 | * VPI for the physical port. |
| 2711 | */ |
| 2712 | void |
| 2713 | lpfc_issue_init_vfi(struct lpfc_vport *vport) |
| 2714 | { |
| 2715 | LPFC_MBOXQ_t *mboxq; |
| 2716 | int rc; |
| 2717 | struct lpfc_hba *phba = vport->phba; |
| 2718 | |
| 2719 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2720 | if (!mboxq) { |
| 2721 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2722 | LOG_MBOX, "2892 Failed to allocate " |
| 2723 | "init_vfi mailbox\n"); |
| 2724 | return; |
| 2725 | } |
| 2726 | lpfc_init_vfi(mboxq, vport); |
| 2727 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; |
| 2728 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 2729 | if (rc == MBX_NOT_FINISHED) { |
| 2730 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2731 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); |
| 2732 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2737 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2738 | * @phba: pointer to lpfc hba data structure. |
| 2739 | * @mboxq: pointer to mailbox data structure. |
| 2740 | * |
| 2741 | * This function handles completion of init vpi mailbox command. |
| 2742 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2743 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2744 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2745 | { |
| 2746 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2747 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2748 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2749 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2750 | if (mboxq->u.mb.mbxStatus) { |
| 2751 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2752 | LOG_MBOX, |
| 2753 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2754 | mboxq->u.mb.mbxStatus); |
| 2755 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2756 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2757 | return; |
| 2758 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2759 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2760 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2761 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2762 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2763 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2764 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2765 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2766 | if (!ndlp) |
| 2767 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2768 | LOG_DISCOVERY, |
| 2769 | "2731 Cannot find fabric " |
| 2770 | "controller node\n"); |
| 2771 | else |
| 2772 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2773 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2774 | return; |
| 2775 | } |
| 2776 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2777 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2778 | lpfc_initial_fdisc(vport); |
| 2779 | else { |
| 2780 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2781 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2782 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2783 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2784 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2785 | return; |
| 2786 | } |
| 2787 | |
| 2788 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2789 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2790 | * @vport: pointer to lpfc_vport data structure. |
| 2791 | * |
| 2792 | * This function issue a init_vpi mailbox command to initialize |
| 2793 | * VPI for the vport. |
| 2794 | */ |
| 2795 | void |
| 2796 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2797 | { |
| 2798 | LPFC_MBOXQ_t *mboxq; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame^] | 2799 | int rc, vpi; |
| 2800 | |
| 2801 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { |
| 2802 | vpi = lpfc_alloc_vpi(vport->phba); |
| 2803 | if (!vpi) { |
| 2804 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2805 | LOG_MBOX, |
| 2806 | "3303 Failed to obtain vport vpi\n"); |
| 2807 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2808 | return; |
| 2809 | } |
| 2810 | vport->vpi = vpi; |
| 2811 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2812 | |
| 2813 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2814 | if (!mboxq) { |
| 2815 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2816 | LOG_MBOX, "2607 Failed to allocate " |
| 2817 | "init_vpi mailbox\n"); |
| 2818 | return; |
| 2819 | } |
| 2820 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2821 | mboxq->vport = vport; |
| 2822 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2823 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2824 | if (rc == MBX_NOT_FINISHED) { |
| 2825 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2826 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2827 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2832 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2833 | * @phba: pointer to lpfc hba data structure. |
| 2834 | * |
| 2835 | * This function loops through the list of vports on the @phba and issues an |
| 2836 | * FDISC if possible. |
| 2837 | */ |
| 2838 | void |
| 2839 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2840 | { |
| 2841 | struct lpfc_vport **vports; |
| 2842 | int i; |
| 2843 | |
| 2844 | vports = lpfc_create_vport_work_array(phba); |
| 2845 | if (vports != NULL) { |
| 2846 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2847 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2848 | continue; |
| 2849 | /* There are no vpi for this vport */ |
| 2850 | if (vports[i]->vpi > phba->max_vpi) { |
| 2851 | lpfc_vport_set_state(vports[i], |
| 2852 | FC_VPORT_FAILED); |
| 2853 | continue; |
| 2854 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2855 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2856 | lpfc_vport_set_state(vports[i], |
| 2857 | FC_VPORT_LINKDOWN); |
| 2858 | continue; |
| 2859 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2860 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2861 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2862 | continue; |
| 2863 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2864 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2865 | lpfc_initial_fdisc(vports[i]); |
| 2866 | else { |
| 2867 | lpfc_vport_set_state(vports[i], |
| 2868 | FC_VPORT_NO_FABRIC_SUPP); |
| 2869 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2870 | LOG_ELS, |
| 2871 | "0259 No NPIV " |
| 2872 | "Fabric support\n"); |
| 2873 | } |
| 2874 | } |
| 2875 | } |
| 2876 | lpfc_destroy_vport_work_array(phba, vports); |
| 2877 | } |
| 2878 | |
| 2879 | void |
| 2880 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2881 | { |
| 2882 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2883 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2884 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2885 | |
James Smart | f5eca9b | 2012-03-01 22:37:54 -0500 | [diff] [blame] | 2886 | /* |
| 2887 | * VFI not supported for interface type 0, so ignore any mailbox |
| 2888 | * error (except VFI in use) and continue with the discovery. |
| 2889 | */ |
| 2890 | if (mboxq->u.mb.mbxStatus && |
| 2891 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2892 | LPFC_SLI_INTF_IF_TYPE_0) && |
| 2893 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2894 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2895 | "2018 REG_VFI mbxStatus error x%x " |
| 2896 | "HBA state x%x\n", |
| 2897 | mboxq->u.mb.mbxStatus, vport->port_state); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2898 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2899 | /* FLOGI failed, use loop map to make discovery list */ |
| 2900 | lpfc_disc_list_loopmap(vport); |
| 2901 | /* Start discovery */ |
| 2902 | lpfc_disc_start(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2903 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2904 | } |
| 2905 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2906 | goto out_free_mem; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2907 | } |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2908 | |
| 2909 | /* If the VFI is already registered, there is nothing else to do */ |
| 2910 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 2911 | goto out_free_mem; |
| 2912 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2913 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2914 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2915 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2916 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2917 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 2918 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2919 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2920 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2921 | /* In case SLI4 FC loopback test, we are ready */ |
| 2922 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2923 | (phba->link_flag & LS_LOOPBACK_MODE)) { |
| 2924 | phba->link_state = LPFC_HBA_READY; |
| 2925 | goto out_free_mem; |
| 2926 | } |
| 2927 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2928 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 2929 | /* |
| 2930 | * For private loop or for NPort pt2pt, |
| 2931 | * just start discovery and we are done. |
| 2932 | */ |
| 2933 | if ((vport->fc_flag & FC_PT2PT) || |
| 2934 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
| 2935 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { |
| 2936 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2937 | /* Use loop map to make discovery list */ |
| 2938 | lpfc_disc_list_loopmap(vport); |
| 2939 | /* Start discovery */ |
| 2940 | lpfc_disc_start(vport); |
| 2941 | } else { |
| 2942 | lpfc_start_fdiscs(phba); |
| 2943 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2944 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2945 | } |
| 2946 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2947 | out_free_mem: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2948 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2949 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2950 | kfree(dmabuf); |
| 2951 | return; |
| 2952 | } |
| 2953 | |
| 2954 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2955 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2957 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2958 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2959 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2960 | |
| 2961 | |
| 2962 | /* Check for error */ |
| 2963 | if (mb->mbxStatus) { |
| 2964 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2965 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2966 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2967 | "hba state x%x>\n", |
| 2968 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2969 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | goto out; |
| 2971 | } |
| 2972 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2973 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | sizeof (struct serv_parm)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 2975 | lpfc_update_vport_wwn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2976 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2977 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2978 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2979 | } |
| 2980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2982 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2983 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | return; |
| 2985 | |
| 2986 | out: |
| 2987 | pmb->context1 = NULL; |
| 2988 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2989 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2990 | lpfc_issue_clear_la(phba, vport); |
| 2991 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | return; |
| 2993 | } |
| 2994 | |
| 2995 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2996 | 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] | 2997 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2999 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3000 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3001 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3002 | struct lpfc_dmabuf *mp; |
| 3003 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3004 | struct fcf_record *fcf_record; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3005 | uint32_t fc_flags = 0; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3006 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3007 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3008 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { |
| 3009 | case LPFC_LINK_SPEED_1GHZ: |
| 3010 | case LPFC_LINK_SPEED_2GHZ: |
| 3011 | case LPFC_LINK_SPEED_4GHZ: |
| 3012 | case LPFC_LINK_SPEED_8GHZ: |
| 3013 | case LPFC_LINK_SPEED_10GHZ: |
| 3014 | case LPFC_LINK_SPEED_16GHZ: |
| 3015 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3016 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3017 | default: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3018 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3019 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3022 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3023 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3024 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3025 | shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3026 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3027 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3029 | /* if npiv is enabled and this adapter supports npiv log |
| 3030 | * a message that npiv is not supported in this topology |
| 3031 | */ |
| 3032 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3033 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3034 | "1309 Link Up Event npiv not supported in loop " |
| 3035 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3036 | /* Get Loop Map information */ |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3037 | if (bf_get(lpfc_mbx_read_top_il, la)) |
| 3038 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3040 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
| 3041 | i = la->lilpBde64.tus.f.bdeSize; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | |
| 3043 | if (i == 0) { |
| 3044 | phba->alpa_map[0] = 0; |
| 3045 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3046 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | int numalpa, j, k; |
| 3048 | union { |
| 3049 | uint8_t pamap[16]; |
| 3050 | struct { |
| 3051 | uint32_t wd1; |
| 3052 | uint32_t wd2; |
| 3053 | uint32_t wd3; |
| 3054 | uint32_t wd4; |
| 3055 | } pa; |
| 3056 | } un; |
| 3057 | numalpa = phba->alpa_map[0]; |
| 3058 | j = 0; |
| 3059 | while (j < numalpa) { |
| 3060 | memset(un.pamap, 0, 16); |
| 3061 | for (k = 1; j < numalpa; k++) { |
| 3062 | un.pamap[k - 1] = |
| 3063 | phba->alpa_map[j + 1]; |
| 3064 | j++; |
| 3065 | if (k == 16) |
| 3066 | break; |
| 3067 | } |
| 3068 | /* Link Up Event ALPA map */ |
| 3069 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3070 | KERN_WARNING, |
| 3071 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3072 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3073 | "ALPA map Data: x%x " |
| 3074 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3075 | un.pa.wd1, un.pa.wd2, |
| 3076 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | } |
| 3080 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3081 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3082 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3083 | (phba->sli_rev >= LPFC_SLI_REV3)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3084 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3085 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3086 | vport->fc_myDID = phba->fc_pref_DID; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3087 | fc_flags |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3089 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3091 | if (fc_flags) { |
| 3092 | spin_lock_irq(shost->host_lock); |
| 3093 | vport->fc_flag |= fc_flags; |
| 3094 | spin_unlock_irq(shost->host_lock); |
| 3095 | } |
| 3096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 3098 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3099 | if (!sparam_mbox) |
| 3100 | goto out; |
| 3101 | |
| 3102 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 3103 | if (rc) { |
| 3104 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3105 | goto out; |
| 3106 | } |
| 3107 | sparam_mbox->vport = vport; |
| 3108 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 3109 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 3110 | if (rc == MBX_NOT_FINISHED) { |
| 3111 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 3112 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3113 | kfree(mp); |
| 3114 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 3115 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | } |
| 3117 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3118 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3119 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3120 | if (!cfglink_mbox) |
| 3121 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3122 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3123 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3124 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 3125 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3126 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3127 | if (rc == MBX_NOT_FINISHED) { |
| 3128 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 3129 | goto out; |
| 3130 | } |
| 3131 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3132 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3133 | /* |
| 3134 | * Add the driver's default FCF record at FCF index 0 now. This |
| 3135 | * is phase 1 implementation that support FCF index 0 and driver |
| 3136 | * defaults. |
| 3137 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3138 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3139 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 3140 | GFP_KERNEL); |
| 3141 | if (unlikely(!fcf_record)) { |
| 3142 | lpfc_printf_log(phba, KERN_ERR, |
| 3143 | LOG_MBOX | LOG_SLI, |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 3144 | "2554 Could not allocate memory for " |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3145 | "fcf record\n"); |
| 3146 | rc = -ENODEV; |
| 3147 | goto out; |
| 3148 | } |
| 3149 | |
| 3150 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 3151 | LPFC_FCOE_FCF_DEF_INDEX); |
| 3152 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 3153 | if (unlikely(rc)) { |
| 3154 | lpfc_printf_log(phba, KERN_ERR, |
| 3155 | LOG_MBOX | LOG_SLI, |
| 3156 | "2013 Could not manually add FCF " |
| 3157 | "record 0, status %d\n", rc); |
| 3158 | rc = -ENODEV; |
| 3159 | kfree(fcf_record); |
| 3160 | goto out; |
| 3161 | } |
| 3162 | kfree(fcf_record); |
| 3163 | } |
| 3164 | /* |
| 3165 | * The driver is expected to do FIP/FCF. Call the port |
| 3166 | * and get the FCF Table. |
| 3167 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3168 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3169 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3170 | spin_unlock_irq(&phba->hbalock); |
| 3171 | return; |
| 3172 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3173 | /* This is the initial FCF discovery scan */ |
| 3174 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3175 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3176 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3177 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3178 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3179 | LPFC_FCOE_FCF_GET_FIRST); |
| 3180 | if (rc) { |
| 3181 | spin_lock_irq(&phba->hbalock); |
| 3182 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 3183 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3184 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3185 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3186 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3187 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3189 | |
| 3190 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3191 | out: |
| 3192 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3193 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3194 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 3195 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3196 | lpfc_issue_clear_la(phba, vport); |
| 3197 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3201 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3202 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | uint32_t control; |
| 3204 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3206 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3207 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3208 | control = readl(phba->HCregaddr); |
| 3209 | control |= HC_LAINT_ENA; |
| 3210 | writel(control, phba->HCregaddr); |
| 3211 | readl(phba->HCregaddr); /* flush */ |
| 3212 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3213 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3214 | } |
| 3215 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3216 | static void |
| 3217 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 3218 | { |
| 3219 | lpfc_linkdown(phba); |
| 3220 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3221 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3222 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 3223 | } |
| 3224 | |
| 3225 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | /* |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3227 | * This routine handles processing a READ_TOPOLOGY mailbox |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3228 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3229 | * as the completion routine when the command is |
| 3230 | * handed off to the SLI layer. |
| 3231 | */ |
| 3232 | void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3233 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3235 | struct lpfc_vport *vport = pmb->vport; |
| 3236 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3237 | struct lpfc_mbx_read_top *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3238 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3240 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3241 | /* Unblock ELS traffic */ |
| 3242 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | /* Check for error */ |
| 3244 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3245 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3246 | "1307 READ_LA mbox error x%x state x%x\n", |
| 3247 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3250 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3253 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | |
| 3255 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 3256 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3257 | spin_lock_irq(shost->host_lock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3258 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3260 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3261 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 3262 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3263 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3264 | if (phba->fc_eventTag <= la->eventTag) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3266 | if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | if (phba->fc_eventTag != 0) |
| 3268 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | |
| 3271 | phba->fc_eventTag = la->eventTag; |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3272 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3273 | spin_lock_irq(&phba->hbalock); |
| 3274 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
| 3275 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 3276 | else |
| 3277 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| 3278 | spin_unlock_irq(&phba->hbalock); |
| 3279 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3281 | phba->link_events++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3282 | if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) && |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3283 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3286 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3287 | "1306 Link Up Event in loop back mode " |
| 3288 | "x%x received Data: x%x x%x x%x x%x\n", |
| 3289 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3290 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3291 | la), |
| 3292 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3293 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3294 | } else { |
| 3295 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3296 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3297 | "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] | 3298 | la->eventTag, phba->fc_eventTag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3299 | bf_get(lpfc_mbx_read_top_alpa_granted, |
| 3300 | la), |
| 3301 | bf_get(lpfc_mbx_read_top_link_spd, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3302 | phba->alpa_map[0], |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3303 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3304 | bf_get(lpfc_mbx_read_top_fa, la), |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3305 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3306 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3307 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3308 | } else if (bf_get(lpfc_mbx_read_top_att_type, la) == |
| 3309 | LPFC_ATT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | phba->fc_stat.LinkDown++; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3311 | if (phba->link_flag & LS_LOOPBACK_MODE) |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3312 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3313 | "1308 Link Down Event in loop back mode " |
| 3314 | "x%x received " |
| 3315 | "Data: x%x x%x x%x\n", |
| 3316 | la->eventTag, phba->fc_eventTag, |
| 3317 | phba->pport->port_state, vport->fc_flag); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3318 | else |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3319 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3320 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3321 | "Data: x%x x%x x%x x%x x%x\n", |
| 3322 | la->eventTag, phba->fc_eventTag, |
| 3323 | phba->pport->port_state, vport->fc_flag, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3324 | bf_get(lpfc_mbx_read_top_mm, la), |
| 3325 | bf_get(lpfc_mbx_read_top_fa, la)); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3326 | lpfc_mbx_issue_link_down(phba); |
| 3327 | } |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3328 | if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) && |
| 3329 | ((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] | 3330 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 3331 | phba->fc_stat.LinkDown++; |
| 3332 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3333 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3335 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3336 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3337 | lpfc_mbx_issue_link_down(phba); |
| 3338 | } else |
| 3339 | lpfc_enable_la(phba); |
| 3340 | |
| 3341 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 3342 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 3343 | "Data: x%x x%x x%x\n", |
| 3344 | la->eventTag, phba->fc_eventTag, |
| 3345 | phba->pport->port_state, vport->fc_flag); |
| 3346 | /* |
| 3347 | * The cmnd that triggered this will be waiting for this |
| 3348 | * signal. |
| 3349 | */ |
| 3350 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 3351 | if (phba->wait_4_mlo_maint_flg) { |
| 3352 | phba->wait_4_mlo_maint_flg = 0; |
| 3353 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3354 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3355 | } |
| 3356 | |
James Smart | be0c008 | 2013-03-01 16:38:14 -0500 | [diff] [blame] | 3357 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3358 | bf_get(lpfc_mbx_read_top_fa, la)) { |
| 3359 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3360 | lpfc_issue_clear_la(phba, vport); |
| 3361 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3362 | "1311 fa %d\n", |
| 3363 | bf_get(lpfc_mbx_read_top_fa, la)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | } |
| 3365 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3366 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3368 | kfree(mp); |
| 3369 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3370 | return; |
| 3371 | } |
| 3372 | |
| 3373 | /* |
| 3374 | * This routine handles processing a REG_LOGIN mailbox |
| 3375 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3376 | * as the completion routine when the command is |
| 3377 | * handed off to the SLI layer. |
| 3378 | */ |
| 3379 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3380 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3383 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3385 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3388 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3389 | |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3390 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 3391 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 3392 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3393 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 3394 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3395 | /* We rcvd a rscn after issuing this |
| 3396 | * mbox reg login, we may have cycled |
| 3397 | * back through the state and be |
| 3398 | * back at reg login state so this |
| 3399 | * mbox needs to be ignored becase |
| 3400 | * there is another reg login in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3401 | * process. |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3402 | */ |
| 3403 | spin_lock_irq(shost->host_lock); |
| 3404 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 3405 | spin_unlock_irq(shost->host_lock); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3406 | } else |
| 3407 | /* Good status, call state machine */ |
| 3408 | lpfc_disc_state_machine(vport, ndlp, pmb, |
| 3409 | NLP_EVT_CMPL_REG_LOGIN); |
| 3410 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3412 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3413 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3414 | /* decrement the node reference count held for this callback |
| 3415 | * function. |
| 3416 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3417 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | |
| 3419 | return; |
| 3420 | } |
| 3421 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3422 | static void |
| 3423 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3424 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3425 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3426 | struct lpfc_vport *vport = pmb->vport; |
| 3427 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3428 | |
| 3429 | switch (mb->mbxStatus) { |
| 3430 | case 0x0011: |
| 3431 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3432 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3433 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 3434 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3435 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3436 | /* If VPI is busy, reset the HBA */ |
| 3437 | case 0x9700: |
| 3438 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3439 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 3440 | vport->vpi, mb->mbxStatus); |
| 3441 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3442 | lpfc_workq_post_event(phba, NULL, NULL, |
| 3443 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3445 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3446 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 3447 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3448 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3449 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 3450 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3451 | lpfc_cleanup_vports_rrqs(vport, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3452 | /* |
| 3453 | * This shost reference might have been taken at the beginning of |
| 3454 | * lpfc_vport_delete() |
| 3455 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 3456 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3457 | scsi_host_put(shost); |
| 3458 | } |
| 3459 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3460 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3461 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 3462 | { |
| 3463 | struct lpfc_hba *phba = vport->phba; |
| 3464 | LPFC_MBOXQ_t *mbox; |
| 3465 | int rc; |
| 3466 | |
| 3467 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3468 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3469 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3470 | |
| 3471 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 3472 | mbox->vport = vport; |
| 3473 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3474 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3475 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3476 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3477 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3479 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3480 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3481 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3482 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | static void |
| 3486 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3487 | { |
| 3488 | struct lpfc_vport *vport = pmb->vport; |
| 3489 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3490 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3491 | |
| 3492 | switch (mb->mbxStatus) { |
| 3493 | case 0x0011: |
| 3494 | case 0x9601: |
| 3495 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3496 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3497 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 3498 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3499 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 3500 | spin_lock_irq(shost->host_lock); |
| 3501 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3502 | spin_unlock_irq(shost->host_lock); |
| 3503 | vport->fc_myDID = 0; |
| 3504 | goto out; |
| 3505 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3506 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3507 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3508 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3509 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3510 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3511 | vport->num_disc_nodes = 0; |
| 3512 | /* go thru NPR list and issue ELS PLOGIs */ |
| 3513 | if (vport->fc_npr_cnt) |
| 3514 | lpfc_els_disc_plogi(vport); |
| 3515 | |
| 3516 | if (!vport->num_disc_nodes) { |
| 3517 | spin_lock_irq(shost->host_lock); |
| 3518 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3519 | spin_unlock_irq(shost->host_lock); |
| 3520 | lpfc_can_disctmo(vport); |
| 3521 | } |
| 3522 | vport->port_state = LPFC_VPORT_READY; |
| 3523 | |
| 3524 | out: |
| 3525 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3526 | return; |
| 3527 | } |
| 3528 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3529 | /** |
| 3530 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 3531 | * @phba: pointer to lpfc hba data structure. |
| 3532 | * |
| 3533 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3534 | * the list of static vports to be created. The function create vports |
| 3535 | * based on the information returned from the HBA. |
| 3536 | **/ |
| 3537 | void |
| 3538 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3539 | { |
| 3540 | LPFC_MBOXQ_t *pmb = NULL; |
| 3541 | MAILBOX_t *mb; |
| 3542 | struct static_vport_info *vport_info; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3543 | int mbx_wait_rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3544 | struct fc_vport_identifiers vport_id; |
| 3545 | struct fc_vport *new_fc_vport; |
| 3546 | struct Scsi_Host *shost; |
| 3547 | struct lpfc_vport *vport; |
| 3548 | uint16_t offset = 0; |
| 3549 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3550 | struct lpfc_dmabuf *mp; |
| 3551 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3552 | |
| 3553 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3554 | if (!pmb) { |
| 3555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3556 | "0542 lpfc_create_static_vport failed to" |
| 3557 | " allocate mailbox memory\n"); |
| 3558 | return; |
| 3559 | } |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3560 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3561 | mb = &pmb->u.mb; |
| 3562 | |
| 3563 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3564 | if (!vport_info) { |
| 3565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3566 | "0543 lpfc_create_static_vport failed to" |
| 3567 | " allocate vport_info\n"); |
| 3568 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | vport_buff = (uint8_t *) vport_info; |
| 3573 | do { |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3574 | /* free dma buffer from previous round */ |
| 3575 | if (pmb->context1) { |
| 3576 | mp = (struct lpfc_dmabuf *)pmb->context1; |
| 3577 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3578 | kfree(mp); |
| 3579 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3580 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3581 | goto out; |
| 3582 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3583 | pmb->vport = phba->pport; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3584 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
| 3585 | LPFC_MBOX_TMO); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3586 | |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3587 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3588 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3589 | "0544 lpfc_create_static_vport failed to" |
| 3590 | " issue dump mailbox command ret 0x%x " |
| 3591 | "status 0x%x\n", |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3592 | mbx_wait_rc, mb->mbxStatus); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3593 | goto out; |
| 3594 | } |
| 3595 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3596 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3597 | byte_count = pmb->u.mqe.un.mb_words[5]; |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3598 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3599 | if (byte_count > sizeof(struct static_vport_info) - |
| 3600 | offset) |
| 3601 | byte_count = sizeof(struct static_vport_info) |
| 3602 | - offset; |
| 3603 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3604 | offset += byte_count; |
| 3605 | } else { |
| 3606 | if (mb->un.varDmp.word_cnt > |
| 3607 | sizeof(struct static_vport_info) - offset) |
| 3608 | mb->un.varDmp.word_cnt = |
| 3609 | sizeof(struct static_vport_info) |
| 3610 | - offset; |
| 3611 | byte_count = mb->un.varDmp.word_cnt; |
| 3612 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3613 | vport_buff + offset, |
| 3614 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3615 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3616 | offset += byte_count; |
| 3617 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3618 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3619 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3620 | offset < sizeof(struct static_vport_info)); |
| 3621 | |
| 3622 | |
| 3623 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3624 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3625 | != VPORT_INFO_REV)) { |
| 3626 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3627 | "0545 lpfc_create_static_vport bad" |
| 3628 | " information header 0x%x 0x%x\n", |
| 3629 | le32_to_cpu(vport_info->signature), |
| 3630 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3631 | |
| 3632 | goto out; |
| 3633 | } |
| 3634 | |
| 3635 | shost = lpfc_shost_from_vport(phba->pport); |
| 3636 | |
| 3637 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3638 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3639 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3640 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3641 | if (!vport_id.port_name || !vport_id.node_name) |
| 3642 | continue; |
| 3643 | |
| 3644 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3645 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3646 | vport_id.disable = false; |
| 3647 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3648 | |
| 3649 | if (!new_fc_vport) { |
| 3650 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3651 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3652 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3653 | continue; |
| 3654 | } |
| 3655 | |
| 3656 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3657 | vport->vport_flag |= STATIC_VPORT; |
| 3658 | } |
| 3659 | |
| 3660 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3661 | kfree(vport_info); |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 3662 | if (mbx_wait_rc != MBX_TIMEOUT) { |
| 3663 | if (pmb->context1) { |
| 3664 | mp = (struct lpfc_dmabuf *)pmb->context1; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3665 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3666 | kfree(mp); |
| 3667 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3668 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3669 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3670 | |
| 3671 | return; |
| 3672 | } |
| 3673 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | /* |
| 3675 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3676 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3677 | * as the completion routine when the command is |
| 3678 | * handed off to the SLI layer. |
| 3679 | */ |
| 3680 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3681 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3683 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3684 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3685 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3686 | struct lpfc_nodelist *ndlp; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3687 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3689 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3690 | pmb->context1 = NULL; |
| 3691 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3692 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3694 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3695 | "0258 Register Fabric login error: 0x%x\n", |
| 3696 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3698 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3699 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3701 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3702 | /* FLOGI failed, use loop map to make discovery list */ |
| 3703 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3705 | /* Start discovery */ |
| 3706 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3707 | /* Decrement the reference count to ndlp after the |
| 3708 | * reference to the ndlp are done. |
| 3709 | */ |
| 3710 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3711 | return; |
| 3712 | } |
| 3713 | |
| 3714 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3715 | /* Decrement the reference count to ndlp after the reference |
| 3716 | * to the ndlp are done. |
| 3717 | */ |
| 3718 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | return; |
| 3720 | } |
| 3721 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3722 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3723 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3724 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3726 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3728 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3729 | /* when physical port receive logo donot start |
| 3730 | * vport discovery */ |
| 3731 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3732 | lpfc_start_fdiscs(phba); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3733 | else { |
| 3734 | shost = lpfc_shost_from_vport(vport); |
| 3735 | spin_lock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3736 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3737 | spin_unlock_irq(shost->host_lock); |
| 3738 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3739 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3743 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3744 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3745 | |
| 3746 | /* Drop the reference count from the mbox at the end after |
| 3747 | * all the current reference to the ndlp have been done. |
| 3748 | */ |
| 3749 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3750 | return; |
| 3751 | } |
| 3752 | |
| 3753 | /* |
| 3754 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3755 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3756 | * as the completion routine when the command is |
| 3757 | * handed off to the SLI layer. |
| 3758 | */ |
| 3759 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3760 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3762 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3763 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3764 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3765 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3767 | pmb->context1 = NULL; |
| 3768 | pmb->context2 = NULL; |
| 3769 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3773 | "0260 Register NameServer error: 0x%x\n", |
| 3774 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3775 | /* decrement the node reference count held for this |
| 3776 | * callback function. |
| 3777 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3778 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3780 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3781 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3782 | |
| 3783 | /* If no other thread is using the ndlp, free it */ |
| 3784 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3786 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3787 | /* |
| 3788 | * RegLogin failed, use loop map to make discovery |
| 3789 | * list |
| 3790 | */ |
| 3791 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3793 | /* Start discovery */ |
| 3794 | lpfc_disc_start(vport); |
| 3795 | return; |
| 3796 | } |
| 3797 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | return; |
| 3799 | } |
| 3800 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3801 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3802 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 3803 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3805 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3807 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3808 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3809 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3810 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3811 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3812 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3813 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3814 | |
| 3815 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3816 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | } |
| 3818 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3819 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3821 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3823 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } |
| 3825 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3826 | /* decrement the node reference count held for this |
| 3827 | * callback function. |
| 3828 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3829 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3831 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | |
| 3834 | return; |
| 3835 | } |
| 3836 | |
| 3837 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3838 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3839 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3840 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3841 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3842 | struct lpfc_rport_data *rdata; |
| 3843 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | |
| 3846 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3847 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3848 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | rport_ids.port_id = ndlp->nlp_DID; |
| 3850 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3852 | /* |
| 3853 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3854 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3855 | * rport->dd_data points. So, if we're reusing a previously |
| 3856 | * registered port, drop the reference that we took the last time we |
| 3857 | * registered the port. |
| 3858 | */ |
| 3859 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3860 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3861 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3862 | |
| 3863 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3864 | "rport add: did:x%x flg:x%x type x%x", |
| 3865 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3866 | |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 3867 | /* Don't add the remote port if unloading. */ |
| 3868 | if (vport->load_flag & FC_UNLOADING) |
| 3869 | return; |
| 3870 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3872 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3874 | "Warning: fc_remote_port_add failed\n"); |
| 3875 | return; |
| 3876 | } |
| 3877 | |
| 3878 | /* initialize static port data */ |
| 3879 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3880 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3881 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3882 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3883 | |
| 3884 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3885 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3886 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3887 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3888 | |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3889 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3890 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3891 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3892 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3893 | "3183 rport register x%06x, rport %p role x%x\n", |
| 3894 | ndlp->nlp_DID, rport, rport_ids.roles); |
| 3895 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3896 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3897 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3898 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3899 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3900 | return; |
| 3901 | } |
| 3902 | |
| 3903 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3904 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3905 | { |
| 3906 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3907 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3908 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3909 | "rport delete: did:x%x flg:x%x type x%x", |
| 3910 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3911 | |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 3912 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3913 | "3184 rport unregister x%06x, rport %p\n", |
| 3914 | ndlp->nlp_DID, rport); |
| 3915 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3916 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | |
| 3918 | return; |
| 3919 | } |
| 3920 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3921 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3923 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3925 | |
| 3926 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3927 | switch (state) { |
| 3928 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3929 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3930 | break; |
| 3931 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3933 | break; |
| 3934 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3936 | break; |
| 3937 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3939 | break; |
| 3940 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3941 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3942 | break; |
| 3943 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3944 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3945 | break; |
| 3946 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3947 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3948 | break; |
| 3949 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3951 | break; |
| 3952 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3953 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3954 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3955 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3956 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3958 | int old_state, int new_state) |
| 3959 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3960 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3961 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3962 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3963 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3964 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3965 | } |
| 3966 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3967 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3968 | if (new_state == NLP_STE_NPR_NODE) |
| 3969 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3971 | /* Transport interface */ |
| 3972 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 3973 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3974 | vport->phba->nport_event_cnt++; |
| 3975 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3976 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3978 | if (new_state == NLP_STE_MAPPED_NODE || |
| 3979 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3980 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3981 | /* |
| 3982 | * Tell the fc transport about the port, if we haven't |
| 3983 | * already. If we have, and it's a scsi entity, be |
| 3984 | * sure to unblock any attached scsi devices |
| 3985 | */ |
| 3986 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3987 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3988 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 3989 | (vport->stat_data_enabled)) { |
| 3990 | /* |
| 3991 | * A new target is discovered, if there is no buffer for |
| 3992 | * statistical data collection allocate buffer. |
| 3993 | */ |
| 3994 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 3995 | sizeof(struct lpfc_scsicmd_bkt), |
| 3996 | GFP_KERNEL); |
| 3997 | |
| 3998 | if (!ndlp->lat_data) |
| 3999 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 4000 | "0286 lpfc_nlp_state_cleanup failed to " |
| 4001 | "allocate statistical data buffer DID " |
| 4002 | "0x%x\n", ndlp->nlp_DID); |
| 4003 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4004 | /* |
| 4005 | * if we added to Mapped list, but the remote port |
| 4006 | * registration failed or assigned a target id outside |
| 4007 | * our presentable range - move the node to the |
| 4008 | * Unmapped List |
| 4009 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4010 | if (new_state == NLP_STE_MAPPED_NODE && |
| 4011 | (!ndlp->rport || |
| 4012 | ndlp->rport->scsi_target_id == -1 || |
| 4013 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4015 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | spin_unlock_irq(shost->host_lock); |
| 4017 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4019 | } |
| 4020 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4021 | static char * |
| 4022 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 4023 | { |
| 4024 | static char *states[] = { |
| 4025 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 4026 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 4027 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 4028 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 4029 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4030 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4031 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 4032 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 4033 | [NLP_STE_NPR_NODE] = "NPR", |
| 4034 | }; |
| 4035 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4036 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4037 | strlcpy(buffer, states[state], size); |
| 4038 | else |
| 4039 | snprintf(buffer, size, "unknown (%d)", state); |
| 4040 | return buffer; |
| 4041 | } |
| 4042 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4043 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4044 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4045 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4046 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4048 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4049 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4050 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4051 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4052 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 4053 | ndlp->nlp_DID, |
| 4054 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 4055 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4056 | |
| 4057 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4058 | "node statechg did:x%x old:%d ste:%d", |
| 4059 | ndlp->nlp_DID, old_state, state); |
| 4060 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4061 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4062 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4063 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4064 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 4065 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 4066 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 4067 | } |
| 4068 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4069 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4070 | spin_lock_irq(shost->host_lock); |
| 4071 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4072 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4073 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4075 | |
| 4076 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | lpfc_nlp_counters(vport, state, 1); |
| 4078 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4082 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4083 | { |
| 4084 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4085 | |
| 4086 | if (list_empty(&ndlp->nlp_listp)) { |
| 4087 | spin_lock_irq(shost->host_lock); |
| 4088 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 4089 | spin_unlock_irq(shost->host_lock); |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4094 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4095 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4096 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4097 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4098 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4099 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4101 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4102 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4103 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4104 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4105 | NLP_STE_UNUSED_NODE); |
| 4106 | } |
| 4107 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 4108 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4109 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4110 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4111 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4112 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 4113 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 4114 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 4115 | NLP_STE_UNUSED_NODE); |
| 4116 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4118 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4119 | * @vport: Pointer to Virtual Port object. |
| 4120 | * @ndlp: Pointer to FC node object. |
| 4121 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4122 | * |
| 4123 | * This function is always called when node object need to be initialized. |
| 4124 | * It initializes all the fields of the node object. Although the reference |
| 4125 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 4126 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 4127 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 4128 | * the final release of ndlp is determined by its reference count. And, the |
| 4129 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4130 | **/ |
| 4131 | static inline void |
| 4132 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4133 | uint32_t did) |
| 4134 | { |
| 4135 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 4136 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 4137 | init_timer(&ndlp->nlp_delayfunc); |
| 4138 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 4139 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 4140 | ndlp->nlp_DID = did; |
| 4141 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4142 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4143 | ndlp->nlp_sid = NLP_NO_SID; |
| 4144 | kref_init(&ndlp->kref); |
| 4145 | NLP_INT_NODE_ACT(ndlp); |
| 4146 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4147 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4148 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4149 | ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4150 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4151 | |
| 4152 | struct lpfc_nodelist * |
| 4153 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4154 | int state) |
| 4155 | { |
| 4156 | struct lpfc_hba *phba = vport->phba; |
| 4157 | uint32_t did; |
| 4158 | unsigned long flags; |
| 4159 | |
| 4160 | if (!ndlp) |
| 4161 | return NULL; |
| 4162 | |
| 4163 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4164 | /* The ndlp should not be in memory free mode */ |
| 4165 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4166 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4167 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4168 | "0277 lpfc_enable_node: ndlp:x%p " |
| 4169 | "usgmap:x%x refcnt:%d\n", |
| 4170 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4171 | atomic_read(&ndlp->kref.refcount)); |
| 4172 | return NULL; |
| 4173 | } |
| 4174 | /* The ndlp should not already be in active mode */ |
| 4175 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 4176 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4177 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4178 | "0278 lpfc_enable_node: ndlp:x%p " |
| 4179 | "usgmap:x%x refcnt:%d\n", |
| 4180 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4181 | atomic_read(&ndlp->kref.refcount)); |
| 4182 | return NULL; |
| 4183 | } |
| 4184 | |
| 4185 | /* Keep the original DID */ |
| 4186 | did = ndlp->nlp_DID; |
| 4187 | |
| 4188 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 4189 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 4190 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4191 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4192 | |
| 4193 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4194 | |
| 4195 | if (state != NLP_STE_UNUSED_NODE) |
| 4196 | lpfc_nlp_set_state(vport, ndlp, state); |
| 4197 | |
| 4198 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4199 | "node enable: did:x%x", |
| 4200 | ndlp->nlp_DID, 0, 0); |
| 4201 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4206 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4207 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4208 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4209 | * 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] | 4210 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 4211 | * until ALL other outstanding threads have completed. We check |
| 4212 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4213 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4214 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 4215 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4216 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4217 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4218 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4219 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4220 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /* |
| 4224 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 4225 | */ |
| 4226 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4229 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4230 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | uint32_t tmo; |
| 4232 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4233 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4234 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4235 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 4236 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4237 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4238 | * FC spec states we need 3 * ratov for CT requests |
| 4239 | */ |
| 4240 | tmo = ((phba->fc_ratov * 3) + 3); |
| 4241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4243 | |
| 4244 | if (!timer_pending(&vport->fc_disctmo)) { |
| 4245 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4246 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 4247 | tmo, vport->port_state, vport->fc_flag); |
| 4248 | } |
| 4249 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 4251 | spin_lock_irq(shost->host_lock); |
| 4252 | vport->fc_flag |= FC_DISC_TMO; |
| 4253 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | |
| 4255 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4256 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4257 | "0247 Start Discovery Timer state x%x " |
| 4258 | "Data: x%x x%lx x%x x%x\n", |
| 4259 | vport->port_state, tmo, |
| 4260 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 4261 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | |
| 4263 | return; |
| 4264 | } |
| 4265 | |
| 4266 | /* |
| 4267 | * Cancel rescue timer for Discovery / RSCN handling |
| 4268 | */ |
| 4269 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4270 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | unsigned long iflags; |
| 4274 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4275 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4276 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 4277 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4280 | if (vport->fc_flag & FC_DISC_TMO) { |
| 4281 | spin_lock_irqsave(shost->host_lock, iflags); |
| 4282 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4283 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 4284 | del_timer_sync(&vport->fc_disctmo); |
| 4285 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 4286 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 4287 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4291 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4292 | "0248 Cancel Discovery Timer state x%x " |
| 4293 | "Data: x%x x%x x%x\n", |
| 4294 | vport->port_state, vport->fc_flag, |
| 4295 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4296 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | /* |
| 4300 | * Check specified ring for outstanding IOCB on the SLI queue |
| 4301 | * Return true if iocb matches the specified nport |
| 4302 | */ |
| 4303 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 4305 | struct lpfc_sli_ring *pring, |
| 4306 | struct lpfc_iocbq *iocb, |
| 4307 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4309 | struct lpfc_sli *psli = &phba->sli; |
| 4310 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4311 | struct lpfc_vport *vport = ndlp->vport; |
| 4312 | |
| 4313 | if (iocb->vport != vport) |
| 4314 | return 0; |
| 4315 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | if (pring->ringno == LPFC_ELS_RING) { |
| 4317 | switch (icmd->ulpCommand) { |
| 4318 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4319 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4320 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 4322 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 4323 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | case CMD_XMIT_ELS_RSP64_CX: |
| 4325 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4326 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4328 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4329 | |
| 4330 | } else if (pring->ringno == psli->fcp_ring) { |
| 4331 | /* Skip match check if waiting to relogin to FCP target */ |
| 4332 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4333 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4334 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | } |
| 4336 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4337 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | } |
| 4339 | } else if (pring->ringno == psli->next_ring) { |
| 4340 | |
| 4341 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4342 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | /* |
| 4346 | * Free resources / clean up outstanding I/Os |
| 4347 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 4348 | */ |
| 4349 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4350 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4351 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4352 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | struct lpfc_sli *psli; |
| 4354 | struct lpfc_sli_ring *pring; |
| 4355 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4356 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4358 | lpfc_fabric_abort_nport(ndlp); |
| 4359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | /* |
| 4361 | * Everything that matches on txcmplq will be returned |
| 4362 | * by firmware with a no rpi error. |
| 4363 | */ |
| 4364 | psli = &phba->sli; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4365 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | /* Now process each ring */ |
| 4367 | for (i = 0; i < psli->num_rings; i++) { |
| 4368 | pring = &psli->ring[i]; |
| 4369 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4371 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | /* |
| 4374 | * Check to see if iocb matches the nport we are |
| 4375 | * looking for |
| 4376 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4377 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 4378 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4379 | /* It matches, so deque and call compl |
| 4380 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4381 | list_move_tail(&iocb->list, |
| 4382 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | } |
| 4384 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4385 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | } |
| 4387 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4388 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4389 | /* Cancel all the IOCBs from the completions list */ |
| 4390 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4391 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4392 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4393 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4394 | } |
| 4395 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4396 | /** |
| 4397 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO |
| 4398 | * @phba: Pointer to HBA context object. |
| 4399 | * @pmb: Pointer to mailbox object. |
| 4400 | * |
| 4401 | * This function will issue an ELS LOGO command after completing |
| 4402 | * the UNREG_RPI. |
| 4403 | **/ |
| 4404 | void |
| 4405 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4406 | { |
| 4407 | struct lpfc_vport *vport = pmb->vport; |
| 4408 | struct lpfc_nodelist *ndlp; |
| 4409 | |
| 4410 | ndlp = (struct lpfc_nodelist *)(pmb->context1); |
| 4411 | if (!ndlp) |
| 4412 | return; |
| 4413 | lpfc_issue_els_logo(vport, ndlp, 0); |
| 4414 | } |
| 4415 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4416 | /* |
| 4417 | * Free rpi associated with LPFC_NODELIST entry. |
| 4418 | * This routine is called from lpfc_freenode(), when we are removing |
| 4419 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 4420 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 4421 | * to the remote NPort. In addition, it is called after we receive |
| 4422 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 4423 | * we are waiting to PLOGI back to the remote NPort. |
| 4424 | */ |
| 4425 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4426 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4428 | struct lpfc_hba *phba = vport->phba; |
| 4429 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | int rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4431 | uint16_t rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4433 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4434 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4435 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4436 | /* SLI4 ports require the physical rpi value. */ |
| 4437 | rpi = ndlp->nlp_rpi; |
| 4438 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4439 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4440 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4441 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4442 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4443 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
| 4444 | mbox->context1 = ndlp; |
| 4445 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
| 4446 | } else { |
| 4447 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4448 | } |
| 4449 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4450 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4452 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4453 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4454 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4455 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4456 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 4457 | ndlp->nlp_rpi = 0; |
| 4458 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 4459 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | return 1; |
| 4461 | } |
| 4462 | return 0; |
| 4463 | } |
| 4464 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4465 | /** |
| 4466 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 4467 | * @phba: pointer to lpfc hba data structure. |
| 4468 | * |
| 4469 | * This routine is invoked to unregister all the currently registered RPIs |
| 4470 | * to the HBA. |
| 4471 | **/ |
| 4472 | void |
| 4473 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 4474 | { |
| 4475 | struct lpfc_vport **vports; |
| 4476 | struct lpfc_nodelist *ndlp; |
| 4477 | struct Scsi_Host *shost; |
| 4478 | int i; |
| 4479 | |
| 4480 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4481 | if (!vports) { |
| 4482 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 4483 | "2884 Vport array allocation failed \n"); |
| 4484 | return; |
| 4485 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4486 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4487 | shost = lpfc_shost_from_vport(vports[i]); |
| 4488 | spin_lock_irq(shost->host_lock); |
| 4489 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4490 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4491 | /* The mempool_alloc might sleep */ |
| 4492 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4493 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4494 | spin_lock_irq(shost->host_lock); |
| 4495 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4496 | } |
| 4497 | spin_unlock_irq(shost->host_lock); |
| 4498 | } |
| 4499 | lpfc_destroy_vport_work_array(phba, vports); |
| 4500 | } |
| 4501 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4502 | void |
| 4503 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 4504 | { |
| 4505 | struct lpfc_hba *phba = vport->phba; |
| 4506 | LPFC_MBOXQ_t *mbox; |
| 4507 | int rc; |
| 4508 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 4509 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4510 | lpfc_sli4_unreg_all_rpis(vport); |
| 4511 | return; |
| 4512 | } |
| 4513 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4514 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4515 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4516 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
| 4517 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4518 | mbox->vport = vport; |
| 4519 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4520 | mbox->context1 = NULL; |
| 4521 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4522 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4523 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4524 | |
| 4525 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 4526 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4527 | "1836 Could not issue " |
| 4528 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | void |
| 4533 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 4534 | { |
| 4535 | struct lpfc_hba *phba = vport->phba; |
| 4536 | LPFC_MBOXQ_t *mbox; |
| 4537 | int rc; |
| 4538 | |
| 4539 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4540 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4541 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
| 4542 | mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4543 | mbox->vport = vport; |
| 4544 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4545 | mbox->context1 = NULL; |
| 4546 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4547 | if (rc != MBX_TIMEOUT) |
| 4548 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4549 | |
| 4550 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4551 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 4552 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4553 | "unreg_did (default rpis) status %d\n", |
| 4554 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4558 | /* |
| 4559 | * Free resources associated with LPFC_NODELIST entry |
| 4560 | * so it can be freed. |
| 4561 | */ |
| 4562 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4563 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4564 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4565 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4566 | struct lpfc_hba *phba = vport->phba; |
| 4567 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | |
| 4570 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4571 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4572 | "0900 Cleanup node for NPort x%x " |
| 4573 | "Data: x%x x%x x%x\n", |
| 4574 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4575 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4576 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4577 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4578 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 4579 | "usgmap:x%x refcnt:%d\n", |
| 4580 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4581 | atomic_read(&ndlp->kref.refcount)); |
| 4582 | lpfc_dequeue_node(vport, ndlp); |
| 4583 | } else { |
| 4584 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 4585 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 4586 | "usgmap:x%x refcnt:%d\n", |
| 4587 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4588 | atomic_read(&ndlp->kref.refcount)); |
| 4589 | lpfc_disable_node(vport, ndlp); |
| 4590 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4592 | |
| 4593 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ |
| 4594 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 4596 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4597 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4598 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 4600 | mb->context2 = NULL; |
| 4601 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4602 | } |
| 4603 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 4604 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | spin_lock_irq(&phba->hbalock); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4606 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
| 4607 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 4608 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4609 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 4610 | (ndlp != (struct lpfc_nodelist *) mb->context2)) |
| 4611 | continue; |
| 4612 | |
| 4613 | mb->context2 = NULL; |
| 4614 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4615 | } |
| 4616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4618 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4619 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4620 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4621 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 4622 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4623 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4624 | kfree(mp); |
| 4625 | } |
| 4626 | list_del(&mb->list); |
| 4627 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4628 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4629 | * the ndlp reference count as we are in the process |
| 4630 | * of lpfc_nlp_release. |
| 4631 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 | } |
| 4633 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4634 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4636 | lpfc_els_abort(phba, ndlp); |
| 4637 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4638 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4639 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4640 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4641 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4642 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4644 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4645 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4646 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4647 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4648 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4649 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4650 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | /* |
| 4654 | * Check to see if we can free the nlp back to the freelist. |
| 4655 | * If we are in the middle of using the nlp in the discovery state |
| 4656 | * machine, defer the free till we reach the end of the state machine. |
| 4657 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4658 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4659 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4661 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4662 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4663 | LPFC_MBOXQ_t *mbox; |
| 4664 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4666 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4667 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4668 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
| 4669 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4670 | /* For this case we need to cleanup the default rpi |
| 4671 | * allocated by the firmware. |
| 4672 | */ |
| 4673 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4674 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4675 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 4676 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4677 | if (rc) { |
| 4678 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4679 | } |
| 4680 | else { |
| 4681 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4682 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4683 | mbox->vport = vport; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 4684 | mbox->context2 = ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4685 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4686 | if (rc == MBX_NOT_FINISHED) { |
| 4687 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4688 | } |
| 4689 | } |
| 4690 | } |
| 4691 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4693 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4695 | * We can get here with a non-NULL ndlp->rport because when we |
| 4696 | * unregister a rport we don't break the rport/node linkage. So if we |
| 4697 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4698 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4699 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4700 | rdata = ndlp->rport->dd_data; |
| 4701 | rdata->pnode = NULL; |
| 4702 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4707 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4708 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | |
| 4712 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4713 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | /* First check for Direct match */ |
| 4716 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4717 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | |
| 4719 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4720 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4722 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | matchdid.un.word = did; |
| 4726 | ndlpdid.un.word = ndlp->nlp_DID; |
| 4727 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 4728 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 4729 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 4730 | if ((ndlpdid.un.b.domain == 0) && |
| 4731 | (ndlpdid.un.b.area == 0)) { |
| 4732 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4733 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4735 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | matchdid.un.word = ndlp->nlp_DID; |
| 4739 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 4740 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 4741 | if ((matchdid.un.b.domain == 0) && |
| 4742 | (matchdid.un.b.area == 0)) { |
| 4743 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4744 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | } |
| 4746 | } |
| 4747 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4748 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | } |
| 4750 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4751 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4752 | static struct lpfc_nodelist * |
| 4753 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4754 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 4755 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | uint32_t data1; |
| 4757 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4758 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 4759 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4760 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 4761 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 4762 | ((uint32_t) ndlp->nlp_type << 8) | |
| 4763 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4764 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4765 | "0929 FIND node DID " |
| 4766 | "Data: x%p x%x x%x x%x\n", |
| 4767 | ndlp, ndlp->nlp_DID, |
| 4768 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4769 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | } |
| 4771 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4774 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4775 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | return NULL; |
| 4777 | } |
| 4778 | |
| 4779 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4780 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4783 | struct lpfc_nodelist *ndlp; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4784 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4785 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4786 | spin_lock_irqsave(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | ndlp = __lpfc_findnode_did(vport, did); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4788 | spin_unlock_irqrestore(shost->host_lock, iflags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4789 | return ndlp; |
| 4790 | } |
| 4791 | |
| 4792 | struct lpfc_nodelist * |
| 4793 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 4794 | { |
| 4795 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4796 | struct lpfc_nodelist *ndlp; |
| 4797 | |
| 4798 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4799 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4800 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4801 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4802 | return NULL; |
| 4803 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4804 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | if (!ndlp) |
| 4806 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4807 | lpfc_nlp_init(vport, ndlp, did); |
| 4808 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4809 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4811 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4813 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4814 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4815 | if (!ndlp) |
| 4816 | return NULL; |
| 4817 | spin_lock_irq(shost->host_lock); |
| 4818 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4819 | spin_unlock_irq(shost->host_lock); |
| 4820 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4822 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4823 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4824 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4825 | if (lpfc_rscn_payload_check(vport, did)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4826 | /* If we've already received a PLOGI from this NPort |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4827 | * we don't need to try to discover it again. |
| 4828 | */ |
| 4829 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4830 | return NULL; |
| 4831 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4832 | /* Since this node is marked for discovery, |
| 4833 | * delay timeout is not needed. |
| 4834 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4835 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4836 | spin_lock_irq(shost->host_lock); |
| 4837 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4838 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4839 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4841 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4842 | /* If we've already received a PLOGI from this NPort, |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4843 | * or we are already in the process of discovery on it, |
| 4844 | * we don't need to try to discover it again. |
| 4845 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4846 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4847 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4848 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4849 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4851 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4853 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | } |
| 4855 | return ndlp; |
| 4856 | } |
| 4857 | |
| 4858 | /* Build a list of nodes to discover based on the loopmap */ |
| 4859 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4860 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4862 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | int j; |
| 4864 | uint32_t alpa, index; |
| 4865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4866 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4867 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4868 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4869 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4871 | |
| 4872 | /* Check for loop map present or not */ |
| 4873 | if (phba->alpa_map[0]) { |
| 4874 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4875 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4876 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4878 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | } |
| 4880 | } else { |
| 4881 | /* No alpamap, so try all alpa's */ |
| 4882 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4883 | /* If cfg_scan_down is set, start from highest |
| 4884 | * ALPA (0xef) to lowest (0x1). |
| 4885 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4886 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4887 | index = j; |
| 4888 | else |
| 4889 | index = FC_MAXLOOP - j - 1; |
| 4890 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4891 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4893 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4894 | } |
| 4895 | } |
| 4896 | return; |
| 4897 | } |
| 4898 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4900 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | struct lpfc_sli *psli = &phba->sli; |
| 4904 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4905 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4906 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4907 | int rc; |
| 4908 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4909 | /* |
| 4910 | * if it's not a physical port or if we already send |
| 4911 | * clear_la then don't send it. |
| 4912 | */ |
| 4913 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4914 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4915 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4916 | return; |
| 4917 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4918 | /* Link up discovery */ |
| 4919 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4920 | phba->link_state = LPFC_CLEAR_LA; |
| 4921 | lpfc_clear_la(phba, mbox); |
| 4922 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4923 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4924 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4925 | if (rc == MBX_NOT_FINISHED) { |
| 4926 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4927 | lpfc_disc_flush_list(vport); |
| 4928 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4929 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4930 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4931 | phba->link_state = LPFC_HBA_ERROR; |
| 4932 | } |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4937 | void |
| 4938 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4939 | { |
| 4940 | LPFC_MBOXQ_t *regvpimbox; |
| 4941 | |
| 4942 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4943 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4944 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4945 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4946 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4947 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4948 | == MBX_NOT_FINISHED) { |
| 4949 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 4955 | void |
| 4956 | lpfc_disc_start(struct lpfc_vport *vport) |
| 4957 | { |
| 4958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4959 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4960 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4962 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4964 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4966 | |
| 4967 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | clear_la_pending = 1; |
| 4969 | else |
| 4970 | clear_la_pending = 0; |
| 4971 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4972 | if (vport->port_state < LPFC_VPORT_READY) |
| 4973 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | lpfc_set_disctmo(vport); |
| 4976 | |
| 4977 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4978 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4979 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4980 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4981 | |
| 4982 | vport->fc_prevDID = vport->fc_myDID; |
| 4983 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4984 | |
| 4985 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4986 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4987 | "0202 Start Discovery hba state x%x " |
| 4988 | "Data: x%x x%x x%x\n", |
| 4989 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 4990 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4991 | |
| 4992 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4993 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | |
| 4995 | if (num_sent) |
| 4996 | return; |
| 4997 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4998 | /* Register the VPI for SLI3, NON-NPIV only. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4999 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5000 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5001 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 5002 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5003 | lpfc_issue_reg_vpi(phba, vport); |
| 5004 | return; |
| 5005 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5006 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5007 | /* |
| 5008 | * For SLI2, we need to set port_state to READY and continue |
| 5009 | * discovery. |
| 5010 | */ |
| 5011 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 5012 | /* If we get here, there is nothing to ADISC */ |
| 5013 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5014 | lpfc_issue_clear_la(phba, vport); |
| 5015 | |
| 5016 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5017 | vport->num_disc_nodes = 0; |
| 5018 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 5019 | if (vport->fc_npr_cnt) |
| 5020 | lpfc_els_disc_plogi(vport); |
| 5021 | |
| 5022 | if (!vport->num_disc_nodes) { |
| 5023 | spin_lock_irq(shost->host_lock); |
| 5024 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 5025 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5026 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | } |
| 5028 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5029 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | } else { |
| 5031 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5032 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | |
| 5034 | if (num_sent) |
| 5035 | return; |
| 5036 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5037 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5038 | /* Check to see if more RSCNs came in while we |
| 5039 | * were processing this one. |
| 5040 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5041 | if ((vport->fc_rscn_id_cnt == 0) && |
| 5042 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 5043 | spin_lock_irq(shost->host_lock); |
| 5044 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 5045 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5046 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5047 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5048 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | return; |
| 5052 | } |
| 5053 | |
| 5054 | /* |
| 5055 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 5056 | * ring the match the sppecified nodelist. |
| 5057 | */ |
| 5058 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5059 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5060 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5061 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5062 | struct lpfc_sli *psli; |
| 5063 | IOCB_t *icmd; |
| 5064 | struct lpfc_iocbq *iocb, *next_iocb; |
| 5065 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5066 | |
| 5067 | psli = &phba->sli; |
| 5068 | pring = &psli->ring[LPFC_ELS_RING]; |
| 5069 | |
| 5070 | /* Error matching iocb on txq or txcmplq |
| 5071 | * First check the txq. |
| 5072 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5073 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5074 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5075 | if (iocb->context1 != ndlp) { |
| 5076 | continue; |
| 5077 | } |
| 5078 | icmd = &iocb->iocb; |
| 5079 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 5080 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 5081 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5082 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | } |
| 5084 | } |
| 5085 | |
| 5086 | /* Next check the txcmplq */ |
| 5087 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 5088 | if (iocb->context1 != ndlp) { |
| 5089 | continue; |
| 5090 | } |
| 5091 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5092 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 5093 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5094 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5095 | } |
| 5096 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5097 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5098 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5099 | /* Cancel all the IOCBs from the completions list */ |
| 5100 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5101 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | } |
| 5103 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5104 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5105 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | { |
| 5107 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5108 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5109 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5110 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 5111 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5112 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5113 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5114 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5115 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 5116 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 5117 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5118 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5119 | } |
| 5120 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5121 | } |
| 5122 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5123 | void |
| 5124 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 5125 | { |
| 5126 | lpfc_els_flush_rscn(vport); |
| 5127 | lpfc_els_flush_cmd(vport); |
| 5128 | lpfc_disc_flush_list(vport); |
| 5129 | } |
| 5130 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | /*****************************************************************************/ |
| 5132 | /* |
| 5133 | * NAME: lpfc_disc_timeout |
| 5134 | * |
| 5135 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 5136 | * |
| 5137 | * EXECUTION ENVIRONMENT: interrupt only |
| 5138 | * |
| 5139 | * CALLED FROM: |
| 5140 | * Timer function |
| 5141 | * |
| 5142 | * RETURNS: |
| 5143 | * none |
| 5144 | */ |
| 5145 | /*****************************************************************************/ |
| 5146 | void |
| 5147 | lpfc_disc_timeout(unsigned long ptr) |
| 5148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5149 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5150 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5151 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | unsigned long flags = 0; |
| 5153 | |
| 5154 | if (unlikely(!phba)) |
| 5155 | return; |
| 5156 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5157 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 5158 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 5159 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5160 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5161 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5162 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5163 | if (!tmo_posted) |
| 5164 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | return; |
| 5166 | } |
| 5167 | |
| 5168 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5169 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5171 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5172 | struct lpfc_hba *phba = vport->phba; |
| 5173 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5174 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5175 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5176 | int rc, clrlaerr = 0; |
| 5177 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5178 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | return; |
| 5180 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5181 | spin_lock_irq(shost->host_lock); |
| 5182 | vport->fc_flag &= ~FC_DISC_TMO; |
| 5183 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5184 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5185 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5186 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 5187 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 5188 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | |
| 5191 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5192 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 5193 | * FAN |
| 5194 | */ |
| 5195 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5196 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 5197 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5198 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5199 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5200 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5201 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5202 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5203 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 5204 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5205 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 5206 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5207 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5208 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5209 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5210 | /* Fail outstanding IO now since device |
| 5211 | * is marked for PLOGI. |
| 5212 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5213 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5214 | } |
| 5215 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5216 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5217 | if (phba->sli_rev <= LPFC_SLI_REV3) |
| 5218 | lpfc_initial_flogi(vport); |
| 5219 | else |
| 5220 | lpfc_issue_init_vfi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5221 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5222 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5223 | break; |
| 5224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5225 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5227 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5229 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5230 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5231 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | |
| 5233 | /* Assume no Fabric and go on with discovery. |
| 5234 | * Check for outstanding ELS FLOGI to abort. |
| 5235 | */ |
| 5236 | |
| 5237 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5238 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | |
| 5240 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5241 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | break; |
| 5243 | |
| 5244 | case LPFC_FABRIC_CFG_LINK: |
| 5245 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 5246 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5247 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5248 | "0223 Timeout while waiting for " |
| 5249 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5250 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5251 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5252 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5253 | lpfc_els_abort(phba, ndlp); |
| 5254 | |
| 5255 | /* ReStart discovery */ |
| 5256 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | |
| 5258 | case LPFC_NS_QRY: |
| 5259 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5261 | "0224 NameServer Query timeout " |
| 5262 | "Data: x%x x%x\n", |
| 5263 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5265 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 5266 | /* Try it one more time */ |
| 5267 | vport->fc_ns_retry++; |
| 5268 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 5269 | vport->fc_ns_retry, 0); |
| 5270 | if (rc == 0) |
| 5271 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5272 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5273 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5275 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5276 | /* |
| 5277 | * Discovery is over. |
| 5278 | * set port_state to PORT_READY if SLI2. |
| 5279 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5280 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5281 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5282 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5283 | lpfc_issue_reg_vpi(phba, vport); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5284 | else { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5285 | lpfc_issue_clear_la(phba, vport); |
| 5286 | vport->port_state = LPFC_VPORT_READY; |
| 5287 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 5291 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5292 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5293 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5294 | "0206 Device Discovery " |
| 5295 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5296 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5297 | break; |
| 5298 | } |
| 5299 | |
| 5300 | lpfc_linkdown(phba); |
| 5301 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 5302 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5303 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5304 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5305 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5306 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 5307 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5308 | if (rc == MBX_NOT_FINISHED) |
| 5309 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 5310 | |
| 5311 | break; |
| 5312 | |
| 5313 | case LPFC_DISC_AUTH: |
| 5314 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5315 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5316 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5317 | lpfc_disc_flush_list(vport); |
| 5318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5319 | /* |
| 5320 | * set port_state to PORT_READY if SLI2. |
| 5321 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 5322 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5323 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 5324 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 5325 | lpfc_issue_reg_vpi(phba, vport); |
| 5326 | else { /* NPIV Not enabled */ |
| 5327 | lpfc_issue_clear_la(phba, vport); |
| 5328 | vport->port_state = LPFC_VPORT_READY; |
| 5329 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5330 | } |
| 5331 | break; |
| 5332 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5333 | case LPFC_VPORT_READY: |
| 5334 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5335 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5336 | "0231 RSCN timeout Data: x%x " |
| 5337 | "x%x\n", |
| 5338 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5339 | |
| 5340 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5341 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5343 | lpfc_els_flush_rscn(vport); |
| 5344 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5345 | } |
| 5346 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5347 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5348 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5349 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5350 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5351 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5352 | break; |
| 5353 | } |
| 5354 | |
| 5355 | switch (phba->link_state) { |
| 5356 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5357 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5358 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5359 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5360 | clrlaerr = 1; |
| 5361 | break; |
| 5362 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5363 | case LPFC_LINK_UP: |
| 5364 | lpfc_issue_clear_la(phba, vport); |
| 5365 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5366 | case LPFC_LINK_UNKNOWN: |
| 5367 | case LPFC_WARM_START: |
| 5368 | case LPFC_INIT_START: |
| 5369 | case LPFC_INIT_MBX_CMDS: |
| 5370 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5371 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5372 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 5373 | "0230 Unexpected timeout, hba link " |
| 5374 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5375 | clrlaerr = 1; |
| 5376 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5377 | |
| 5378 | case LPFC_HBA_READY: |
| 5379 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5383 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5384 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5385 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 5386 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5387 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | return; |
| 5391 | } |
| 5392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5393 | /* |
| 5394 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 5395 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 5396 | * as the completion routine when the command is |
| 5397 | * handed off to the SLI layer. |
| 5398 | */ |
| 5399 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5400 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5401 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5402 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5403 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 5404 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5405 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5406 | |
| 5407 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5408 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5409 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5410 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5411 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5412 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5414 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5415 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5416 | /* |
| 5417 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 5418 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 5419 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5422 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5423 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 5424 | else |
| 5425 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5427 | /* decrement the node reference count held for this callback |
| 5428 | * function. |
| 5429 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5430 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5431 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5432 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5433 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5434 | |
| 5435 | return; |
| 5436 | } |
| 5437 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5438 | static int |
| 5439 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 5440 | { |
| 5441 | uint16_t *rpi = param; |
| 5442 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 5443 | /* check for active node */ |
| 5444 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5445 | return 0; |
| 5446 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5447 | return ndlp->nlp_rpi == *rpi; |
| 5448 | } |
| 5449 | |
| 5450 | static int |
| 5451 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 5452 | { |
| 5453 | return memcmp(&ndlp->nlp_portname, param, |
| 5454 | sizeof(ndlp->nlp_portname)) == 0; |
| 5455 | } |
| 5456 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5457 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5458 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5460 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5462 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5463 | if (filter(ndlp, param)) { |
| 5464 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5465 | "3185 FIND node filter %p DID " |
| 5466 | "Data: x%p x%x x%x\n", |
| 5467 | filter, ndlp, ndlp->nlp_DID, |
| 5468 | ndlp->nlp_flag); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5469 | return ndlp; |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5470 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5471 | } |
James Smart | 34f5ad8 | 2012-08-03 12:35:03 -0400 | [diff] [blame] | 5472 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 5473 | "3186 FIND node filter %p NOT FOUND.\n", filter); |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 5474 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | } |
| 5476 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5477 | /* |
| 5478 | * 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] | 5479 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5480 | */ |
| 5481 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5482 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5483 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5484 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5485 | } |
| 5486 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5487 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5488 | * 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] | 5489 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5490 | */ |
| 5491 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5492 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5494 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5495 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5496 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5497 | spin_lock_irq(shost->host_lock); |
| 5498 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 5499 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5500 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5501 | } |
| 5502 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5503 | /* |
| 5504 | * This routine looks up the ndlp lists for the given RPI. If the rpi |
| 5505 | * is found, the routine returns the node element list pointer else |
| 5506 | * return NULL. |
| 5507 | */ |
| 5508 | struct lpfc_nodelist * |
| 5509 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
| 5510 | { |
| 5511 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5512 | struct lpfc_nodelist *ndlp; |
| 5513 | |
| 5514 | spin_lock_irq(shost->host_lock); |
| 5515 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
| 5516 | spin_unlock_irq(shost->host_lock); |
| 5517 | return ndlp; |
| 5518 | } |
| 5519 | |
| 5520 | /** |
| 5521 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
| 5522 | * @phba: pointer to lpfc hba data structure. |
| 5523 | * @vpi: the physical host virtual N_Port identifier. |
| 5524 | * |
| 5525 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5526 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5527 | * of the vport with the matching @vpi. |
| 5528 | * |
| 5529 | * Return code |
| 5530 | * NULL - No vport with the matching @vpi found |
| 5531 | * Otherwise - Address to the vport with the matching @vpi. |
| 5532 | **/ |
| 5533 | struct lpfc_vport * |
| 5534 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5535 | { |
| 5536 | struct lpfc_vport *vport; |
| 5537 | unsigned long flags; |
| 5538 | int i = 0; |
| 5539 | |
| 5540 | /* The physical ports are always vpi 0 - translate is unnecessary. */ |
| 5541 | if (vpi > 0) { |
| 5542 | /* |
| 5543 | * Translate the physical vpi to the logical vpi. The |
| 5544 | * vport stores the logical vpi. |
| 5545 | */ |
| 5546 | for (i = 0; i < phba->max_vpi; i++) { |
| 5547 | if (vpi == phba->vpi_ids[i]) |
| 5548 | break; |
| 5549 | } |
| 5550 | |
| 5551 | if (i >= phba->max_vpi) { |
| 5552 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 5553 | "2936 Could not find Vport mapped " |
| 5554 | "to vpi %d\n", vpi); |
| 5555 | return NULL; |
| 5556 | } |
| 5557 | } |
| 5558 | |
| 5559 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5560 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 5561 | if (vport->vpi == i) { |
| 5562 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5563 | return vport; |
| 5564 | } |
| 5565 | } |
| 5566 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5567 | return NULL; |
| 5568 | } |
| 5569 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5571 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5572 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | { |
| 5574 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 5575 | |
| 5576 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5577 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5578 | |
| 5579 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 5580 | "node init: did:x%x", |
| 5581 | ndlp->nlp_DID, 0, 0); |
| 5582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | return; |
| 5584 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5585 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5586 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 5587 | * and mempool_free's the nodelist. |
| 5588 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 5589 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5590 | lpfc_nlp_release(struct kref *kref) |
| 5591 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5592 | struct lpfc_hba *phba; |
| 5593 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5594 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 5595 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5596 | |
| 5597 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5598 | "node release: did:x%x flg:x%x type:x%x", |
| 5599 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 5600 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5601 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5602 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5603 | "usgmap:x%x refcnt:%d\n", |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 5604 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5605 | atomic_read(&ndlp->kref.refcount)); |
| 5606 | |
| 5607 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5608 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5609 | |
| 5610 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5611 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5612 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5613 | NLP_CLR_NODE_ACT(ndlp); |
| 5614 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 5615 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5616 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5617 | |
| 5618 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5619 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 5620 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5621 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5622 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5623 | } |
| 5624 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5625 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 5626 | * that one discovery thread won't free a ndlp while another discovery thread |
| 5627 | * is using it. |
| 5628 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5629 | struct lpfc_nodelist * |
| 5630 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 5631 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5632 | struct lpfc_hba *phba; |
| 5633 | unsigned long flags; |
| 5634 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5635 | if (ndlp) { |
| 5636 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5637 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 5638 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5639 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5640 | /* The check of ndlp usage to prevent incrementing the |
| 5641 | * ndlp reference count that is in the process of being |
| 5642 | * released. |
| 5643 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5644 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5645 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5646 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 5647 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5648 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5649 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 5650 | "usgmap:x%x refcnt:%d\n", |
| 5651 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5652 | atomic_read(&ndlp->kref.refcount)); |
| 5653 | return NULL; |
| 5654 | } else |
| 5655 | kref_get(&ndlp->kref); |
| 5656 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5657 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5658 | return ndlp; |
| 5659 | } |
| 5660 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5661 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5662 | * count goes to 0, this indicates the the associated nodelist should be |
| 5663 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 5664 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 5665 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5666 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5667 | int |
| 5668 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 5669 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5670 | struct lpfc_hba *phba; |
| 5671 | unsigned long flags; |
| 5672 | |
| 5673 | if (!ndlp) |
| 5674 | return 1; |
| 5675 | |
| 5676 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5677 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 5678 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5679 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5680 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5681 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 5682 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 5683 | * possible race condition that kref_put got invoked again |
| 5684 | * after previous one has done ndlp memory free. |
| 5685 | */ |
| 5686 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 5687 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5688 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5689 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 5690 | "usgmap:x%x refcnt:%d\n", |
| 5691 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5692 | atomic_read(&ndlp->kref.refcount)); |
| 5693 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5694 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5695 | /* Check the ndlp inactivate log flag to avoid the possible |
| 5696 | * race condition that kref_put got invoked again after ndlp |
| 5697 | * is already in inactivating state. |
| 5698 | */ |
| 5699 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 5700 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5701 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5702 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 5703 | "usgmap:x%x refcnt:%d\n", |
| 5704 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5705 | atomic_read(&ndlp->kref.refcount)); |
| 5706 | return 1; |
| 5707 | } |
| 5708 | /* For last put, mark the ndlp usage flags to make sure no |
| 5709 | * other kref_get and kref_put on the same ndlp shall get |
| 5710 | * in between the process when the final kref_put has been |
| 5711 | * invoked on this ndlp. |
| 5712 | */ |
| 5713 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 5714 | /* Indicate ndlp is put to inactive state. */ |
| 5715 | NLP_SET_IACT_REQ(ndlp); |
| 5716 | /* Acknowledge ndlp memory free has been seen. */ |
| 5717 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 5718 | NLP_SET_FREE_ACK(ndlp); |
| 5719 | } |
| 5720 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5721 | /* Note, the kref_put returns 1 when decrementing a reference |
| 5722 | * count that was 1, it invokes the release callback function, |
| 5723 | * but it still left the reference count as 1 (not actually |
| 5724 | * performs the last decrementation). Otherwise, it actually |
| 5725 | * decrements the reference count and returns 0. |
| 5726 | */ |
| 5727 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5728 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5729 | |
| 5730 | /* 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] | 5731 | * by any other discovery thread. This routine returns 1 if the |
| 5732 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 5733 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5734 | */ |
| 5735 | int |
| 5736 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 5737 | { |
| 5738 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5739 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 5740 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5741 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5742 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 5743 | if (lpfc_nlp_put(ndlp)) |
| 5744 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5745 | return 0; |
| 5746 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5747 | |
| 5748 | /** |
| 5749 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 5750 | * @phba: Pointer to hba context object. |
| 5751 | * |
| 5752 | * This function iterate through all FC nodes associated |
| 5753 | * will all vports to check if there is any node with |
| 5754 | * fc_rports associated with it. If there is an fc_rport |
| 5755 | * associated with the node, then the node is either in |
| 5756 | * discovered state or its devloss_timer is pending. |
| 5757 | */ |
| 5758 | static int |
| 5759 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 5760 | { |
| 5761 | struct lpfc_vport **vports; |
| 5762 | int i, ret = 0; |
| 5763 | struct lpfc_nodelist *ndlp; |
| 5764 | struct Scsi_Host *shost; |
| 5765 | |
| 5766 | vports = lpfc_create_vport_work_array(phba); |
| 5767 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5768 | /* If driver cannot allocate memory, indicate fcf is in use */ |
| 5769 | if (!vports) |
| 5770 | return 1; |
| 5771 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5772 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5773 | shost = lpfc_shost_from_vport(vports[i]); |
| 5774 | spin_lock_irq(shost->host_lock); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5775 | /* |
| 5776 | * IF the CVL_RCVD bit is not set then we have sent the |
| 5777 | * flogi. |
| 5778 | * If dev_loss fires while we are waiting we do not want to |
| 5779 | * unreg the fcf. |
| 5780 | */ |
| 5781 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { |
| 5782 | spin_unlock_irq(shost->host_lock); |
| 5783 | ret = 1; |
| 5784 | goto out; |
| 5785 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5786 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 5787 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 5788 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 5789 | ret = 1; |
| 5790 | spin_unlock_irq(shost->host_lock); |
| 5791 | goto out; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5792 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
| 5793 | ret = 1; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5794 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5795 | "2624 RPI %x DID %x flag %x " |
| 5796 | "still logged in\n", |
| 5797 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5798 | ndlp->nlp_flag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5799 | } |
| 5800 | } |
| 5801 | spin_unlock_irq(shost->host_lock); |
| 5802 | } |
| 5803 | out: |
| 5804 | lpfc_destroy_vport_work_array(phba, vports); |
| 5805 | return ret; |
| 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 5810 | * @phba: Pointer to hba context object. |
| 5811 | * @mboxq: Pointer to mailbox object. |
| 5812 | * |
| 5813 | * This function frees memory associated with the mailbox command. |
| 5814 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5815 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5816 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5817 | { |
| 5818 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5819 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5820 | |
| 5821 | if (mboxq->u.mb.mbxStatus) { |
| 5822 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5823 | "2555 UNREG_VFI mbxStatus error x%x " |
| 5824 | "HBA state x%x\n", |
| 5825 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5826 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5827 | spin_lock_irq(shost->host_lock); |
| 5828 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 5829 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5830 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5831 | return; |
| 5832 | } |
| 5833 | |
| 5834 | /** |
| 5835 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 5836 | * @phba: Pointer to hba context object. |
| 5837 | * @mboxq: Pointer to mailbox object. |
| 5838 | * |
| 5839 | * This function frees memory associated with the mailbox command. |
| 5840 | */ |
| 5841 | static void |
| 5842 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5843 | { |
| 5844 | struct lpfc_vport *vport = mboxq->vport; |
| 5845 | |
| 5846 | if (mboxq->u.mb.mbxStatus) { |
| 5847 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5848 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 5849 | "HBA state x%x\n", |
| 5850 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5851 | } |
| 5852 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5853 | return; |
| 5854 | } |
| 5855 | |
| 5856 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5857 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5858 | * @phba: Pointer to hba context object. |
| 5859 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5860 | * This function prepare the HBA for unregistering the currently registered |
| 5861 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 5862 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5863 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5864 | int |
| 5865 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5866 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5867 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5868 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5869 | struct Scsi_Host *shost; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5870 | int i, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5871 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5872 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5873 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5874 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5875 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5876 | /* At this point, all discovery is aborted */ |
| 5877 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5878 | |
| 5879 | /* Unregister VPIs */ |
| 5880 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5881 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5882 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5883 | /* Stop FLOGI/FDISC retries */ |
| 5884 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 5885 | if (ndlp) |
| 5886 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5887 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 5888 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5889 | lpfc_sli4_unreg_all_rpis(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5890 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5891 | shost = lpfc_shost_from_vport(vports[i]); |
| 5892 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5893 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5894 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5895 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5896 | } |
| 5897 | lpfc_destroy_vport_work_array(phba, vports); |
| 5898 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5899 | /* Cleanup any outstanding ELS commands */ |
| 5900 | lpfc_els_flush_all_cmd(phba); |
| 5901 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5902 | /* Unregister the physical port VFI */ |
| 5903 | rc = lpfc_issue_unreg_vfi(phba->pport); |
| 5904 | return rc; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5909 | * @phba: Pointer to hba context object. |
| 5910 | * |
| 5911 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5912 | * unregister the currently registered FCF record. The driver does not reset |
| 5913 | * the driver FCF usage state flags. |
| 5914 | * |
| 5915 | * Return 0 if successfully issued, none-zero otherwise. |
| 5916 | */ |
| 5917 | int |
| 5918 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 5919 | { |
| 5920 | LPFC_MBOXQ_t *mbox; |
| 5921 | int rc; |
| 5922 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5923 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5924 | if (!mbox) { |
| 5925 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5926 | "2551 UNREG_FCFI mbox allocation failed" |
| 5927 | "HBA state x%x\n", phba->pport->port_state); |
| 5928 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5929 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5930 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 5931 | mbox->vport = phba->pport; |
| 5932 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 5933 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5934 | |
| 5935 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5936 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5937 | "2552 Unregister FCFI command failed rc x%x " |
| 5938 | "HBA state x%x\n", |
| 5939 | rc, phba->pport->port_state); |
| 5940 | return -EINVAL; |
| 5941 | } |
| 5942 | return 0; |
| 5943 | } |
| 5944 | |
| 5945 | /** |
| 5946 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 5947 | * @phba: Pointer to hba context object. |
| 5948 | * |
| 5949 | * This function unregisters the currently reigstered FCF. This function |
| 5950 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 5951 | */ |
| 5952 | void |
| 5953 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 5954 | { |
| 5955 | int rc; |
| 5956 | |
| 5957 | /* Preparation for unregistering fcf */ |
| 5958 | rc = lpfc_unregister_fcf_prep(phba); |
| 5959 | if (rc) { |
| 5960 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5961 | "2748 Failed to prepare for unregistering " |
| 5962 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5963 | return; |
| 5964 | } |
| 5965 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5966 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5967 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5968 | if (rc) |
| 5969 | return; |
| 5970 | /* Reset HBA FCF states after successful unregister FCF */ |
| 5971 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5972 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5973 | |
| 5974 | /* |
| 5975 | * If driver is not unloading, check if there is any other |
| 5976 | * FCF record that can be used for discovery. |
| 5977 | */ |
| 5978 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5979 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5980 | return; |
| 5981 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5982 | /* This is considered as the initial FCF discovery scan */ |
| 5983 | spin_lock_irq(&phba->hbalock); |
| 5984 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 5985 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5986 | |
| 5987 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5988 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5989 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5990 | 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] | 5991 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5992 | if (rc) { |
| 5993 | spin_lock_irq(&phba->hbalock); |
| 5994 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 5995 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5996 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5997 | "2553 lpfc_unregister_unused_fcf failed " |
| 5998 | "to read FCF record HBA state x%x\n", |
| 5999 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6000 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | /** |
| 6004 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 6005 | * @phba: Pointer to hba context object. |
| 6006 | * |
| 6007 | * This function just unregisters the currently reigstered FCF. It does not |
| 6008 | * try to find another FCF for discovery. |
| 6009 | */ |
| 6010 | void |
| 6011 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 6012 | { |
| 6013 | int rc; |
| 6014 | |
| 6015 | /* Preparation for unregistering fcf */ |
| 6016 | rc = lpfc_unregister_fcf_prep(phba); |
| 6017 | if (rc) { |
| 6018 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 6019 | "2749 Failed to prepare for unregistering " |
| 6020 | "HBA's FCF record: rc=%d\n", rc); |
| 6021 | return; |
| 6022 | } |
| 6023 | |
| 6024 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 6025 | rc = lpfc_sli4_unregister_fcf(phba); |
| 6026 | if (rc) |
| 6027 | return; |
| 6028 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 6029 | spin_lock_irq(&phba->hbalock); |
| 6030 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 6031 | spin_unlock_irq(&phba->hbalock); |
| 6032 | } |
| 6033 | |
| 6034 | /** |
| 6035 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 6036 | * @phba: Pointer to hba context object. |
| 6037 | * |
| 6038 | * This function check if there are any connected remote port for the FCF and |
| 6039 | * if all the devices are disconnected, this function unregister FCFI. |
| 6040 | * This function also tries to use another FCF for discovery. |
| 6041 | */ |
| 6042 | void |
| 6043 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 6044 | { |
| 6045 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6046 | * If HBA is not running in FIP mode, if HBA does not support |
| 6047 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 6048 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6049 | */ |
| 6050 | spin_lock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6051 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6052 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6053 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6054 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 6055 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6056 | spin_unlock_irq(&phba->hbalock); |
| 6057 | return; |
| 6058 | } |
| 6059 | spin_unlock_irq(&phba->hbalock); |
| 6060 | |
| 6061 | if (lpfc_fcf_inuse(phba)) |
| 6062 | return; |
| 6063 | |
| 6064 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 6069 | * @phba: Pointer to hba context object. |
| 6070 | * @buff: Buffer containing the FCF connection table as in the config |
| 6071 | * region. |
| 6072 | * This function create driver data structure for the FCF connection |
| 6073 | * record table read from config region 23. |
| 6074 | */ |
| 6075 | static void |
| 6076 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 6077 | uint8_t *buff) |
| 6078 | { |
| 6079 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6080 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 6081 | struct lpfc_fcf_conn_rec *conn_rec; |
| 6082 | uint32_t record_count; |
| 6083 | int i; |
| 6084 | |
| 6085 | /* Free the current connect table */ |
| 6086 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6087 | &phba->fcf_conn_rec_list, list) { |
| 6088 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6089 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6090 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6091 | |
| 6092 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 6093 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 6094 | sizeof(struct lpfc_fcf_conn_rec); |
| 6095 | |
| 6096 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 6097 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 6098 | |
| 6099 | for (i = 0; i < record_count; i++) { |
| 6100 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 6101 | continue; |
| 6102 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 6103 | GFP_KERNEL); |
| 6104 | if (!conn_entry) { |
| 6105 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6106 | "2566 Failed to allocate connection" |
| 6107 | " table entry\n"); |
| 6108 | return; |
| 6109 | } |
| 6110 | |
| 6111 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 6112 | sizeof(struct lpfc_fcf_conn_rec)); |
| 6113 | conn_entry->conn_rec.vlan_tag = |
| 6114 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 6115 | conn_entry->conn_rec.flags = |
| 6116 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 6117 | list_add_tail(&conn_entry->list, |
| 6118 | &phba->fcf_conn_rec_list); |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | /** |
| 6123 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 6124 | * @phba: Pointer to hba context object. |
| 6125 | * @buff: Buffer containing the FCoE parameter data structure. |
| 6126 | * |
| 6127 | * This function update driver data structure with config |
| 6128 | * parameters read from config region 23. |
| 6129 | */ |
| 6130 | static void |
| 6131 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 6132 | uint8_t *buff) |
| 6133 | { |
| 6134 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 6135 | struct lpfc_fcoe_params *fcoe_param; |
| 6136 | |
| 6137 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 6138 | buff; |
| 6139 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 6140 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6141 | |
| 6142 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 6143 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 6144 | return; |
| 6145 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6146 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 6147 | phba->valid_vlan = 1; |
| 6148 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 6149 | 0xFFF; |
| 6150 | } |
| 6151 | |
| 6152 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 6153 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 6154 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 6155 | return; |
| 6156 | } |
| 6157 | |
| 6158 | /** |
| 6159 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 6160 | * @buff: Buffer containing config region 23 data. |
| 6161 | * @size: Size of the data buffer. |
| 6162 | * @rec_type: Record type to be searched. |
| 6163 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6164 | * This function searches config region data to find the beginning |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6165 | * of the record specified by record_type. If record found, this |
| 6166 | * function return pointer to the record else return NULL. |
| 6167 | */ |
| 6168 | static uint8_t * |
| 6169 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 6170 | { |
| 6171 | uint32_t offset = 0, rec_length; |
| 6172 | |
| 6173 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 6174 | (size < sizeof(uint32_t))) |
| 6175 | return NULL; |
| 6176 | |
| 6177 | rec_length = buff[offset + 1]; |
| 6178 | |
| 6179 | /* |
| 6180 | * One TLV record has one word header and number of data words |
| 6181 | * specified in the rec_length field of the record header. |
| 6182 | */ |
| 6183 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 6184 | <= size) { |
| 6185 | if (buff[offset] == rec_type) |
| 6186 | return &buff[offset]; |
| 6187 | |
| 6188 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 6189 | return NULL; |
| 6190 | |
| 6191 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 6192 | rec_length = buff[offset + 1]; |
| 6193 | } |
| 6194 | return NULL; |
| 6195 | } |
| 6196 | |
| 6197 | /** |
| 6198 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 6199 | * @phba: Pointer to lpfc_hba data structure. |
| 6200 | * @buff: Buffer containing config region 23 data. |
| 6201 | * @size: Size of the data buffer. |
| 6202 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 6203 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6204 | * populate driver data structure with the parameters. |
| 6205 | */ |
| 6206 | void |
| 6207 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 6208 | uint8_t *buff, |
| 6209 | uint32_t size) |
| 6210 | { |
| 6211 | uint32_t offset = 0, rec_length; |
| 6212 | uint8_t *rec_ptr; |
| 6213 | |
| 6214 | /* |
| 6215 | * If data size is less than 2 words signature and version cannot be |
| 6216 | * verified. |
| 6217 | */ |
| 6218 | if (size < 2*sizeof(uint32_t)) |
| 6219 | return; |
| 6220 | |
| 6221 | /* Check the region signature first */ |
| 6222 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 6223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6224 | "2567 Config region 23 has bad signature\n"); |
| 6225 | return; |
| 6226 | } |
| 6227 | |
| 6228 | offset += 4; |
| 6229 | |
| 6230 | /* Check the data structure version */ |
| 6231 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 6232 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6233 | "2568 Config region 23 has bad version\n"); |
| 6234 | return; |
| 6235 | } |
| 6236 | offset += 4; |
| 6237 | |
| 6238 | rec_length = buff[offset + 1]; |
| 6239 | |
| 6240 | /* Read FCoE param record */ |
| 6241 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6242 | size - offset, FCOE_PARAM_TYPE); |
| 6243 | if (rec_ptr) |
| 6244 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 6245 | |
| 6246 | /* Read FCF connection table */ |
| 6247 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 6248 | size - offset, FCOE_CONN_TBL_TYPE); |
| 6249 | if (rec_ptr) |
| 6250 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 6251 | |
| 6252 | } |