| 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 | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/pci.h> |
| 25 | #include <linux/kthread.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 28 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_host.h> |
| 31 | #include <scsi/scsi_transport_fc.h> |
| 32 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 33 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_scsi.h" |
| 40 | #include "lpfc.h" |
| 41 | #include "lpfc_logmsg.h" |
| 42 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 43 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 44 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | |
| 46 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 47 | static uint8_t lpfcAlpaArray[] = { |
| 48 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 49 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 50 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 51 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 52 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 53 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 54 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 55 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 56 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 57 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 58 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 59 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 60 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 61 | }; |
| 62 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 63 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 64 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 65 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 66 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 67 | void |
| 68 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 69 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 70 | struct lpfc_rport_data *rdata; |
| 71 | struct lpfc_nodelist * ndlp; |
| 72 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 73 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 74 | rdata = rport->dd_data; |
| 75 | ndlp = rdata->pnode; |
| 76 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 77 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 78 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 79 | printk(KERN_ERR "Cannot find remote node" |
| 80 | " to terminate I/O Data x%x\n", |
| 81 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 85 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 86 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 87 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 88 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 89 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 90 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 91 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 92 | lpfc_sli_abort_iocb(ndlp->vport, |
| 93 | &phba->sli.ring[phba->sli.fcp_ring], |
| 94 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 95 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * This function will be called when dev_loss_tmo fire. |
| 100 | */ |
| 101 | void |
| 102 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 103 | { |
| 104 | struct lpfc_rport_data *rdata; |
| 105 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 106 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 107 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 108 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 109 | int put_node; |
| 110 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 111 | |
| 112 | rdata = rport->dd_data; |
| 113 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 114 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 115 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 116 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 117 | vport = ndlp->vport; |
| 118 | phba = vport->phba; |
| 119 | |
| 120 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 121 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 122 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 123 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 124 | /* Don't defer this if we are in the process of deleting the vport |
| 125 | * or unloading the driver. The unload will cleanup the node |
| 126 | * appropriately we just need to cleanup the ndlp rport info here. |
| 127 | */ |
| 128 | if (vport->load_flag & FC_UNLOADING) { |
| 129 | put_node = rdata->pnode != NULL; |
| 130 | put_rport = ndlp->rport != NULL; |
| 131 | rdata->pnode = NULL; |
| 132 | ndlp->rport = NULL; |
| 133 | if (put_node) |
| 134 | lpfc_nlp_put(ndlp); |
| 135 | if (put_rport) |
| 136 | put_device(&rport->dev); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 141 | return; |
| 142 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 143 | evtp = &ndlp->dev_loss_evt; |
| 144 | |
| 145 | if (!list_empty(&evtp->evt_listp)) |
| 146 | return; |
| 147 | |
| 148 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 149 | /* We need to hold the node by incrementing the reference |
| 150 | * count until this queued work is done |
| 151 | */ |
| 152 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 153 | if (evtp->evt_arg1) { |
| 154 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 155 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 156 | lpfc_worker_wake_up(phba); |
| 157 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 158 | spin_unlock_irq(&phba->hbalock); |
| 159 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * This function is called from the worker thread when dev_loss_tmo |
| 165 | * expire. |
| 166 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 167 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 168 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 169 | { |
| 170 | struct lpfc_rport_data *rdata; |
| 171 | struct fc_rport *rport; |
| 172 | struct lpfc_vport *vport; |
| 173 | struct lpfc_hba *phba; |
| 174 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 175 | int put_node; |
| 176 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 177 | int warn_on = 0; |
| 178 | |
| 179 | rport = ndlp->rport; |
| 180 | |
| 181 | if (!rport) |
| 182 | return; |
| 183 | |
| 184 | rdata = rport->dd_data; |
| 185 | name = (uint8_t *) &ndlp->nlp_portname; |
| 186 | vport = ndlp->vport; |
| 187 | phba = vport->phba; |
| 188 | |
| 189 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 190 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 191 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 192 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 193 | /* Don't defer this if we are in the process of deleting the vport |
| 194 | * or unloading the driver. The unload will cleanup the node |
| 195 | * appropriately we just need to cleanup the ndlp rport info here. |
| 196 | */ |
| 197 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 198 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 199 | /* flush the target */ |
| 200 | lpfc_sli_abort_iocb(vport, |
| 201 | &phba->sli.ring[phba->sli.fcp_ring], |
| 202 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 203 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 204 | put_node = rdata->pnode != NULL; |
| 205 | put_rport = ndlp->rport != NULL; |
| 206 | rdata->pnode = NULL; |
| 207 | ndlp->rport = NULL; |
| 208 | if (put_node) |
| 209 | lpfc_nlp_put(ndlp); |
| 210 | if (put_rport) |
| 211 | put_device(&rport->dev); |
| 212 | return; |
| 213 | } |
| 214 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 215 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 216 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 217 | "0284 Devloss timeout Ignored on " |
| 218 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 219 | "NPort x%x\n", |
| 220 | *name, *(name+1), *(name+2), *(name+3), |
| 221 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 222 | ndlp->nlp_DID); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 223 | return; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 224 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 227 | /* We will clean up these Nodes in linkup */ |
| 228 | put_node = rdata->pnode != NULL; |
| 229 | put_rport = ndlp->rport != NULL; |
| 230 | rdata->pnode = NULL; |
| 231 | ndlp->rport = NULL; |
| 232 | if (put_node) |
| 233 | lpfc_nlp_put(ndlp); |
| 234 | if (put_rport) |
| 235 | put_device(&rport->dev); |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 236 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 240 | warn_on = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | /* flush the target */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 242 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 243 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 245 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 246 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 247 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 248 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 249 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 250 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 251 | *name, *(name+1), *(name+2), *(name+3), |
| 252 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 253 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 254 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 255 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 256 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 257 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 258 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 259 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 260 | *name, *(name+1), *(name+2), *(name+3), |
| 261 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 262 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 263 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 264 | } |
| 265 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 266 | put_node = rdata->pnode != NULL; |
| 267 | put_rport = ndlp->rport != NULL; |
| 268 | rdata->pnode = NULL; |
| 269 | ndlp->rport = NULL; |
| 270 | if (put_node) |
| 271 | lpfc_nlp_put(ndlp); |
| 272 | if (put_rport) |
| 273 | put_device(&rport->dev); |
| 274 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 275 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 276 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 277 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 278 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 279 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
| 280 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 281 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 282 | |
| 283 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 284 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 285 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 286 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 287 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 288 | * @phba: Pointer to hba context object. |
| 289 | * |
| 290 | * This function is called from the functions which need to post |
| 291 | * events from interrupt context. This function allocates data |
| 292 | * structure required for posting event. It also keeps track of |
| 293 | * number of events pending and prevent event storm when there are |
| 294 | * too many events. |
| 295 | **/ |
| 296 | struct lpfc_fast_path_event * |
| 297 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 298 | struct lpfc_fast_path_event *ret; |
| 299 | |
| 300 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 301 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 302 | return NULL; |
| 303 | |
| 304 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 305 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 306 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 307 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 308 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 309 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 310 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 315 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 316 | * @phba: Pointer to hba context object. |
| 317 | * @evt: Event object which need to be freed. |
| 318 | * |
| 319 | * This function frees the data structure required for posting |
| 320 | * events. |
| 321 | **/ |
| 322 | void |
| 323 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 324 | struct lpfc_fast_path_event *evt) { |
| 325 | |
| 326 | atomic_dec(&phba->fast_event_count); |
| 327 | kfree(evt); |
| 328 | } |
| 329 | |
| 330 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 331 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 332 | * @phba: Pointer to hba context object. |
| 333 | * @evtp: Event data structure. |
| 334 | * |
| 335 | * This function is called from worker thread, when the interrupt |
| 336 | * context need to post an event. This function posts the event |
| 337 | * to fc transport netlink interface. |
| 338 | **/ |
| 339 | static void |
| 340 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 341 | struct lpfc_work_evt *evtp) |
| 342 | { |
| 343 | unsigned long evt_category, evt_sub_category; |
| 344 | struct lpfc_fast_path_event *fast_evt_data; |
| 345 | char *evt_data; |
| 346 | uint32_t evt_data_size; |
| 347 | struct Scsi_Host *shost; |
| 348 | |
| 349 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 350 | work_evt); |
| 351 | |
| 352 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 353 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 354 | fabric_evt.subcategory; |
| 355 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 356 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 357 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 358 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 359 | evt_data_size = sizeof(fast_evt_data->un. |
| 360 | read_check_error); |
| 361 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 362 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 363 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 364 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 365 | } else { |
| 366 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 367 | return; |
| 368 | } |
| 369 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 370 | switch (evt_sub_category) { |
| 371 | case LPFC_EVENT_QFULL: |
| 372 | case LPFC_EVENT_DEVBSY: |
| 373 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 374 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 375 | break; |
| 376 | case LPFC_EVENT_CHECK_COND: |
| 377 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 378 | evt_data_size = sizeof(fast_evt_data->un. |
| 379 | check_cond_evt); |
| 380 | break; |
| 381 | case LPFC_EVENT_VARQUEDEPTH: |
| 382 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 383 | evt_data_size = sizeof(fast_evt_data->un. |
| 384 | queue_depth_evt); |
| 385 | break; |
| 386 | default: |
| 387 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 388 | return; |
| 389 | } |
| 390 | } else { |
| 391 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | fc_host_post_vendor_event(shost, |
| 396 | fc_get_event_number(), |
| 397 | evt_data_size, |
| 398 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 399 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 400 | |
| 401 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 402 | return; |
| 403 | } |
| 404 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 406 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | { |
| 408 | struct lpfc_work_evt *evtp = NULL; |
| 409 | struct lpfc_nodelist *ndlp; |
| 410 | int free_evt; |
| 411 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | spin_lock_irq(&phba->hbalock); |
| 413 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 415 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 416 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 418 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 419 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 420 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 422 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 423 | /* decrement the node reference count held |
| 424 | * for this queued work |
| 425 | */ |
| 426 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 428 | case LPFC_EVT_DEV_LOSS: |
| 429 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 430 | lpfc_dev_loss_tmo_handler(ndlp); |
| 431 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 432 | /* decrement the node reference count held for |
| 433 | * this queued work |
| 434 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 435 | lpfc_nlp_put(ndlp); |
| 436 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | if (phba->link_state < LPFC_LINK_DOWN) |
| 439 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 440 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 441 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | complete((struct completion *)(evtp->evt_arg2)); |
| 443 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 444 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 445 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 446 | lpfc_offline_prep(phba); |
| 447 | *(int *)(evtp->evt_arg1) = 0; |
| 448 | complete((struct completion *)(evtp->evt_arg2)); |
| 449 | break; |
| 450 | case LPFC_EVT_OFFLINE: |
| 451 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 452 | lpfc_sli_brdrestart(phba); |
| 453 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 454 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 455 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 456 | complete((struct completion *)(evtp->evt_arg2)); |
| 457 | break; |
| 458 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 459 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 460 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 461 | lpfc_sli_brdreset(phba); |
| 462 | lpfc_hba_down_post(phba); |
| 463 | *(int *)(evtp->evt_arg1) = |
| 464 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 465 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 466 | complete((struct completion *)(evtp->evt_arg2)); |
| 467 | break; |
| 468 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 469 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 470 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 471 | = (phba->pport->stopped) |
| 472 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 473 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | complete((struct completion *)(evtp->evt_arg2)); |
| 475 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 476 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 477 | lpfc_send_fastpath_evt(phba, evtp); |
| 478 | free_evt = 0; |
| 479 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 480 | case LPFC_EVT_RESET_HBA: |
| 481 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 482 | lpfc_reset_hba(phba); |
| 483 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 484 | } |
| 485 | if (free_evt) |
| 486 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 487 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 489 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | |
| 491 | } |
| 492 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 493 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 494 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 495 | { |
| 496 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 497 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 498 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 499 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 500 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 502 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | ha_copy = phba->work_ha; |
| 504 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 505 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 507 | /* First, try to post the next mailbox command to SLI4 device */ |
| 508 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 509 | lpfc_sli4_post_async_mbox(phba); |
| 510 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 511 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 512 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | lpfc_handle_eratt(phba); |
| 514 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 515 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | lpfc_sli_handle_mb_event(phba); |
| 517 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 518 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 520 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 521 | /* Process SLI4 events */ |
| 522 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
| 523 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 524 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 525 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 526 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 527 | if (phba->hba_flag & ASYNC_EVENT) |
| 528 | lpfc_sli4_async_event_proc(phba); |
| 529 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 530 | spin_lock_irq(&phba->hbalock); |
| 531 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 532 | spin_unlock_irq(&phba->hbalock); |
| 533 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 534 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 535 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 536 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 537 | } |
| 538 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 539 | vports = lpfc_create_vport_work_array(phba); |
| 540 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 541 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 542 | /* |
| 543 | * We could have no vports in array if unloading, so if |
| 544 | * this happens then just use the pport |
| 545 | */ |
| 546 | if (vports[i] == NULL && i == 0) |
| 547 | vport = phba->pport; |
| 548 | else |
| 549 | vport = vports[i]; |
| 550 | if (vport == NULL) |
| 551 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 552 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 553 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 554 | vport->work_port_events &= ~work_port_events; |
| 555 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 556 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 557 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 558 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 559 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 560 | if (work_port_events & WORKER_HB_TMO) |
| 561 | lpfc_hb_timeout_handler(phba); |
| 562 | if (work_port_events & WORKER_MBOX_TMO) |
| 563 | lpfc_mbox_timeout_handler(phba); |
| 564 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 565 | lpfc_unblock_fabric_iocbs(phba); |
| 566 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 567 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 568 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 569 | lpfc_ramp_down_queue_handler(phba); |
| 570 | if (work_port_events & WORKER_RAMP_UP_QUEUE) |
| 571 | lpfc_ramp_up_queue_handler(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 572 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 573 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 575 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 576 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 577 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 578 | if ((status & HA_RXMASK) || |
| 579 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 580 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 581 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 582 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 583 | /* Set the lpfc data pending flag */ |
| 584 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 585 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 586 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 587 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 588 | (status & |
| 589 | HA_RXMASK)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 590 | } |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 591 | if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 592 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 593 | /* |
| 594 | * Turn on Ring interrupts |
| 595 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 596 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 597 | spin_lock_irq(&phba->hbalock); |
| 598 | control = readl(phba->HCregaddr); |
| 599 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 600 | lpfc_debugfs_slow_ring_trc(phba, |
| 601 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 602 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 603 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 604 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 605 | writel(control, phba->HCregaddr); |
| 606 | readl(phba->HCregaddr); /* flush */ |
| 607 | } else { |
| 608 | lpfc_debugfs_slow_ring_trc(phba, |
| 609 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 610 | control, ha_copy, 0); |
| 611 | } |
| 612 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | } |
| 614 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 615 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | } |
| 617 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 618 | int |
| 619 | lpfc_do_work(void *p) |
| 620 | { |
| 621 | struct lpfc_hba *phba = p; |
| 622 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | |
| 624 | set_user_nice(current, -20); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 625 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 627 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 628 | /* wait and check worker queue activities */ |
| 629 | rc = wait_event_interruptible(phba->work_waitq, |
| 630 | (test_and_clear_bit(LPFC_DATA_READY, |
| 631 | &phba->data_flags) |
| 632 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 633 | /* Signal wakeup shall terminate the worker thread */ |
| 634 | if (rc) { |
| 635 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 636 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 637 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 638 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 640 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 643 | phba->worker_thread = NULL; |
| 644 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 645 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * This is only called to handle FC worker events. Since this a rare |
| 651 | * occurance, we allocate a struct lpfc_work_evt structure here instead of |
| 652 | * embedding it in the IOCB. |
| 653 | */ |
| 654 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | uint32_t evt) |
| 657 | { |
| 658 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 659 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | |
| 661 | /* |
| 662 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 663 | * be queued to worker thread for processing |
| 664 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 665 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | if (!evtp) |
| 667 | return 0; |
| 668 | |
| 669 | evtp->evt_arg1 = arg1; |
| 670 | evtp->evt_arg2 = arg2; |
| 671 | evtp->evt = evt; |
| 672 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 673 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 674 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 675 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 677 | lpfc_worker_wake_up(phba); |
| 678 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 679 | return 1; |
| 680 | } |
| 681 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 682 | void |
| 683 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 684 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 685 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 686 | struct lpfc_hba *phba = vport->phba; |
| 687 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 688 | int rc; |
| 689 | |
| 690 | 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] | 691 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 692 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 693 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 694 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 695 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 696 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 697 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 698 | lpfc_unreg_rpi(vport, ndlp); |
| 699 | |
| 700 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 701 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 702 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 703 | continue; |
| 704 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 705 | remove |
| 706 | ? NLP_EVT_DEVICE_RM |
| 707 | : NLP_EVT_DEVICE_RECOVERY); |
| 708 | } |
| 709 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
| 710 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 711 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 712 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 713 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 717 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 718 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 719 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 720 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 721 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 722 | /* Cleanup any outstanding received buffers */ |
| 723 | lpfc_cleanup_rcv_buffers(vport); |
| 724 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | /* Cleanup any outstanding RSCN activity */ |
| 726 | lpfc_els_flush_rscn(vport); |
| 727 | |
| 728 | /* Cleanup any outstanding ELS commands */ |
| 729 | lpfc_els_flush_cmd(vport); |
| 730 | |
| 731 | lpfc_cleanup_rpis(vport, 0); |
| 732 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 733 | /* Turn off discovery timer if its running */ |
| 734 | lpfc_can_disctmo(vport); |
| 735 | } |
| 736 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 737 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 738 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 739 | { |
| 740 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 741 | |
| 742 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 743 | |
| 744 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 745 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 746 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 747 | |
| 748 | lpfc_port_link_failure(vport); |
| 749 | |
| 750 | } |
| 751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 753 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 754 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 755 | struct lpfc_vport *vport = phba->pport; |
| 756 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 757 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 758 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 759 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 761 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 762 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 763 | |
| 764 | /* Block all SCSI stack I/Os */ |
| 765 | lpfc_scsi_dev_block(phba); |
| 766 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 767 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 768 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 769 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 770 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 771 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 772 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 773 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 774 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 775 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 776 | vports = lpfc_create_vport_work_array(phba); |
| 777 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 778 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 779 | /* Issue a LINK DOWN event to all nodes */ |
| 780 | lpfc_linkdown_port(vports[i]); |
| 781 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 782 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 784 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 785 | if (mb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 786 | lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 787 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 788 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 789 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 791 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 797 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 798 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 799 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 801 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 802 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 803 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 806 | } |
| 807 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 808 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 810 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 811 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 812 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 813 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | } |
| 815 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 816 | static void |
| 817 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 818 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | struct lpfc_nodelist *ndlp; |
| 820 | |
| 821 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 822 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 823 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 825 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 826 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 827 | /* On Linkup its safe to clean up the ndlp |
| 828 | * from Fabric connections. |
| 829 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 830 | if (ndlp->nlp_DID != Fabric_DID) |
| 831 | lpfc_unreg_rpi(vport, ndlp); |
| 832 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 833 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 834 | /* Fail outstanding IO now since device is |
| 835 | * marked for PLOGI. |
| 836 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | lpfc_unreg_rpi(vport, ndlp); |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | static void |
| 843 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 844 | { |
| 845 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 846 | struct lpfc_hba *phba = vport->phba; |
| 847 | |
| 848 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 849 | return; |
| 850 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 851 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 852 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 853 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 854 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 855 | /* If NPIV is not enabled, only bring the physical port up */ |
| 856 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 857 | (vport != phba->pport)) |
| 858 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 860 | 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] | 861 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 862 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 863 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 864 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 865 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 866 | vport->fc_ns_retry = 0; |
| 867 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 868 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 869 | if (vport->fc_flag & FC_LBIT) |
| 870 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static int |
| 875 | lpfc_linkup(struct lpfc_hba *phba) |
| 876 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 877 | struct lpfc_vport **vports; |
| 878 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 879 | |
| 880 | phba->link_state = LPFC_LINK_UP; |
| 881 | |
| 882 | /* Unblock fabric iocbs if they are blocked */ |
| 883 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 884 | del_timer_sync(&phba->fabric_block_timer); |
| 885 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 886 | vports = lpfc_create_vport_work_array(phba); |
| 887 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 888 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 889 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 890 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 891 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 892 | (phba->sli_rev < LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 893 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | /* |
| 899 | * This routine handles processing a CLEAR_LA mailbox |
| 900 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 901 | * as the completion routine when the command is |
| 902 | * handed off to the SLI layer. |
| 903 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 904 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 905 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 907 | struct lpfc_vport *vport = pmb->vport; |
| 908 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 909 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 910 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | uint32_t control; |
| 912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 914 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 916 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 917 | |
| 918 | /* Check for error */ |
| 919 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 920 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 921 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 922 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 923 | "state x%x\n", |
| 924 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 925 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 926 | goto out; |
| 927 | } |
| 928 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 929 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 930 | phba->link_state = LPFC_HBA_READY; |
| 931 | |
| 932 | spin_lock_irq(&phba->hbalock); |
| 933 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 934 | control = readl(phba->HCregaddr); |
| 935 | control |= HC_LAINT_ENA; |
| 936 | writel(control, phba->HCregaddr); |
| 937 | readl(phba->HCregaddr); /* flush */ |
| 938 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 939 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 940 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | out: |
| 943 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 944 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 945 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 948 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 949 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 952 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | |
| 954 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 955 | |
| 956 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 958 | control = readl(phba->HCregaddr); |
| 959 | control |= HC_LAINT_ENA; |
| 960 | writel(control, phba->HCregaddr); |
| 961 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 962 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | |
| 964 | return; |
| 965 | } |
| 966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 967 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 969 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 971 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 973 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 976 | mempool_free(pmb, phba->mbox_mem_pool); |
| 977 | |
| 978 | if (phba->fc_topology == TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 979 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 980 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 981 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 983 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 984 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 985 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 986 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 989 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 990 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 991 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 992 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 993 | lpfc_initial_flogi(vport); |
| 994 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 995 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | |
| 997 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 998 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 999 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 1000 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1001 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1002 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1003 | |
| 1004 | lpfc_linkdown(phba); |
| 1005 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1006 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1007 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1008 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1010 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1015 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1016 | { |
| 1017 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1018 | |
| 1019 | if (mboxq->u.mb.mbxStatus) { |
| 1020 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1021 | "2017 REG_FCFI mbxStatus error x%x " |
| 1022 | "HBA state x%x\n", |
| 1023 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 1024 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1029 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1030 | /* Set the FCFI registered flag */ |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1031 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1032 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1033 | spin_unlock_irq(&phba->hbalock); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1034 | /* If there is a pending FCoE event, restart FCF table scan. */ |
| 1035 | if (lpfc_check_pending_fcoe_event(phba, 1)) { |
| 1036 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1037 | return; |
| 1038 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1039 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1040 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1041 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1042 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1043 | if (vport->port_state != LPFC_FLOGI) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1044 | lpfc_initial_flogi(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1045 | |
| 1046 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1052 | * @fab_name: pointer to fabric name. |
| 1053 | * @new_fcf_record: pointer to fcf record. |
| 1054 | * |
| 1055 | * This routine compare the fcf record's fabric name with provided |
| 1056 | * fabric name. If the fabric name are identical this function |
| 1057 | * returns 1 else return 0. |
| 1058 | **/ |
| 1059 | static uint32_t |
| 1060 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1061 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1062 | 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] | 1063 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1064 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) |
| 1065 | return 0; |
| 1066 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) |
| 1067 | return 0; |
| 1068 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) |
| 1069 | return 0; |
| 1070 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) |
| 1071 | return 0; |
| 1072 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) |
| 1073 | return 0; |
| 1074 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
| 1075 | return 0; |
| 1076 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) |
| 1077 | return 0; |
| 1078 | return 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1082 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1083 | * @fab_name: pointer to fabric name. |
| 1084 | * @new_fcf_record: pointer to fcf record. |
| 1085 | * |
| 1086 | * This routine compare the fcf record's switch name with provided |
| 1087 | * switch name. If the switch name are identical this function |
| 1088 | * returns 1 else return 0. |
| 1089 | **/ |
| 1090 | static uint32_t |
| 1091 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1092 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1093 | 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] | 1094 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1095 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) |
| 1096 | return 0; |
| 1097 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) |
| 1098 | return 0; |
| 1099 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
| 1100 | return 0; |
| 1101 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) |
| 1102 | return 0; |
| 1103 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) |
| 1104 | return 0; |
| 1105 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) |
| 1106 | return 0; |
| 1107 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) |
| 1108 | return 0; |
| 1109 | return 1; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1113 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1114 | * @mac_addr: pointer to mac address. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1115 | * @new_fcf_record: pointer to fcf record. |
| 1116 | * |
| 1117 | * This routine compare the fcf record's mac address with HBA's |
| 1118 | * FCF mac address. If the mac addresses are identical this function |
| 1119 | * returns 1 else return 0. |
| 1120 | **/ |
| 1121 | static uint32_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1122 | 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] | 1123 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1124 | 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] | 1125 | return 0; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1126 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) |
| 1127 | return 0; |
| 1128 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) |
| 1129 | return 0; |
| 1130 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) |
| 1131 | return 0; |
| 1132 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) |
| 1133 | return 0; |
| 1134 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) |
| 1135 | return 0; |
| 1136 | return 1; |
| 1137 | } |
| 1138 | |
| 1139 | static bool |
| 1140 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) |
| 1141 | { |
| 1142 | return (curr_vlan_id == new_vlan_id); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1147 | * @fcf: pointer to driver fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1148 | * @new_fcf_record: pointer to fcf record. |
| 1149 | * |
| 1150 | * This routine copies the FCF information from the FCF |
| 1151 | * record to lpfc_hba data structure. |
| 1152 | **/ |
| 1153 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1154 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
| 1155 | struct fcf_record *new_fcf_record) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1156 | { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1157 | /* Fabric name */ |
| 1158 | fcf_rec->fabric_name[0] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1159 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1160 | fcf_rec->fabric_name[1] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1161 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1162 | fcf_rec->fabric_name[2] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1163 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1164 | fcf_rec->fabric_name[3] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1165 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1166 | fcf_rec->fabric_name[4] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1167 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1168 | fcf_rec->fabric_name[5] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1169 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1170 | fcf_rec->fabric_name[6] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1171 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1172 | fcf_rec->fabric_name[7] = |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1173 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1174 | /* Mac address */ |
| 1175 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1176 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1177 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1178 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1179 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1180 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1181 | /* FCF record index */ |
| 1182 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1183 | /* FCF record priority */ |
| 1184 | fcf_rec->priority = new_fcf_record->fip_priority; |
| 1185 | /* Switch name */ |
| 1186 | fcf_rec->switch_name[0] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1187 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1188 | fcf_rec->switch_name[1] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1189 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1190 | fcf_rec->switch_name[2] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1191 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1192 | fcf_rec->switch_name[3] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1193 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1194 | fcf_rec->switch_name[4] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1195 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1196 | fcf_rec->switch_name[5] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1197 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1198 | fcf_rec->switch_name[6] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1199 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1200 | fcf_rec->switch_name[7] = |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1201 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1205 | * lpfc_update_fcf_record - Update driver fcf record |
| 1206 | * @phba: pointer to lpfc hba data structure. |
| 1207 | * @fcf_rec: pointer to driver fcf record. |
| 1208 | * @new_fcf_record: pointer to hba fcf record. |
| 1209 | * @addr_mode: address mode to be set to the driver fcf record. |
| 1210 | * @vlan_id: vlan tag to be set to the driver fcf record. |
| 1211 | * @flag: flag bits to be set to the driver fcf record. |
| 1212 | * |
| 1213 | * This routine updates the driver FCF record from the new HBA FCF record |
| 1214 | * together with the address mode, vlan_id, and other informations. This |
| 1215 | * routine is called with the host lock held. |
| 1216 | **/ |
| 1217 | static void |
| 1218 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, |
| 1219 | struct fcf_record *new_fcf_record, uint32_t addr_mode, |
| 1220 | uint16_t vlan_id, uint32_t flag) |
| 1221 | { |
| 1222 | /* Copy the fields from the HBA's FCF record */ |
| 1223 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); |
| 1224 | /* Update other fields of driver FCF record */ |
| 1225 | fcf_rec->addr_mode = addr_mode; |
| 1226 | fcf_rec->vlan_id = vlan_id; |
| 1227 | fcf_rec->flag |= (flag | RECORD_VALID); |
| 1228 | } |
| 1229 | |
| 1230 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1231 | * lpfc_register_fcf - Register the FCF with hba. |
| 1232 | * @phba: pointer to lpfc hba data structure. |
| 1233 | * |
| 1234 | * This routine issues a register fcfi mailbox command to register |
| 1235 | * the fcf with HBA. |
| 1236 | **/ |
| 1237 | static void |
| 1238 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1239 | { |
| 1240 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1241 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1242 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1243 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1244 | |
| 1245 | /* If the FCF is not availabe do nothing. */ |
| 1246 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1247 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1248 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | /* The FCF is already registered, start discovery */ |
| 1253 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1254 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1255 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1256 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1257 | if (phba->pport->port_state != LPFC_FLOGI) |
| 1258 | lpfc_initial_flogi(phba->pport); |
| 1259 | return; |
| 1260 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1261 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1262 | |
| 1263 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, |
| 1264 | GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1265 | if (!fcf_mbxq) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1266 | spin_lock_irq(&phba->hbalock); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1267 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1268 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1269 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1270 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1271 | |
| 1272 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1273 | fcf_mbxq->vport = phba->pport; |
| 1274 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1275 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1276 | if (rc == MBX_NOT_FINISHED) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1277 | spin_lock_irq(&phba->hbalock); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1278 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1279 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1280 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1281 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1282 | |
| 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1288 | * @phba: pointer to lpfc hba data structure. |
| 1289 | * @new_fcf_record: pointer to fcf record. |
| 1290 | * @boot_flag: Indicates if this record used by boot bios. |
| 1291 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1292 | * @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] | 1293 | * |
| 1294 | * This routine compare the fcf record with connect list obtained from the |
| 1295 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1296 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1297 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1298 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1299 | * used for this FCF when the function returns. |
| 1300 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1301 | * 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] | 1302 | * 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] | 1303 | **/ |
| 1304 | static int |
| 1305 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1306 | struct fcf_record *new_fcf_record, |
| 1307 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1308 | uint16_t *vlan_id) |
| 1309 | { |
| 1310 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1311 | int i, j, fcf_vlan_id = 0; |
| 1312 | |
| 1313 | /* Find the lowest VLAN id in the FCF record */ |
| 1314 | for (i = 0; i < 512; i++) { |
| 1315 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1316 | fcf_vlan_id = i * 8; |
| 1317 | j = 0; |
| 1318 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1319 | j++; |
| 1320 | fcf_vlan_id++; |
| 1321 | } |
| 1322 | break; |
| 1323 | } |
| 1324 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1325 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1326 | /* If FCF not available return 0 */ |
| 1327 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
| 1328 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record)) |
| 1329 | return 0; |
| 1330 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1331 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1332 | *boot_flag = 0; |
| 1333 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1334 | new_fcf_record); |
| 1335 | if (phba->valid_vlan) |
| 1336 | *vlan_id = phba->vlan_id; |
| 1337 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1338 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1339 | return 1; |
| 1340 | } |
| 1341 | |
| 1342 | /* |
| 1343 | * If there are no FCF connection table entry, driver connect to all |
| 1344 | * FCFs. |
| 1345 | */ |
| 1346 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1347 | *boot_flag = 0; |
| 1348 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1349 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1350 | |
| 1351 | /* |
| 1352 | * When there are no FCF connect entries, use driver's default |
| 1353 | * addressing mode - FPMA. |
| 1354 | */ |
| 1355 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1356 | *addr_mode = LPFC_FCF_FPMA; |
| 1357 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1358 | /* If FCF record report a vlan id use that vlan id */ |
| 1359 | if (fcf_vlan_id) |
| 1360 | *vlan_id = fcf_vlan_id; |
| 1361 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1362 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1363 | return 1; |
| 1364 | } |
| 1365 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1366 | list_for_each_entry(conn_entry, |
| 1367 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1368 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1369 | continue; |
| 1370 | |
| 1371 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1372 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1373 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1374 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1375 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1376 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1377 | new_fcf_record)) |
| 1378 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1379 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1380 | /* |
| 1381 | * If the vlan bit map does not have the bit set for the |
| 1382 | * vlan id to be used, then it is not a match. |
| 1383 | */ |
| 1384 | if (!(new_fcf_record->vlan_bitmap |
| 1385 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1386 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1387 | continue; |
| 1388 | } |
| 1389 | |
| 1390 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1391 | * If connection record does not support any addressing mode, |
| 1392 | * skip the FCF record. |
| 1393 | */ |
| 1394 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1395 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1396 | continue; |
| 1397 | |
| 1398 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1399 | * Check if the connection record specifies a required |
| 1400 | * addressing mode. |
| 1401 | */ |
| 1402 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1403 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1404 | |
| 1405 | /* |
| 1406 | * If SPMA required but FCF not support this continue. |
| 1407 | */ |
| 1408 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1409 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1410 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1411 | continue; |
| 1412 | |
| 1413 | /* |
| 1414 | * If FPMA required but FCF not support this continue. |
| 1415 | */ |
| 1416 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1417 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1418 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1419 | continue; |
| 1420 | } |
| 1421 | |
| 1422 | /* |
| 1423 | * This fcf record matches filtering criteria. |
| 1424 | */ |
| 1425 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1426 | *boot_flag = 1; |
| 1427 | else |
| 1428 | *boot_flag = 0; |
| 1429 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1430 | /* |
| 1431 | * If user did not specify any addressing mode, or if the |
| 1432 | * prefered addressing mode specified by user is not supported |
| 1433 | * by FCF, allow fabric to pick the addressing mode. |
| 1434 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1435 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1436 | new_fcf_record); |
| 1437 | /* |
| 1438 | * If the user specified a required address mode, assign that |
| 1439 | * address mode |
| 1440 | */ |
| 1441 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1442 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1443 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1444 | FCFCNCT_AM_SPMA) ? |
| 1445 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1446 | /* |
| 1447 | * If the user specified a prefered address mode, use the |
| 1448 | * addr mode only if FCF support the addr_mode. |
| 1449 | */ |
| 1450 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1451 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1452 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1453 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1454 | *addr_mode = LPFC_FCF_SPMA; |
| 1455 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1456 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1457 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1458 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1459 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1460 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1461 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1462 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1463 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1464 | /* |
| 1465 | * If no vlan id is specified in connect list, use the vlan id |
| 1466 | * in the FCF record |
| 1467 | */ |
| 1468 | else if (fcf_vlan_id) |
| 1469 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1470 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1471 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1472 | |
| 1473 | return 1; |
| 1474 | } |
| 1475 | |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1480 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1481 | * @phba: pointer to lpfc hba data structure. |
| 1482 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1483 | * |
| 1484 | * This function check if there is any fcoe event pending while driver |
| 1485 | * scan FCF entries. If there is any pending event, it will restart the |
| 1486 | * FCF saning and return 1 else return 0. |
| 1487 | */ |
| 1488 | int |
| 1489 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1490 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1491 | /* |
| 1492 | * If the Link is up and no FCoE events while in the |
| 1493 | * FCF discovery, no need to restart FCF discovery. |
| 1494 | */ |
| 1495 | if ((phba->link_state >= LPFC_LINK_UP) && |
| 1496 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
| 1497 | return 0; |
| 1498 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1499 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1500 | "2768 Pending link or FCF event during current " |
| 1501 | "handling of the previous event: link_state:x%x, " |
| 1502 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1503 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1504 | phba->fcoe_eventtag); |
| 1505 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1506 | spin_lock_irq(&phba->hbalock); |
| 1507 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1508 | spin_unlock_irq(&phba->hbalock); |
| 1509 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1510 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1511 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1512 | "2780 Restart FCF table scan due to " |
| 1513 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1514 | "evt_tag_current:x%x\n", |
| 1515 | phba->fcoe_eventtag_at_fcf_scan, |
| 1516 | phba->fcoe_eventtag); |
| 1517 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1518 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1519 | /* |
| 1520 | * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS |
| 1521 | * flag |
| 1522 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1523 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1524 | "2833 Stop FCF discovery process due to link " |
| 1525 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1526 | spin_lock_irq(&phba->hbalock); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1527 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1528 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1529 | spin_unlock_irq(&phba->hbalock); |
| 1530 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1531 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1532 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1533 | if (unreg_fcf) { |
| 1534 | spin_lock_irq(&phba->hbalock); |
| 1535 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1536 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1537 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1538 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1539 | return 1; |
| 1540 | } |
| 1541 | |
| 1542 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1543 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1544 | * @phba: pointer to lpfc hba data structure. |
| 1545 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1546 | * |
| 1547 | * This function makes an running random selection decision on FCF record to |
| 1548 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1549 | * probability. To perform integer manunipulation of random numbers with |
| 1550 | * size unit32_t, the lower 16 bits of the 32-bit random number returned |
| 1551 | * from random32() are taken as the random random number generated. |
| 1552 | * |
| 1553 | * Returns true when outcome is for the newly read FCF record should be |
| 1554 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1555 | * chosen FCF record. |
| 1556 | **/ |
| 1557 | static bool |
| 1558 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1559 | { |
| 1560 | uint32_t rand_num; |
| 1561 | |
| 1562 | /* Get 16-bit uniform random number */ |
| 1563 | rand_num = (0xFFFF & random32()); |
| 1564 | |
| 1565 | /* Decision with probability 1/fcf_cnt */ |
| 1566 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1567 | return true; |
| 1568 | else |
| 1569 | return false; |
| 1570 | } |
| 1571 | |
| 1572 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 1573 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1574 | * @phba: pointer to lpfc hba data structure. |
| 1575 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1576 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1577 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1578 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1579 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1580 | * SGE parsing, and endianness swapping. |
| 1581 | * |
| 1582 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1583 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1584 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1585 | static struct fcf_record * |
| 1586 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1587 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1588 | { |
| 1589 | void *virt_addr; |
| 1590 | dma_addr_t phys_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1591 | struct lpfc_mbx_sge sge; |
| 1592 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1593 | uint32_t shdr_status, shdr_add_status; |
| 1594 | union lpfc_sli4_cfg_shdr *shdr; |
| 1595 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1596 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1597 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1598 | * routine only uses a single SGE. |
| 1599 | */ |
| 1600 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1601 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1602 | if (unlikely(!mboxq->sge_array)) { |
| 1603 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1604 | "2524 Failed to get the non-embedded SGE " |
| 1605 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1606 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1607 | } |
| 1608 | virt_addr = mboxq->sge_array->addr[0]; |
| 1609 | |
| 1610 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
| 1611 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1612 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1613 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1614 | if (shdr_status == STATUS_FCF_TABLE_EMPTY) |
| 1615 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1616 | "2726 READ_FCF_RECORD Indicates empty " |
| 1617 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1618 | else |
| 1619 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1620 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1621 | "with status x%x add_status x%x, " |
| 1622 | "mbx\n", shdr_status, shdr_add_status); |
| 1623 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1624 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1625 | |
| 1626 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1627 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1628 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1629 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1630 | *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] | 1631 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1632 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1633 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1634 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1635 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1636 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1637 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1638 | return new_fcf_record; |
| 1639 | } |
| 1640 | |
| 1641 | /** |
| 1642 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1643 | * @phba: pointer to lpfc hba data structure. |
| 1644 | * @fcf_record: pointer to the fcf record. |
| 1645 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1646 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1647 | * |
| 1648 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1649 | * enabled. |
| 1650 | **/ |
| 1651 | static void |
| 1652 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1653 | struct fcf_record *fcf_record, |
| 1654 | uint16_t vlan_id, |
| 1655 | uint16_t next_fcf_index) |
| 1656 | { |
| 1657 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1658 | "2764 READ_FCF_RECORD:\n" |
| 1659 | "\tFCF_Index : x%x\n" |
| 1660 | "\tFCF_Avail : x%x\n" |
| 1661 | "\tFCF_Valid : x%x\n" |
| 1662 | "\tFIP_Priority : x%x\n" |
| 1663 | "\tMAC_Provider : x%x\n" |
| 1664 | "\tLowest VLANID : x%x\n" |
| 1665 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1666 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1667 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1668 | "\tNext_FCF_Index: x%x\n", |
| 1669 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1670 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1671 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
| 1672 | fcf_record->fip_priority, |
| 1673 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1674 | vlan_id, |
| 1675 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1676 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1677 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1678 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1679 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1680 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1681 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1682 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1683 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1684 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1685 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1686 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1687 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1688 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1689 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1690 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1691 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1692 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1693 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1694 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1695 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1696 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1697 | next_fcf_index); |
| 1698 | } |
| 1699 | |
| 1700 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1701 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1702 | * @phba: pointer to lpfc hba data structure. |
| 1703 | * @fcf_rec: pointer to an existing FCF record. |
| 1704 | * @new_fcf_record: pointer to a new FCF record. |
| 1705 | * @new_vlan_id: vlan id from the new FCF record. |
| 1706 | * |
| 1707 | * This function performs matching test of a new FCF record against an existing |
| 1708 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1709 | * will not be used as part of the FCF record matching criteria. |
| 1710 | * |
| 1711 | * Returns true if all the fields matching, otherwise returns false. |
| 1712 | */ |
| 1713 | static bool |
| 1714 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1715 | struct lpfc_fcf_rec *fcf_rec, |
| 1716 | struct fcf_record *new_fcf_record, |
| 1717 | uint16_t new_vlan_id) |
| 1718 | { |
| 1719 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1720 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1721 | return false; |
| 1722 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1723 | return false; |
| 1724 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1725 | return false; |
| 1726 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1727 | return false; |
| 1728 | return true; |
| 1729 | } |
| 1730 | |
| 1731 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1732 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 1733 | * @phba: pointer to lpfc hba data structure. |
| 1734 | * @mboxq: pointer to mailbox object. |
| 1735 | * |
| 1736 | * This function iterates through all the fcf records available in |
| 1737 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 1738 | * the FCF for discovery it registers the FCF record and kicks start |
| 1739 | * discovery. |
| 1740 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 1741 | * use an FCF record which matches fabric name and mac address of the |
| 1742 | * currently used FCF record. |
| 1743 | * If the driver supports only one FCF, it will try to use the FCF record |
| 1744 | * used by BOOT_BIOS. |
| 1745 | */ |
| 1746 | void |
| 1747 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1748 | { |
| 1749 | struct fcf_record *new_fcf_record; |
| 1750 | uint32_t boot_flag, addr_mode; |
| 1751 | uint16_t fcf_index, next_fcf_index; |
| 1752 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 1753 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1754 | uint32_t seed; |
| 1755 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1756 | int rc; |
| 1757 | |
| 1758 | /* If there is pending FCoE event restart FCF table scan */ |
| 1759 | if (lpfc_check_pending_fcoe_event(phba, 0)) { |
| 1760 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1761 | return; |
| 1762 | } |
| 1763 | |
| 1764 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 1765 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 1766 | &next_fcf_index); |
| 1767 | if (!new_fcf_record) { |
| 1768 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1769 | "2765 Mailbox command READ_FCF_RECORD " |
| 1770 | "failed to retrieve a FCF record.\n"); |
| 1771 | /* Let next new FCF event trigger fast failover */ |
| 1772 | spin_lock_irq(&phba->hbalock); |
| 1773 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
| 1774 | spin_unlock_irq(&phba->hbalock); |
| 1775 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1776 | return; |
| 1777 | } |
| 1778 | |
| 1779 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1780 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 1781 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1782 | |
| 1783 | /* Log the FCF record information if turned on */ |
| 1784 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 1785 | next_fcf_index); |
| 1786 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1787 | /* |
| 1788 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1789 | * read the next entry; otherwise, this is an eligible FCF |
| 1790 | * record for round robin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1791 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1792 | if (!rc) { |
| 1793 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1794 | "2781 FCF record (x%x) failed FCF " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1795 | "connection list check, fcf_avail:x%x, " |
| 1796 | "fcf_valid:x%x\n", |
| 1797 | bf_get(lpfc_fcf_record_fcf_index, |
| 1798 | new_fcf_record), |
| 1799 | bf_get(lpfc_fcf_record_fcf_avail, |
| 1800 | new_fcf_record), |
| 1801 | bf_get(lpfc_fcf_record_fcf_valid, |
| 1802 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1803 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 1804 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 1805 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
| 1806 | /* |
| 1807 | * In case the current in-use FCF record becomes |
| 1808 | * invalid/unavailable during FCF discovery that |
| 1809 | * was not triggered by fast FCF failover process, |
| 1810 | * treat it as fast FCF failover. |
| 1811 | */ |
| 1812 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 1813 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 1814 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1815 | "2835 Invalid in-use FCF " |
| 1816 | "record (x%x) reported, " |
| 1817 | "entering fast FCF failover " |
| 1818 | "mode scanning.\n", |
| 1819 | phba->fcf.current_rec.fcf_indx); |
| 1820 | spin_lock_irq(&phba->hbalock); |
| 1821 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 1822 | spin_unlock_irq(&phba->hbalock); |
| 1823 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1824 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 1825 | LPFC_FCOE_FCF_GET_FIRST); |
| 1826 | return; |
| 1827 | } |
| 1828 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1829 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1830 | } else { |
| 1831 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1832 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 1833 | if (rc) |
| 1834 | goto read_next_fcf; |
| 1835 | } |
| 1836 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1837 | /* |
| 1838 | * 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] | 1839 | * FCF record for the discovery. The condition that a rescan |
| 1840 | * matches the in-use FCF record: fabric name, switch name, mac |
| 1841 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1842 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1843 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1844 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1845 | if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 1846 | new_fcf_record, vlan_id)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1847 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1848 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 1849 | /* Stop FCF redisc wait timer if pending */ |
| 1850 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
| 1851 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1852 | /* If in fast failover, mark it's completed */ |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1853 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1854 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1855 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1856 | "2836 The new FCF record (x%x) " |
| 1857 | "matches the in-use FCF record " |
| 1858 | "(x%x)\n", |
| 1859 | phba->fcf.current_rec.fcf_indx, |
| 1860 | bf_get(lpfc_fcf_record_fcf_index, |
| 1861 | new_fcf_record)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1862 | goto out; |
| 1863 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1864 | /* |
| 1865 | * Read next FCF record from HBA searching for the matching |
| 1866 | * with in-use record only if not during the fast failover |
| 1867 | * period. In case of fast failover period, it shall try to |
| 1868 | * determine whether the FCF record just read should be the |
| 1869 | * next candidate. |
| 1870 | */ |
| 1871 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1872 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1873 | goto read_next_fcf; |
| 1874 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1875 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1876 | /* |
| 1877 | * Update on failover FCF record only if it's in FCF fast-failover |
| 1878 | * period; otherwise, update on current FCF record. |
| 1879 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1880 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1881 | fcf_rec = &phba->fcf.failover_rec; |
| 1882 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1883 | fcf_rec = &phba->fcf.current_rec; |
| 1884 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1885 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 1886 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1887 | * If the driver FCF record does not have boot flag |
| 1888 | * set and new hba fcf record has boot flag set, use |
| 1889 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1890 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1891 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 1892 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1893 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1894 | "2837 Update current FCF record " |
| 1895 | "(x%x) with new FCF record (x%x)\n", |
| 1896 | fcf_rec->fcf_indx, |
| 1897 | bf_get(lpfc_fcf_record_fcf_index, |
| 1898 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1899 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1900 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1901 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1902 | goto read_next_fcf; |
| 1903 | } |
| 1904 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1905 | * If the driver FCF record has boot flag set and the |
| 1906 | * new hba FCF record does not have boot flag, read |
| 1907 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1908 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1909 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1910 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1911 | goto read_next_fcf; |
| 1912 | } |
| 1913 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1914 | * If the new hba FCF record has lower priority value |
| 1915 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1916 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1917 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1918 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1919 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1920 | "2838 Update current FCF record " |
| 1921 | "(x%x) with new FCF record (x%x)\n", |
| 1922 | fcf_rec->fcf_indx, |
| 1923 | bf_get(lpfc_fcf_record_fcf_index, |
| 1924 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1925 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1926 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1927 | /* Reset running random FCF selection count */ |
| 1928 | phba->fcf.eligible_fcf_cnt = 1; |
| 1929 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 1930 | /* Update running random FCF selection count */ |
| 1931 | phba->fcf.eligible_fcf_cnt++; |
| 1932 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 1933 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1934 | if (select_new_fcf) { |
| 1935 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1936 | "2839 Update current FCF record " |
| 1937 | "(x%x) with new FCF record (x%x)\n", |
| 1938 | fcf_rec->fcf_indx, |
| 1939 | bf_get(lpfc_fcf_record_fcf_index, |
| 1940 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1941 | /* Choose the new FCF by random selection */ |
| 1942 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 1943 | new_fcf_record, |
| 1944 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1945 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1946 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1947 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1948 | goto read_next_fcf; |
| 1949 | } |
| 1950 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1951 | * This is the first suitable FCF record, choose this record for |
| 1952 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1953 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1954 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1955 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1956 | "2840 Update current FCF record " |
| 1957 | "with initial FCF record (x%x)\n", |
| 1958 | bf_get(lpfc_fcf_record_fcf_index, |
| 1959 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1960 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1961 | addr_mode, vlan_id, (boot_flag ? |
| 1962 | BOOT_ENABLE : 0)); |
| 1963 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1964 | /* Setup initial running random FCF selection count */ |
| 1965 | phba->fcf.eligible_fcf_cnt = 1; |
| 1966 | /* Seeding the random number generator for random selection */ |
| 1967 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
| 1968 | srandom32(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1969 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1970 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1971 | goto read_next_fcf; |
| 1972 | |
| 1973 | read_next_fcf: |
| 1974 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1975 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 1976 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 1977 | /* |
| 1978 | * Case of FCF fast failover scan |
| 1979 | */ |
| 1980 | |
| 1981 | /* |
| 1982 | * It has not found any suitable FCF record, cancel |
| 1983 | * FCF scan inprogress, and do nothing |
| 1984 | */ |
| 1985 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1986 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1987 | "2782 No suitable FCF record " |
| 1988 | "found during this round of " |
| 1989 | "post FCF rediscovery scan: " |
| 1990 | "fcf_evt_tag:x%x, fcf_index: " |
| 1991 | "x%x\n", |
| 1992 | phba->fcoe_eventtag_at_fcf_scan, |
| 1993 | bf_get(lpfc_fcf_record_fcf_index, |
| 1994 | new_fcf_record)); |
| 1995 | /* |
| 1996 | * Let next new FCF event trigger fast |
| 1997 | * failover |
| 1998 | */ |
| 1999 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2000 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2001 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | /* |
| 2005 | * It has found a suitable FCF record that is not |
| 2006 | * the same as in-use FCF record, unregister the |
| 2007 | * in-use FCF record, replace the in-use FCF record |
| 2008 | * with the new FCF record, mark FCF fast failover |
| 2009 | * completed, and then start register the new FCF |
| 2010 | * record. |
| 2011 | */ |
| 2012 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2013 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2014 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2015 | |
| 2016 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2017 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2018 | "2842 Replace the current in-use " |
| 2019 | "FCF record (x%x) with failover FCF " |
| 2020 | "record (x%x)\n", |
| 2021 | phba->fcf.current_rec.fcf_indx, |
| 2022 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2023 | memcpy(&phba->fcf.current_rec, |
| 2024 | &phba->fcf.failover_rec, |
| 2025 | sizeof(struct lpfc_fcf_rec)); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2026 | /* |
| 2027 | * Mark the fast FCF failover rediscovery completed |
| 2028 | * and the start of the first round of the roundrobin |
| 2029 | * FCF failover. |
| 2030 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2031 | spin_lock_irq(&phba->hbalock); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2032 | phba->fcf.fcf_flag &= |
| 2033 | ~(FCF_REDISC_FOV | FCF_REDISC_RRU); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2034 | spin_unlock_irq(&phba->hbalock); |
| 2035 | /* |
| 2036 | * Set up the initial registered FCF index for FLOGI |
| 2037 | * round robin FCF failover. |
| 2038 | */ |
| 2039 | phba->fcf.fcf_rr_init_indx = |
| 2040 | phba->fcf.failover_rec.fcf_indx; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2041 | /* Register to the new FCF record */ |
| 2042 | lpfc_register_fcf(phba); |
| 2043 | } else { |
| 2044 | /* |
| 2045 | * In case of transaction period to fast FCF failover, |
| 2046 | * do nothing when search to the end of the FCF table. |
| 2047 | */ |
| 2048 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2049 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2050 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2051 | |
| 2052 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
| 2053 | /* |
| 2054 | * In case the current in-use FCF record no |
| 2055 | * longer existed during FCF discovery that |
| 2056 | * was not triggered by fast FCF failover |
| 2057 | * process, treat it as fast FCF failover. |
| 2058 | */ |
| 2059 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2060 | "2841 In-use FCF record (x%x) " |
| 2061 | "not reported, entering fast " |
| 2062 | "FCF failover mode scanning.\n", |
| 2063 | phba->fcf.current_rec.fcf_indx); |
| 2064 | spin_lock_irq(&phba->hbalock); |
| 2065 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2066 | spin_unlock_irq(&phba->hbalock); |
| 2067 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2068 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2069 | LPFC_FCOE_FCF_GET_FIRST); |
| 2070 | return; |
| 2071 | } |
| 2072 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2073 | /* |
| 2074 | * Otherwise, initial scan or post linkdown rescan, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2075 | * register with the best FCF record found so far |
| 2076 | * through the FCF scanning process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2077 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2078 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2079 | /* |
| 2080 | * Mark the initial FCF discovery completed and |
| 2081 | * the start of the first round of the roundrobin |
| 2082 | * FCF failover. |
| 2083 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2084 | spin_lock_irq(&phba->hbalock); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2085 | phba->fcf.fcf_flag &= |
| 2086 | ~(FCF_INIT_DISC | FCF_REDISC_RRU); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2087 | spin_unlock_irq(&phba->hbalock); |
| 2088 | /* |
| 2089 | * Set up the initial registered FCF index for FLOGI |
| 2090 | * round robin FCF failover |
| 2091 | */ |
| 2092 | phba->fcf.fcf_rr_init_indx = |
| 2093 | phba->fcf.current_rec.fcf_indx; |
| 2094 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2095 | lpfc_register_fcf(phba); |
| 2096 | } |
| 2097 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2098 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2099 | return; |
| 2100 | |
| 2101 | out: |
| 2102 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2103 | lpfc_register_fcf(phba); |
| 2104 | |
| 2105 | return; |
| 2106 | } |
| 2107 | |
| 2108 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2109 | * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler |
| 2110 | * @phba: pointer to lpfc hba data structure. |
| 2111 | * @mboxq: pointer to mailbox object. |
| 2112 | * |
| 2113 | * This is the callback function for FLOGI failure round robin FCF failover |
| 2114 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2115 | * performing the failover. If the FCF read back is not valid/available, it |
| 2116 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2117 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2118 | * newly read FCF record to the failover FCF record, unregister currently |
| 2119 | * registered FCF record, copy the failover FCF record to the current |
| 2120 | * FCF record, and then register the current FCF record before proceeding |
| 2121 | * to trying FLOGI on the new failover FCF. |
| 2122 | */ |
| 2123 | void |
| 2124 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2125 | { |
| 2126 | struct fcf_record *new_fcf_record; |
| 2127 | uint32_t boot_flag, addr_mode; |
| 2128 | uint16_t next_fcf_index; |
| 2129 | uint16_t current_fcf_index; |
| 2130 | uint16_t vlan_id; |
| 2131 | |
| 2132 | /* If link state is not up, stop the round robin failover process */ |
| 2133 | if (phba->link_state < LPFC_LINK_UP) { |
| 2134 | spin_lock_irq(&phba->hbalock); |
| 2135 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 2136 | spin_unlock_irq(&phba->hbalock); |
| 2137 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2138 | return; |
| 2139 | } |
| 2140 | |
| 2141 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2142 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2143 | &next_fcf_index); |
| 2144 | if (!new_fcf_record) { |
| 2145 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2146 | "2766 Mailbox command READ_FCF_RECORD " |
| 2147 | "failed to retrieve a FCF record.\n"); |
| 2148 | goto out; |
| 2149 | } |
| 2150 | |
| 2151 | /* Get the needed parameters from FCF record */ |
| 2152 | lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2153 | &addr_mode, &vlan_id); |
| 2154 | |
| 2155 | /* Log the FCF record information if turned on */ |
| 2156 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2157 | next_fcf_index); |
| 2158 | |
| 2159 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2160 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2161 | "2834 Update the current FCF record (x%x) " |
| 2162 | "with the next FCF record (x%x)\n", |
| 2163 | phba->fcf.failover_rec.fcf_indx, |
| 2164 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2165 | spin_lock_irq(&phba->hbalock); |
| 2166 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2167 | new_fcf_record, addr_mode, vlan_id, |
| 2168 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2169 | spin_unlock_irq(&phba->hbalock); |
| 2170 | |
| 2171 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2172 | |
| 2173 | /* Unregister the current in-use FCF record */ |
| 2174 | lpfc_unregister_fcf(phba); |
| 2175 | |
| 2176 | /* Replace in-use record with the new record */ |
| 2177 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2178 | sizeof(struct lpfc_fcf_rec)); |
| 2179 | |
| 2180 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2181 | "2783 FLOGI round robin FCF failover from FCF " |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2182 | "(x%x) to FCF (x%x).\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2183 | current_fcf_index, |
| 2184 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record)); |
| 2185 | |
| 2186 | out: |
| 2187 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2188 | lpfc_register_fcf(phba); |
| 2189 | } |
| 2190 | |
| 2191 | /** |
| 2192 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2193 | * @phba: pointer to lpfc hba data structure. |
| 2194 | * @mboxq: pointer to mailbox object. |
| 2195 | * |
| 2196 | * This is the callback function of read FCF record mailbox command for |
| 2197 | * updating the eligible FCF bmask for FLOGI failure round robin FCF |
| 2198 | * failover when a new FCF event happened. If the FCF read back is |
| 2199 | * valid/available and it passes the connection list check, it updates |
| 2200 | * the bmask for the eligible FCF record for round robin failover. |
| 2201 | */ |
| 2202 | void |
| 2203 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2204 | { |
| 2205 | struct fcf_record *new_fcf_record; |
| 2206 | uint32_t boot_flag, addr_mode; |
| 2207 | uint16_t fcf_index, next_fcf_index; |
| 2208 | uint16_t vlan_id; |
| 2209 | int rc; |
| 2210 | |
| 2211 | /* If link state is not up, no need to proceed */ |
| 2212 | if (phba->link_state < LPFC_LINK_UP) |
| 2213 | goto out; |
| 2214 | |
| 2215 | /* If FCF discovery period is over, no need to proceed */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2216 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2217 | goto out; |
| 2218 | |
| 2219 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2220 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2221 | &next_fcf_index); |
| 2222 | if (!new_fcf_record) { |
| 2223 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2224 | "2767 Mailbox command READ_FCF_RECORD " |
| 2225 | "failed to retrieve a FCF record.\n"); |
| 2226 | goto out; |
| 2227 | } |
| 2228 | |
| 2229 | /* Check the connection list for eligibility */ |
| 2230 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2231 | &addr_mode, &vlan_id); |
| 2232 | |
| 2233 | /* Log the FCF record information if turned on */ |
| 2234 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2235 | next_fcf_index); |
| 2236 | |
| 2237 | if (!rc) |
| 2238 | goto out; |
| 2239 | |
| 2240 | /* Update the eligible FCF record index bmask */ |
| 2241 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2242 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 2243 | |
| 2244 | out: |
| 2245 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2246 | } |
| 2247 | |
| 2248 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2249 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2250 | * @phba: pointer to lpfc hba data structure. |
| 2251 | * @mboxq: pointer to mailbox data structure. |
| 2252 | * |
| 2253 | * This function handles completion of init vpi mailbox command. |
| 2254 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2255 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2256 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2257 | { |
| 2258 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2259 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2260 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2261 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2262 | if (mboxq->u.mb.mbxStatus) { |
| 2263 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2264 | LOG_MBOX, |
| 2265 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2266 | mboxq->u.mb.mbxStatus); |
| 2267 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2268 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2269 | return; |
| 2270 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2271 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2272 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2273 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2274 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2275 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2276 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2277 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2278 | if (!ndlp) |
| 2279 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2280 | LOG_DISCOVERY, |
| 2281 | "2731 Cannot find fabric " |
| 2282 | "controller node\n"); |
| 2283 | else |
| 2284 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2285 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2286 | return; |
| 2287 | } |
| 2288 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2289 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2290 | lpfc_initial_fdisc(vport); |
| 2291 | else { |
| 2292 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2293 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2294 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2295 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2296 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2297 | return; |
| 2298 | } |
| 2299 | |
| 2300 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2301 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2302 | * @vport: pointer to lpfc_vport data structure. |
| 2303 | * |
| 2304 | * This function issue a init_vpi mailbox command to initialize |
| 2305 | * VPI for the vport. |
| 2306 | */ |
| 2307 | void |
| 2308 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2309 | { |
| 2310 | LPFC_MBOXQ_t *mboxq; |
| 2311 | int rc; |
| 2312 | |
| 2313 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2314 | if (!mboxq) { |
| 2315 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2316 | LOG_MBOX, "2607 Failed to allocate " |
| 2317 | "init_vpi mailbox\n"); |
| 2318 | return; |
| 2319 | } |
| 2320 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2321 | mboxq->vport = vport; |
| 2322 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2323 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2324 | if (rc == MBX_NOT_FINISHED) { |
| 2325 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2326 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2327 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2332 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2333 | * @phba: pointer to lpfc hba data structure. |
| 2334 | * |
| 2335 | * This function loops through the list of vports on the @phba and issues an |
| 2336 | * FDISC if possible. |
| 2337 | */ |
| 2338 | void |
| 2339 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2340 | { |
| 2341 | struct lpfc_vport **vports; |
| 2342 | int i; |
| 2343 | |
| 2344 | vports = lpfc_create_vport_work_array(phba); |
| 2345 | if (vports != NULL) { |
| 2346 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2347 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2348 | continue; |
| 2349 | /* There are no vpi for this vport */ |
| 2350 | if (vports[i]->vpi > phba->max_vpi) { |
| 2351 | lpfc_vport_set_state(vports[i], |
| 2352 | FC_VPORT_FAILED); |
| 2353 | continue; |
| 2354 | } |
| 2355 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2356 | lpfc_vport_set_state(vports[i], |
| 2357 | FC_VPORT_LINKDOWN); |
| 2358 | continue; |
| 2359 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2360 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2361 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2362 | continue; |
| 2363 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2364 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2365 | lpfc_initial_fdisc(vports[i]); |
| 2366 | else { |
| 2367 | lpfc_vport_set_state(vports[i], |
| 2368 | FC_VPORT_NO_FABRIC_SUPP); |
| 2369 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2370 | LOG_ELS, |
| 2371 | "0259 No NPIV " |
| 2372 | "Fabric support\n"); |
| 2373 | } |
| 2374 | } |
| 2375 | } |
| 2376 | lpfc_destroy_vport_work_array(phba, vports); |
| 2377 | } |
| 2378 | |
| 2379 | void |
| 2380 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2381 | { |
| 2382 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2383 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2384 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2385 | |
| 2386 | if (mboxq->u.mb.mbxStatus) { |
| 2387 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2388 | "2018 REG_VFI mbxStatus error x%x " |
| 2389 | "HBA state x%x\n", |
| 2390 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 2391 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2392 | /* FLOGI failed, use loop map to make discovery list */ |
| 2393 | lpfc_disc_list_loopmap(vport); |
| 2394 | /* Start discovery */ |
| 2395 | lpfc_disc_start(vport); |
| 2396 | goto fail_free_mem; |
| 2397 | } |
| 2398 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2399 | goto fail_free_mem; |
| 2400 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2401 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2402 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2403 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2404 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2405 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2406 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2407 | |
| 2408 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
| 2409 | lpfc_start_fdiscs(phba); |
| 2410 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2411 | } |
| 2412 | |
| 2413 | fail_free_mem: |
| 2414 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2415 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2416 | kfree(dmabuf); |
| 2417 | return; |
| 2418 | } |
| 2419 | |
| 2420 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2423 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2425 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | |
| 2427 | |
| 2428 | /* Check for error */ |
| 2429 | if (mb->mbxStatus) { |
| 2430 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2431 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2432 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2433 | "hba state x%x>\n", |
| 2434 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | goto out; |
| 2437 | } |
| 2438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | sizeof (struct serv_parm)); |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 2441 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 2443 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 2444 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 2446 | vport->fc_sparam.portName.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2447 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 2448 | sizeof(vport->fc_nodename)); |
| 2449 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 2450 | sizeof(vport->fc_portname)); |
| 2451 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2452 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2453 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2454 | } |
| 2455 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2457 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | return; |
| 2460 | |
| 2461 | out: |
| 2462 | pmb->context1 = NULL; |
| 2463 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2464 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2465 | lpfc_issue_clear_la(phba, vport); |
| 2466 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | return; |
| 2468 | } |
| 2469 | |
| 2470 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2471 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2473 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2474 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2475 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2476 | struct lpfc_dmabuf *mp; |
| 2477 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2478 | struct fcf_record *fcf_record; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2479 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2480 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2481 | switch (la->UlnkSpeed) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2482 | case LA_1GHZ_LINK: |
| 2483 | phba->fc_linkspeed = LA_1GHZ_LINK; |
| 2484 | break; |
| 2485 | case LA_2GHZ_LINK: |
| 2486 | phba->fc_linkspeed = LA_2GHZ_LINK; |
| 2487 | break; |
| 2488 | case LA_4GHZ_LINK: |
| 2489 | phba->fc_linkspeed = LA_4GHZ_LINK; |
| 2490 | break; |
| 2491 | case LA_8GHZ_LINK: |
| 2492 | phba->fc_linkspeed = LA_8GHZ_LINK; |
| 2493 | break; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2494 | case LA_10GHZ_LINK: |
| 2495 | phba->fc_linkspeed = LA_10GHZ_LINK; |
| 2496 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2497 | default: |
| 2498 | phba->fc_linkspeed = LA_UNKNW_LINK; |
| 2499 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | phba->fc_topology = la->topology; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2503 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | |
| 2505 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2506 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2508 | /* if npiv is enabled and this adapter supports npiv log |
| 2509 | * a message that npiv is not supported in this topology |
| 2510 | */ |
| 2511 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2512 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2513 | "1309 Link Up Event npiv not supported in loop " |
| 2514 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2515 | /* Get Loop Map information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | if (la->il) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2517 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2519 | vport->fc_myDID = la->granted_AL_PA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | i = la->un.lilpBde64.tus.f.bdeSize; |
| 2521 | |
| 2522 | if (i == 0) { |
| 2523 | phba->alpa_map[0] = 0; |
| 2524 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2525 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | int numalpa, j, k; |
| 2527 | union { |
| 2528 | uint8_t pamap[16]; |
| 2529 | struct { |
| 2530 | uint32_t wd1; |
| 2531 | uint32_t wd2; |
| 2532 | uint32_t wd3; |
| 2533 | uint32_t wd4; |
| 2534 | } pa; |
| 2535 | } un; |
| 2536 | numalpa = phba->alpa_map[0]; |
| 2537 | j = 0; |
| 2538 | while (j < numalpa) { |
| 2539 | memset(un.pamap, 0, 16); |
| 2540 | for (k = 1; j < numalpa; k++) { |
| 2541 | un.pamap[k - 1] = |
| 2542 | phba->alpa_map[j + 1]; |
| 2543 | j++; |
| 2544 | if (k == 16) |
| 2545 | break; |
| 2546 | } |
| 2547 | /* Link Up Event ALPA map */ |
| 2548 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2549 | KERN_WARNING, |
| 2550 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2551 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | "ALPA map Data: x%x " |
| 2553 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2554 | un.pa.wd1, un.pa.wd2, |
| 2555 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2560 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2561 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2562 | (phba->sli_rev == 3)) |
| 2563 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 2564 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2565 | vport->fc_myDID = phba->fc_pref_DID; |
| 2566 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2568 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | |
| 2570 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 2571 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2572 | if (!sparam_mbox) |
| 2573 | goto out; |
| 2574 | |
| 2575 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 2576 | if (rc) { |
| 2577 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2578 | goto out; |
| 2579 | } |
| 2580 | sparam_mbox->vport = vport; |
| 2581 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 2582 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 2583 | if (rc == MBX_NOT_FINISHED) { |
| 2584 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 2585 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2586 | kfree(mp); |
| 2587 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2588 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | } |
| 2590 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2591 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) { |
| 2592 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2593 | if (!cfglink_mbox) |
| 2594 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2597 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 2598 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2599 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2600 | if (rc == MBX_NOT_FINISHED) { |
| 2601 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 2602 | goto out; |
| 2603 | } |
| 2604 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2605 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2606 | /* |
| 2607 | * Add the driver's default FCF record at FCF index 0 now. This |
| 2608 | * is phase 1 implementation that support FCF index 0 and driver |
| 2609 | * defaults. |
| 2610 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2611 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2612 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 2613 | GFP_KERNEL); |
| 2614 | if (unlikely(!fcf_record)) { |
| 2615 | lpfc_printf_log(phba, KERN_ERR, |
| 2616 | LOG_MBOX | LOG_SLI, |
| 2617 | "2554 Could not allocate memmory for " |
| 2618 | "fcf record\n"); |
| 2619 | rc = -ENODEV; |
| 2620 | goto out; |
| 2621 | } |
| 2622 | |
| 2623 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 2624 | LPFC_FCOE_FCF_DEF_INDEX); |
| 2625 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 2626 | if (unlikely(rc)) { |
| 2627 | lpfc_printf_log(phba, KERN_ERR, |
| 2628 | LOG_MBOX | LOG_SLI, |
| 2629 | "2013 Could not manually add FCF " |
| 2630 | "record 0, status %d\n", rc); |
| 2631 | rc = -ENODEV; |
| 2632 | kfree(fcf_record); |
| 2633 | goto out; |
| 2634 | } |
| 2635 | kfree(fcf_record); |
| 2636 | } |
| 2637 | /* |
| 2638 | * The driver is expected to do FIP/FCF. Call the port |
| 2639 | * and get the FCF Table. |
| 2640 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2641 | spin_lock_irq(&phba->hbalock); |
| 2642 | if (phba->hba_flag & FCF_DISC_INPROGRESS) { |
| 2643 | spin_unlock_irq(&phba->hbalock); |
| 2644 | return; |
| 2645 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2646 | /* This is the initial FCF discovery scan */ |
| 2647 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2648 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2649 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 2650 | "2778 Start FCF table scan at linkup\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2651 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2652 | LPFC_FCOE_FCF_GET_FIRST); |
| 2653 | if (rc) { |
| 2654 | spin_lock_irq(&phba->hbalock); |
| 2655 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 2656 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2657 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2658 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 2659 | /* Reset FCF roundrobin bmask for new discovery */ |
| 2660 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 2661 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2663 | |
| 2664 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2665 | out: |
| 2666 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2667 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2668 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 2669 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2670 | lpfc_issue_clear_la(phba, vport); |
| 2671 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2675 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2676 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | uint32_t control; |
| 2678 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2679 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2681 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 2682 | control = readl(phba->HCregaddr); |
| 2683 | control |= HC_LAINT_ENA; |
| 2684 | writel(control, phba->HCregaddr); |
| 2685 | readl(phba->HCregaddr); /* flush */ |
| 2686 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2687 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | } |
| 2689 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2690 | static void |
| 2691 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 2692 | { |
| 2693 | lpfc_linkdown(phba); |
| 2694 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2695 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2696 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 2697 | } |
| 2698 | |
| 2699 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | /* |
| 2701 | * This routine handles processing a READ_LA mailbox |
| 2702 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2703 | * as the completion routine when the command is |
| 2704 | * handed off to the SLI layer. |
| 2705 | */ |
| 2706 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | struct lpfc_vport *vport = pmb->vport; |
| 2710 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | READ_LA_VAR *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2712 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2713 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2714 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2715 | /* Unblock ELS traffic */ |
| 2716 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | /* Check for error */ |
| 2718 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2719 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2720 | "1307 READ_LA mbox error x%x state x%x\n", |
| 2721 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2723 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 2725 | } |
| 2726 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2727 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | |
| 2729 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 2730 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2732 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2733 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2734 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2735 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 2736 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2737 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 2738 | if ((phba->fc_eventTag < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2739 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2741 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | if (phba->fc_eventTag != 0) |
| 2743 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2744 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | |
| 2746 | phba->fc_eventTag = la->eventTag; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2747 | spin_lock_irq(&phba->hbalock); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2748 | if (la->mm) |
| 2749 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 2750 | else |
| 2751 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2752 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2754 | phba->link_events++; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2755 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2757 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2758 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2759 | "1306 Link Up Event in loop back mode " |
| 2760 | "x%x received Data: x%x x%x x%x x%x\n", |
| 2761 | la->eventTag, phba->fc_eventTag, |
| 2762 | la->granted_AL_PA, la->UlnkSpeed, |
| 2763 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2764 | } else { |
| 2765 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2766 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2767 | "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] | 2768 | la->eventTag, phba->fc_eventTag, |
| 2769 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2770 | phba->alpa_map[0], |
| 2771 | la->mm, la->fa, |
| 2772 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2773 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2774 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2775 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2777 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 2778 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2779 | "1308 Link Down Event in loop back mode " |
| 2780 | "x%x received " |
| 2781 | "Data: x%x x%x x%x\n", |
| 2782 | la->eventTag, phba->fc_eventTag, |
| 2783 | phba->pport->port_state, vport->fc_flag); |
| 2784 | } |
| 2785 | else { |
| 2786 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2787 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2788 | "Data: x%x x%x x%x x%x x%x\n", |
| 2789 | la->eventTag, phba->fc_eventTag, |
| 2790 | phba->pport->port_state, vport->fc_flag, |
| 2791 | la->mm, la->fa); |
| 2792 | } |
| 2793 | lpfc_mbx_issue_link_down(phba); |
| 2794 | } |
| 2795 | if (la->mm && la->attType == AT_LINK_UP) { |
| 2796 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 2797 | phba->fc_stat.LinkDown++; |
| 2798 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2799 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2800 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2801 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2803 | lpfc_mbx_issue_link_down(phba); |
| 2804 | } else |
| 2805 | lpfc_enable_la(phba); |
| 2806 | |
| 2807 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2808 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 2809 | "Data: x%x x%x x%x\n", |
| 2810 | la->eventTag, phba->fc_eventTag, |
| 2811 | phba->pport->port_state, vport->fc_flag); |
| 2812 | /* |
| 2813 | * The cmnd that triggered this will be waiting for this |
| 2814 | * signal. |
| 2815 | */ |
| 2816 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 2817 | if (phba->wait_4_mlo_maint_flg) { |
| 2818 | phba->wait_4_mlo_maint_flg = 0; |
| 2819 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2820 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | if (la->fa) { |
| 2824 | if (la->mm) |
| 2825 | lpfc_issue_clear_la(phba, vport); |
| 2826 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 2827 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 2831 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2832 | kfree(mp); |
| 2833 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2834 | return; |
| 2835 | } |
| 2836 | |
| 2837 | /* |
| 2838 | * This routine handles processing a REG_LOGIN mailbox |
| 2839 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2840 | * as the completion routine when the command is |
| 2841 | * handed off to the SLI layer. |
| 2842 | */ |
| 2843 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2844 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2846 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2847 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2848 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2849 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2852 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2854 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 2855 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 2856 | |
| 2857 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 2858 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
| 2859 | /* We rcvd a rscn after issuing this |
| 2860 | * mbox reg login, we may have cycled |
| 2861 | * back through the state and be |
| 2862 | * back at reg login state so this |
| 2863 | * mbox needs to be ignored becase |
| 2864 | * there is another reg login in |
| 2865 | * proccess. |
| 2866 | */ |
| 2867 | spin_lock_irq(shost->host_lock); |
| 2868 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 2869 | spin_unlock_irq(shost->host_lock); |
| 2870 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2871 | lpfc_sli4_free_rpi(phba, |
| 2872 | pmb->u.mb.un.varRegLogin.rpi); |
| 2873 | |
| 2874 | } else |
| 2875 | /* Good status, call state machine */ |
| 2876 | lpfc_disc_state_machine(vport, ndlp, pmb, |
| 2877 | NLP_EVT_CMPL_REG_LOGIN); |
| 2878 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2880 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2881 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2882 | /* decrement the node reference count held for this callback |
| 2883 | * function. |
| 2884 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2885 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | |
| 2887 | return; |
| 2888 | } |
| 2889 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2890 | static void |
| 2891 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2892 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2893 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2894 | struct lpfc_vport *vport = pmb->vport; |
| 2895 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2896 | |
| 2897 | switch (mb->mbxStatus) { |
| 2898 | case 0x0011: |
| 2899 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2900 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2901 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 2902 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2903 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 2904 | /* If VPI is busy, reset the HBA */ |
| 2905 | case 0x9700: |
| 2906 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 2907 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 2908 | vport->vpi, mb->mbxStatus); |
| 2909 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 2910 | lpfc_workq_post_event(phba, NULL, NULL, |
| 2911 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2912 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2913 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2914 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 2915 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2916 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2917 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 2918 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2919 | /* |
| 2920 | * This shost reference might have been taken at the beginning of |
| 2921 | * lpfc_vport_delete() |
| 2922 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2923 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | scsi_host_put(shost); |
| 2925 | } |
| 2926 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2927 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2928 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 2929 | { |
| 2930 | struct lpfc_hba *phba = vport->phba; |
| 2931 | LPFC_MBOXQ_t *mbox; |
| 2932 | int rc; |
| 2933 | |
| 2934 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2935 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2936 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2937 | |
| 2938 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 2939 | mbox->vport = vport; |
| 2940 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2941 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2942 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2943 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2944 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2945 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2946 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2947 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2948 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2949 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | static void |
| 2953 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2954 | { |
| 2955 | struct lpfc_vport *vport = pmb->vport; |
| 2956 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2957 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2958 | |
| 2959 | switch (mb->mbxStatus) { |
| 2960 | case 0x0011: |
| 2961 | case 0x9601: |
| 2962 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2963 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2964 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 2965 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2966 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2967 | spin_lock_irq(shost->host_lock); |
| 2968 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 2969 | spin_unlock_irq(shost->host_lock); |
| 2970 | vport->fc_myDID = 0; |
| 2971 | goto out; |
| 2972 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2973 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2974 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2975 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2976 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2977 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2978 | vport->num_disc_nodes = 0; |
| 2979 | /* go thru NPR list and issue ELS PLOGIs */ |
| 2980 | if (vport->fc_npr_cnt) |
| 2981 | lpfc_els_disc_plogi(vport); |
| 2982 | |
| 2983 | if (!vport->num_disc_nodes) { |
| 2984 | spin_lock_irq(shost->host_lock); |
| 2985 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2986 | spin_unlock_irq(shost->host_lock); |
| 2987 | lpfc_can_disctmo(vport); |
| 2988 | } |
| 2989 | vport->port_state = LPFC_VPORT_READY; |
| 2990 | |
| 2991 | out: |
| 2992 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2993 | return; |
| 2994 | } |
| 2995 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2996 | /** |
| 2997 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 2998 | * @phba: pointer to lpfc hba data structure. |
| 2999 | * |
| 3000 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 3001 | * the list of static vports to be created. The function create vports |
| 3002 | * based on the information returned from the HBA. |
| 3003 | **/ |
| 3004 | void |
| 3005 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 3006 | { |
| 3007 | LPFC_MBOXQ_t *pmb = NULL; |
| 3008 | MAILBOX_t *mb; |
| 3009 | struct static_vport_info *vport_info; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3010 | int rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3011 | struct fc_vport_identifiers vport_id; |
| 3012 | struct fc_vport *new_fc_vport; |
| 3013 | struct Scsi_Host *shost; |
| 3014 | struct lpfc_vport *vport; |
| 3015 | uint16_t offset = 0; |
| 3016 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3017 | struct lpfc_dmabuf *mp; |
| 3018 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3019 | |
| 3020 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3021 | if (!pmb) { |
| 3022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3023 | "0542 lpfc_create_static_vport failed to" |
| 3024 | " allocate mailbox memory\n"); |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | mb = &pmb->u.mb; |
| 3029 | |
| 3030 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3031 | if (!vport_info) { |
| 3032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3033 | "0543 lpfc_create_static_vport failed to" |
| 3034 | " allocate vport_info\n"); |
| 3035 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3036 | return; |
| 3037 | } |
| 3038 | |
| 3039 | vport_buff = (uint8_t *) vport_info; |
| 3040 | do { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3041 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3042 | goto out; |
| 3043 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3044 | pmb->vport = phba->pport; |
| 3045 | rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO); |
| 3046 | |
| 3047 | if ((rc != MBX_SUCCESS) || mb->mbxStatus) { |
| 3048 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3049 | "0544 lpfc_create_static_vport failed to" |
| 3050 | " issue dump mailbox command ret 0x%x " |
| 3051 | "status 0x%x\n", |
| 3052 | rc, mb->mbxStatus); |
| 3053 | goto out; |
| 3054 | } |
| 3055 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3056 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3057 | byte_count = pmb->u.mqe.un.mb_words[5]; |
| 3058 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 3059 | if (byte_count > sizeof(struct static_vport_info) - |
| 3060 | offset) |
| 3061 | byte_count = sizeof(struct static_vport_info) |
| 3062 | - offset; |
| 3063 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3064 | offset += byte_count; |
| 3065 | } else { |
| 3066 | if (mb->un.varDmp.word_cnt > |
| 3067 | sizeof(struct static_vport_info) - offset) |
| 3068 | mb->un.varDmp.word_cnt = |
| 3069 | sizeof(struct static_vport_info) |
| 3070 | - offset; |
| 3071 | byte_count = mb->un.varDmp.word_cnt; |
| 3072 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3073 | vport_buff + offset, |
| 3074 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3075 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3076 | offset += byte_count; |
| 3077 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3078 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3079 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3080 | offset < sizeof(struct static_vport_info)); |
| 3081 | |
| 3082 | |
| 3083 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3084 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3085 | != VPORT_INFO_REV)) { |
| 3086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3087 | "0545 lpfc_create_static_vport bad" |
| 3088 | " information header 0x%x 0x%x\n", |
| 3089 | le32_to_cpu(vport_info->signature), |
| 3090 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3091 | |
| 3092 | goto out; |
| 3093 | } |
| 3094 | |
| 3095 | shost = lpfc_shost_from_vport(phba->pport); |
| 3096 | |
| 3097 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3098 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3099 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3100 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3101 | if (!vport_id.port_name || !vport_id.node_name) |
| 3102 | continue; |
| 3103 | |
| 3104 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3105 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3106 | vport_id.disable = false; |
| 3107 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3108 | |
| 3109 | if (!new_fc_vport) { |
| 3110 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3111 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3112 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3113 | continue; |
| 3114 | } |
| 3115 | |
| 3116 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3117 | vport->vport_flag |= STATIC_VPORT; |
| 3118 | } |
| 3119 | |
| 3120 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3121 | kfree(vport_info); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3122 | if (rc != MBX_TIMEOUT) { |
| 3123 | if (pmb->context2) { |
| 3124 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 3125 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3126 | kfree(mp); |
| 3127 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3128 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3129 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3130 | |
| 3131 | return; |
| 3132 | } |
| 3133 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3134 | /* |
| 3135 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3136 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3137 | * as the completion routine when the command is |
| 3138 | * handed off to the SLI layer. |
| 3139 | */ |
| 3140 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3141 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3143 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3144 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3145 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3146 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3147 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3148 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3149 | pmb->context1 = NULL; |
| 3150 | pmb->context2 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3151 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3152 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3154 | "0258 Register Fabric login error: 0x%x\n", |
| 3155 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3156 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3157 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3158 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3160 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3161 | /* FLOGI failed, use loop map to make discovery list */ |
| 3162 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3164 | /* Start discovery */ |
| 3165 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3166 | /* Decrement the reference count to ndlp after the |
| 3167 | * reference to the ndlp are done. |
| 3168 | */ |
| 3169 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3170 | return; |
| 3171 | } |
| 3172 | |
| 3173 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3174 | /* Decrement the reference count to ndlp after the reference |
| 3175 | * to the ndlp are done. |
| 3176 | */ |
| 3177 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | return; |
| 3179 | } |
| 3180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3182 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3184 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3186 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3187 | /* when physical port receive logo donot start |
| 3188 | * vport discovery */ |
| 3189 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3190 | lpfc_start_fdiscs(phba); |
| 3191 | else |
| 3192 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3193 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3197 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3198 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3199 | |
| 3200 | /* Drop the reference count from the mbox at the end after |
| 3201 | * all the current reference to the ndlp have been done. |
| 3202 | */ |
| 3203 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3204 | return; |
| 3205 | } |
| 3206 | |
| 3207 | /* |
| 3208 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3209 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3210 | * as the completion routine when the command is |
| 3211 | * handed off to the SLI layer. |
| 3212 | */ |
| 3213 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3214 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3216 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3217 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3218 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3219 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3220 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3221 | pmb->context1 = NULL; |
| 3222 | pmb->context2 = NULL; |
| 3223 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3224 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3225 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3226 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3227 | "0260 Register NameServer error: 0x%x\n", |
| 3228 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3229 | /* decrement the node reference count held for this |
| 3230 | * callback function. |
| 3231 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3232 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3233 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3234 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3235 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3236 | |
| 3237 | /* If no other thread is using the ndlp, free it */ |
| 3238 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3240 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3241 | /* |
| 3242 | * RegLogin failed, use loop map to make discovery |
| 3243 | * list |
| 3244 | */ |
| 3245 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3247 | /* Start discovery */ |
| 3248 | lpfc_disc_start(vport); |
| 3249 | return; |
| 3250 | } |
| 3251 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | return; |
| 3253 | } |
| 3254 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3256 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3258 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3260 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3261 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3262 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3263 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3264 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3265 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3266 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3267 | |
| 3268 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3269 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | } |
| 3271 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3272 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3274 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3276 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | } |
| 3278 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3279 | /* decrement the node reference count held for this |
| 3280 | * callback function. |
| 3281 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3282 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3284 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3286 | |
| 3287 | return; |
| 3288 | } |
| 3289 | |
| 3290 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3291 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3293 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3294 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | struct lpfc_rport_data *rdata; |
| 3296 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3297 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | |
| 3299 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3300 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3301 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | rport_ids.port_id = ndlp->nlp_DID; |
| 3303 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3305 | /* |
| 3306 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3307 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3308 | * rport->dd_data points. So, if we're reusing a previously |
| 3309 | * registered port, drop the reference that we took the last time we |
| 3310 | * registered the port. |
| 3311 | */ |
| 3312 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3313 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3314 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3315 | |
| 3316 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3317 | "rport add: did:x%x flg:x%x type x%x", |
| 3318 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3320 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3321 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3323 | "Warning: fc_remote_port_add failed\n"); |
| 3324 | return; |
| 3325 | } |
| 3326 | |
| 3327 | /* initialize static port data */ |
| 3328 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3329 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3331 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3332 | |
| 3333 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3334 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3335 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3336 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3337 | |
| 3338 | |
| 3339 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3340 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3341 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3342 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3343 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3344 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3345 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3346 | return; |
| 3347 | } |
| 3348 | |
| 3349 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3350 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3351 | { |
| 3352 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3353 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3354 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3355 | "rport delete: did:x%x flg:x%x type x%x", |
| 3356 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3357 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3358 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | |
| 3360 | return; |
| 3361 | } |
| 3362 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3363 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3365 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3367 | |
| 3368 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3369 | switch (state) { |
| 3370 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3372 | break; |
| 3373 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3374 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3375 | break; |
| 3376 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3378 | break; |
| 3379 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3380 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3381 | break; |
| 3382 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3383 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3384 | break; |
| 3385 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3387 | break; |
| 3388 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3390 | break; |
| 3391 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3393 | break; |
| 3394 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3395 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3396 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3397 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3398 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3400 | int old_state, int new_state) |
| 3401 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3403 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3404 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3405 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3406 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3407 | } |
| 3408 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3409 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3410 | if (new_state == NLP_STE_NPR_NODE) |
| 3411 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3413 | /* Transport interface */ |
| 3414 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 3415 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3416 | vport->phba->nport_event_cnt++; |
| 3417 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3418 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3420 | if (new_state == NLP_STE_MAPPED_NODE || |
| 3421 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3423 | /* |
| 3424 | * Tell the fc transport about the port, if we haven't |
| 3425 | * already. If we have, and it's a scsi entity, be |
| 3426 | * sure to unblock any attached scsi devices |
| 3427 | */ |
| 3428 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3429 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3430 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 3431 | (vport->stat_data_enabled)) { |
| 3432 | /* |
| 3433 | * A new target is discovered, if there is no buffer for |
| 3434 | * statistical data collection allocate buffer. |
| 3435 | */ |
| 3436 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 3437 | sizeof(struct lpfc_scsicmd_bkt), |
| 3438 | GFP_KERNEL); |
| 3439 | |
| 3440 | if (!ndlp->lat_data) |
| 3441 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3442 | "0286 lpfc_nlp_state_cleanup failed to " |
| 3443 | "allocate statistical data buffer DID " |
| 3444 | "0x%x\n", ndlp->nlp_DID); |
| 3445 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3446 | /* |
| 3447 | * if we added to Mapped list, but the remote port |
| 3448 | * registration failed or assigned a target id outside |
| 3449 | * our presentable range - move the node to the |
| 3450 | * Unmapped List |
| 3451 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3452 | if (new_state == NLP_STE_MAPPED_NODE && |
| 3453 | (!ndlp->rport || |
| 3454 | ndlp->rport->scsi_target_id == -1 || |
| 3455 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3457 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | spin_unlock_irq(shost->host_lock); |
| 3459 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3461 | } |
| 3462 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3463 | static char * |
| 3464 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 3465 | { |
| 3466 | static char *states[] = { |
| 3467 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 3468 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 3469 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 3470 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 3471 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 3472 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 3473 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 3474 | [NLP_STE_NPR_NODE] = "NPR", |
| 3475 | }; |
| 3476 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 3477 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3478 | strlcpy(buffer, states[state], size); |
| 3479 | else |
| 3480 | snprintf(buffer, size, "unknown (%d)", state); |
| 3481 | return buffer; |
| 3482 | } |
| 3483 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3484 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3485 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3486 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3487 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3488 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3489 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3490 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3491 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3492 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3493 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 3494 | ndlp->nlp_DID, |
| 3495 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 3496 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3497 | |
| 3498 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3499 | "node statechg did:x%x old:%d ste:%d", |
| 3500 | ndlp->nlp_DID, old_state, state); |
| 3501 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3502 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3503 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3504 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3505 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 3506 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 3507 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 3508 | } |
| 3509 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3510 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | spin_lock_irq(shost->host_lock); |
| 3512 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3513 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3514 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3515 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3516 | |
| 3517 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3518 | lpfc_nlp_counters(vport, state, 1); |
| 3519 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3523 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3524 | { |
| 3525 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3526 | |
| 3527 | if (list_empty(&ndlp->nlp_listp)) { |
| 3528 | spin_lock_irq(shost->host_lock); |
| 3529 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3530 | spin_unlock_irq(shost->host_lock); |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3535 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3538 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3539 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3540 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3541 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3542 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3543 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3544 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3545 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3546 | NLP_STE_UNUSED_NODE); |
| 3547 | } |
| 3548 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 3549 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3550 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3551 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3552 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3553 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 3554 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3555 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 3556 | NLP_STE_UNUSED_NODE); |
| 3557 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3559 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3560 | * @vport: Pointer to Virtual Port object. |
| 3561 | * @ndlp: Pointer to FC node object. |
| 3562 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3563 | * |
| 3564 | * This function is always called when node object need to be initialized. |
| 3565 | * It initializes all the fields of the node object. Although the reference |
| 3566 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 3567 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 3568 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 3569 | * the final release of ndlp is determined by its reference count. And, the |
| 3570 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3571 | **/ |
| 3572 | static inline void |
| 3573 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3574 | uint32_t did) |
| 3575 | { |
| 3576 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 3577 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 3578 | init_timer(&ndlp->nlp_delayfunc); |
| 3579 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 3580 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 3581 | ndlp->nlp_DID = did; |
| 3582 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3583 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3584 | ndlp->nlp_sid = NLP_NO_SID; |
| 3585 | kref_init(&ndlp->kref); |
| 3586 | NLP_INT_NODE_ACT(ndlp); |
| 3587 | atomic_set(&ndlp->cmd_pending, 0); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3588 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3589 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3590 | |
| 3591 | struct lpfc_nodelist * |
| 3592 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3593 | int state) |
| 3594 | { |
| 3595 | struct lpfc_hba *phba = vport->phba; |
| 3596 | uint32_t did; |
| 3597 | unsigned long flags; |
| 3598 | |
| 3599 | if (!ndlp) |
| 3600 | return NULL; |
| 3601 | |
| 3602 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3603 | /* The ndlp should not be in memory free mode */ |
| 3604 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3605 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3606 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3607 | "0277 lpfc_enable_node: ndlp:x%p " |
| 3608 | "usgmap:x%x refcnt:%d\n", |
| 3609 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3610 | atomic_read(&ndlp->kref.refcount)); |
| 3611 | return NULL; |
| 3612 | } |
| 3613 | /* The ndlp should not already be in active mode */ |
| 3614 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3615 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3616 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3617 | "0278 lpfc_enable_node: ndlp:x%p " |
| 3618 | "usgmap:x%x refcnt:%d\n", |
| 3619 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3620 | atomic_read(&ndlp->kref.refcount)); |
| 3621 | return NULL; |
| 3622 | } |
| 3623 | |
| 3624 | /* Keep the original DID */ |
| 3625 | did = ndlp->nlp_DID; |
| 3626 | |
| 3627 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 3628 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 3629 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3630 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3631 | |
| 3632 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3633 | |
| 3634 | if (state != NLP_STE_UNUSED_NODE) |
| 3635 | lpfc_nlp_set_state(vport, ndlp, state); |
| 3636 | |
| 3637 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3638 | "node enable: did:x%x", |
| 3639 | ndlp->nlp_DID, 0, 0); |
| 3640 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3644 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3645 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3646 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3647 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3648 | * 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] | 3649 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 3650 | * until ALL other outstanding threads have completed. We check |
| 3651 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3652 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3653 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3654 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3655 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3656 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3657 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /* |
| 3661 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 3662 | */ |
| 3663 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3664 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3667 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | uint32_t tmo; |
| 3669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3670 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3671 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3672 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 3673 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3674 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3675 | * FC spec states we need 3 * ratov for CT requests |
| 3676 | */ |
| 3677 | tmo = ((phba->fc_ratov * 3) + 3); |
| 3678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3680 | |
| 3681 | if (!timer_pending(&vport->fc_disctmo)) { |
| 3682 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3683 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 3684 | tmo, vport->port_state, vport->fc_flag); |
| 3685 | } |
| 3686 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3687 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 3688 | spin_lock_irq(shost->host_lock); |
| 3689 | vport->fc_flag |= FC_DISC_TMO; |
| 3690 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | |
| 3692 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3693 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3694 | "0247 Start Discovery Timer state x%x " |
| 3695 | "Data: x%x x%lx x%x x%x\n", |
| 3696 | vport->port_state, tmo, |
| 3697 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 3698 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | |
| 3700 | return; |
| 3701 | } |
| 3702 | |
| 3703 | /* |
| 3704 | * Cancel rescue timer for Discovery / RSCN handling |
| 3705 | */ |
| 3706 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3707 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3710 | unsigned long iflags; |
| 3711 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3712 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3713 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 3714 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 3715 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3717 | if (vport->fc_flag & FC_DISC_TMO) { |
| 3718 | spin_lock_irqsave(shost->host_lock, iflags); |
| 3719 | vport->fc_flag &= ~FC_DISC_TMO; |
| 3720 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 3721 | del_timer_sync(&vport->fc_disctmo); |
| 3722 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 3723 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 3724 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3728 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3729 | "0248 Cancel Discovery Timer state x%x " |
| 3730 | "Data: x%x x%x x%x\n", |
| 3731 | vport->port_state, vport->fc_flag, |
| 3732 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3733 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | /* |
| 3737 | * Check specified ring for outstanding IOCB on the SLI queue |
| 3738 | * Return true if iocb matches the specified nport |
| 3739 | */ |
| 3740 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 3742 | struct lpfc_sli_ring *pring, |
| 3743 | struct lpfc_iocbq *iocb, |
| 3744 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3746 | struct lpfc_sli *psli = &phba->sli; |
| 3747 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3748 | struct lpfc_vport *vport = ndlp->vport; |
| 3749 | |
| 3750 | if (iocb->vport != vport) |
| 3751 | return 0; |
| 3752 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | if (pring->ringno == LPFC_ELS_RING) { |
| 3754 | switch (icmd->ulpCommand) { |
| 3755 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3756 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3757 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 3759 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 3760 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | case CMD_XMIT_ELS_RSP64_CX: |
| 3762 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3763 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3765 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | |
| 3767 | } else if (pring->ringno == psli->fcp_ring) { |
| 3768 | /* Skip match check if waiting to relogin to FCP target */ |
| 3769 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3770 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3771 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | } |
| 3773 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3774 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | } |
| 3776 | } else if (pring->ringno == psli->next_ring) { |
| 3777 | |
| 3778 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3779 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | /* |
| 3783 | * Free resources / clean up outstanding I/Os |
| 3784 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 3785 | */ |
| 3786 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3787 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3789 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | struct lpfc_sli *psli; |
| 3791 | struct lpfc_sli_ring *pring; |
| 3792 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3793 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3795 | lpfc_fabric_abort_nport(ndlp); |
| 3796 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | /* |
| 3798 | * Everything that matches on txcmplq will be returned |
| 3799 | * by firmware with a no rpi error. |
| 3800 | */ |
| 3801 | psli = &phba->sli; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3802 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | /* Now process each ring */ |
| 3804 | for (i = 0; i < psli->num_rings; i++) { |
| 3805 | pring = &psli->ring[i]; |
| 3806 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3807 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3809 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | /* |
| 3811 | * Check to see if iocb matches the nport we are |
| 3812 | * looking for |
| 3813 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3814 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 3815 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | /* It matches, so deque and call compl |
| 3817 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3818 | list_move_tail(&iocb->list, |
| 3819 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | } |
| 3822 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3823 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } |
| 3825 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3826 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3827 | /* Cancel all the IOCBs from the completions list */ |
| 3828 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3829 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3830 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3831 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | /* |
| 3835 | * Free rpi associated with LPFC_NODELIST entry. |
| 3836 | * This routine is called from lpfc_freenode(), when we are removing |
| 3837 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 3838 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 3839 | * to the remote NPort. In addition, it is called after we receive |
| 3840 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 3841 | * we are waiting to PLOGI back to the remote NPort. |
| 3842 | */ |
| 3843 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3846 | struct lpfc_hba *phba = vport->phba; |
| 3847 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | int rc; |
| 3849 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3850 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3852 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3853 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3854 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3855 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3856 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 3861 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | ndlp->nlp_rpi = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3863 | ndlp->nlp_flag &= ~NLP_RPI_VALID; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 3864 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | return 1; |
| 3866 | } |
| 3867 | return 0; |
| 3868 | } |
| 3869 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3870 | /** |
| 3871 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 3872 | * @phba: pointer to lpfc hba data structure. |
| 3873 | * |
| 3874 | * This routine is invoked to unregister all the currently registered RPIs |
| 3875 | * to the HBA. |
| 3876 | **/ |
| 3877 | void |
| 3878 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 3879 | { |
| 3880 | struct lpfc_vport **vports; |
| 3881 | struct lpfc_nodelist *ndlp; |
| 3882 | struct Scsi_Host *shost; |
| 3883 | int i; |
| 3884 | |
| 3885 | vports = lpfc_create_vport_work_array(phba); |
| 3886 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3887 | shost = lpfc_shost_from_vport(vports[i]); |
| 3888 | spin_lock_irq(shost->host_lock); |
| 3889 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3890 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| 3891 | /* The mempool_alloc might sleep */ |
| 3892 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3893 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3894 | spin_lock_irq(shost->host_lock); |
| 3895 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3896 | } |
| 3897 | spin_unlock_irq(shost->host_lock); |
| 3898 | } |
| 3899 | lpfc_destroy_vport_work_array(phba, vports); |
| 3900 | } |
| 3901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3902 | void |
| 3903 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 3904 | { |
| 3905 | struct lpfc_hba *phba = vport->phba; |
| 3906 | LPFC_MBOXQ_t *mbox; |
| 3907 | int rc; |
| 3908 | |
| 3909 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3910 | if (mbox) { |
| 3911 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 3912 | mbox->vport = vport; |
| 3913 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3914 | mbox->context1 = NULL; |
| 3915 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3916 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3917 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3918 | |
| 3919 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 3920 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3921 | "1836 Could not issue " |
| 3922 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | void |
| 3927 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 3928 | { |
| 3929 | struct lpfc_hba *phba = vport->phba; |
| 3930 | LPFC_MBOXQ_t *mbox; |
| 3931 | int rc; |
| 3932 | |
| 3933 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3934 | if (mbox) { |
| 3935 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 3936 | mbox->vport = vport; |
| 3937 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3938 | mbox->context1 = NULL; |
| 3939 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3940 | if (rc != MBX_TIMEOUT) |
| 3941 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3942 | |
| 3943 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3944 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3945 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3946 | "unreg_did (default rpis) status %d\n", |
| 3947 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | /* |
| 3952 | * Free resources associated with LPFC_NODELIST entry |
| 3953 | * so it can be freed. |
| 3954 | */ |
| 3955 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3956 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3959 | struct lpfc_hba *phba = vport->phba; |
| 3960 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | |
| 3963 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3964 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3965 | "0900 Cleanup node for NPort x%x " |
| 3966 | "Data: x%x x%x x%x\n", |
| 3967 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3968 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3969 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3970 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3971 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 3972 | "usgmap:x%x refcnt:%d\n", |
| 3973 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3974 | atomic_read(&ndlp->kref.refcount)); |
| 3975 | lpfc_dequeue_node(vport, ndlp); |
| 3976 | } else { |
| 3977 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3978 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 3979 | "usgmap:x%x refcnt:%d\n", |
| 3980 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3981 | atomic_read(&ndlp->kref.refcount)); |
| 3982 | lpfc_disable_node(vport, ndlp); |
| 3983 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 3986 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3987 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 3989 | mb->context2 = NULL; |
| 3990 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3991 | } |
| 3992 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3993 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3996 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3998 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 3999 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4000 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | kfree(mp); |
| 4002 | } |
| 4003 | list_del(&mb->list); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 4004 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4005 | lpfc_sli4_free_rpi(phba, |
| 4006 | mb->u.mb.un.varRegLogin.rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4007 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4008 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 4009 | * the ndlp reference count as we are in the process |
| 4010 | * of lpfc_nlp_release. |
| 4011 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | } |
| 4013 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4015 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4016 | lpfc_els_abort(phba, ndlp); |
| 4017 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4019 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4020 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4021 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4022 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4024 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4025 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4026 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4028 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4030 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | /* |
| 4034 | * Check to see if we can free the nlp back to the freelist. |
| 4035 | * If we are in the middle of using the nlp in the discovery state |
| 4036 | * machine, defer the free till we reach the end of the state machine. |
| 4037 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4038 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4039 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4041 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4042 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4043 | LPFC_MBOXQ_t *mbox; |
| 4044 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4046 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4047 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 4048 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4049 | !(ndlp->nlp_flag & NLP_RPI_VALID)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4050 | /* For this case we need to cleanup the default rpi |
| 4051 | * allocated by the firmware. |
| 4052 | */ |
| 4053 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4054 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4055 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4056 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 4057 | if (rc) { |
| 4058 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4059 | } |
| 4060 | else { |
| 4061 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4062 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4063 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4064 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4065 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4066 | if (rc == MBX_NOT_FINISHED) { |
| 4067 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4068 | } |
| 4069 | } |
| 4070 | } |
| 4071 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4072 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4073 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | * We can get here with a non-NULL ndlp->rport because when we |
| 4076 | * unregister a rport we don't break the rport/node linkage. So if we |
| 4077 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4078 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4079 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4080 | rdata = ndlp->rport->dd_data; |
| 4081 | rdata->pnode = NULL; |
| 4082 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4088 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | |
| 4092 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4093 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | /* First check for Direct match */ |
| 4096 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4097 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | |
| 4099 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4102 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | matchdid.un.word = did; |
| 4106 | ndlpdid.un.word = ndlp->nlp_DID; |
| 4107 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 4108 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 4109 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 4110 | if ((ndlpdid.un.b.domain == 0) && |
| 4111 | (ndlpdid.un.b.area == 0)) { |
| 4112 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4113 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4114 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4115 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | matchdid.un.word = ndlp->nlp_DID; |
| 4119 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 4120 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 4121 | if ((matchdid.un.b.domain == 0) && |
| 4122 | (matchdid.un.b.area == 0)) { |
| 4123 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4124 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | } |
| 4126 | } |
| 4127 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4128 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | } |
| 4130 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4131 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | static struct lpfc_nodelist * |
| 4133 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 4135 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 | uint32_t data1; |
| 4137 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4138 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 4139 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4140 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 4141 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 4142 | ((uint32_t) ndlp->nlp_type << 8) | |
| 4143 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4144 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4145 | "0929 FIND node DID " |
| 4146 | "Data: x%p x%x x%x x%x\n", |
| 4147 | ndlp, ndlp->nlp_DID, |
| 4148 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4149 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | } |
| 4151 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4154 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4155 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | return NULL; |
| 4157 | } |
| 4158 | |
| 4159 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4160 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4161 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4162 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | spin_lock_irq(shost->host_lock); |
| 4166 | ndlp = __lpfc_findnode_did(vport, did); |
| 4167 | spin_unlock_irq(shost->host_lock); |
| 4168 | return ndlp; |
| 4169 | } |
| 4170 | |
| 4171 | struct lpfc_nodelist * |
| 4172 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 4173 | { |
| 4174 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4175 | struct lpfc_nodelist *ndlp; |
| 4176 | |
| 4177 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4178 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4179 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4180 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4181 | return NULL; |
| 4182 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4183 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4184 | if (!ndlp) |
| 4185 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4186 | lpfc_nlp_init(vport, ndlp, did); |
| 4187 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4188 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4190 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4192 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4193 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4194 | if (!ndlp) |
| 4195 | return NULL; |
| 4196 | spin_lock_irq(shost->host_lock); |
| 4197 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4198 | spin_unlock_irq(shost->host_lock); |
| 4199 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4201 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4202 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4203 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4204 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4205 | /* If we've already recieved a PLOGI from this NPort |
| 4206 | * we don't need to try to discover it again. |
| 4207 | */ |
| 4208 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4209 | return NULL; |
| 4210 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4211 | /* Since this node is marked for discovery, |
| 4212 | * delay timeout is not needed. |
| 4213 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4214 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4215 | spin_lock_irq(shost->host_lock); |
| 4216 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4217 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4218 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4220 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4221 | /* If we've already recieved a PLOGI from this NPort, |
| 4222 | * or we are already in the process of discovery on it, |
| 4223 | * we don't need to try to discover it again. |
| 4224 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4225 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4226 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4227 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4229 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4230 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4232 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | } |
| 4234 | return ndlp; |
| 4235 | } |
| 4236 | |
| 4237 | /* Build a list of nodes to discover based on the loopmap */ |
| 4238 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4239 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4241 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | int j; |
| 4243 | uint32_t alpa, index; |
| 4244 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | |
| 4248 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4249 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4250 | |
| 4251 | /* Check for loop map present or not */ |
| 4252 | if (phba->alpa_map[0]) { |
| 4253 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4254 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | } |
| 4259 | } else { |
| 4260 | /* No alpamap, so try all alpa's */ |
| 4261 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4262 | /* If cfg_scan_down is set, start from highest |
| 4263 | * ALPA (0xef) to lowest (0x1). |
| 4264 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4265 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | index = j; |
| 4267 | else |
| 4268 | index = FC_MAXLOOP - j - 1; |
| 4269 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4270 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | return; |
| 4276 | } |
| 4277 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4282 | struct lpfc_sli *psli = &phba->sli; |
| 4283 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4284 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4285 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4286 | int rc; |
| 4287 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4288 | /* |
| 4289 | * if it's not a physical port or if we already send |
| 4290 | * clear_la then don't send it. |
| 4291 | */ |
| 4292 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4293 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4294 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4295 | return; |
| 4296 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4297 | /* Link up discovery */ |
| 4298 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4299 | phba->link_state = LPFC_CLEAR_LA; |
| 4300 | lpfc_clear_la(phba, mbox); |
| 4301 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4302 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4303 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | if (rc == MBX_NOT_FINISHED) { |
| 4305 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4306 | lpfc_disc_flush_list(vport); |
| 4307 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4308 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4309 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4310 | phba->link_state = LPFC_HBA_ERROR; |
| 4311 | } |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4316 | void |
| 4317 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4318 | { |
| 4319 | LPFC_MBOXQ_t *regvpimbox; |
| 4320 | |
| 4321 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4322 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4323 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4324 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4325 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4326 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4327 | == MBX_NOT_FINISHED) { |
| 4328 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 4334 | void |
| 4335 | lpfc_disc_start(struct lpfc_vport *vport) |
| 4336 | { |
| 4337 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4338 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4339 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4341 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4343 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4345 | |
| 4346 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | clear_la_pending = 1; |
| 4348 | else |
| 4349 | clear_la_pending = 0; |
| 4350 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4351 | if (vport->port_state < LPFC_VPORT_READY) |
| 4352 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4354 | lpfc_set_disctmo(vport); |
| 4355 | |
| 4356 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4358 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | |
| 4361 | vport->fc_prevDID = vport->fc_myDID; |
| 4362 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | |
| 4364 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4365 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4366 | "0202 Start Discovery hba state x%x " |
| 4367 | "Data: x%x x%x x%x\n", |
| 4368 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 4369 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | |
| 4371 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | |
| 4374 | if (num_sent) |
| 4375 | return; |
| 4376 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4377 | /* |
| 4378 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 4379 | * continue discovery. |
| 4380 | */ |
| 4381 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4382 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4383 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 4384 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4385 | lpfc_issue_reg_vpi(phba, vport); |
| 4386 | return; |
| 4387 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4388 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4389 | /* |
| 4390 | * For SLI2, we need to set port_state to READY and continue |
| 4391 | * discovery. |
| 4392 | */ |
| 4393 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 4394 | /* If we get here, there is nothing to ADISC */ |
| 4395 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 4396 | lpfc_issue_clear_la(phba, vport); |
| 4397 | |
| 4398 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | vport->num_disc_nodes = 0; |
| 4400 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 4401 | if (vport->fc_npr_cnt) |
| 4402 | lpfc_els_disc_plogi(vport); |
| 4403 | |
| 4404 | if (!vport->num_disc_nodes) { |
| 4405 | spin_lock_irq(shost->host_lock); |
| 4406 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 4407 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4408 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | } |
| 4410 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4411 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | } else { |
| 4413 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4414 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | |
| 4416 | if (num_sent) |
| 4417 | return; |
| 4418 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | /* Check to see if more RSCNs came in while we |
| 4421 | * were processing this one. |
| 4422 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4423 | if ((vport->fc_rscn_id_cnt == 0) && |
| 4424 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 4425 | spin_lock_irq(shost->host_lock); |
| 4426 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 4427 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4428 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4429 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4430 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | return; |
| 4434 | } |
| 4435 | |
| 4436 | /* |
| 4437 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 4438 | * ring the match the sppecified nodelist. |
| 4439 | */ |
| 4440 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4443 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4444 | struct lpfc_sli *psli; |
| 4445 | IOCB_t *icmd; |
| 4446 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4447 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | |
| 4449 | psli = &phba->sli; |
| 4450 | pring = &psli->ring[LPFC_ELS_RING]; |
| 4451 | |
| 4452 | /* Error matching iocb on txq or txcmplq |
| 4453 | * First check the txq. |
| 4454 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4457 | if (iocb->context1 != ndlp) { |
| 4458 | continue; |
| 4459 | } |
| 4460 | icmd = &iocb->iocb; |
| 4461 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 4462 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 4463 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4464 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | /* Next check the txcmplq */ |
| 4470 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 4471 | if (iocb->context1 != ndlp) { |
| 4472 | continue; |
| 4473 | } |
| 4474 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4475 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 4476 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4477 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4478 | } |
| 4479 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4481 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4482 | /* Cancel all the IOCBs from the completions list */ |
| 4483 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4484 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4485 | } |
| 4486 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4487 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | { |
| 4490 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4493 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 4494 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4495 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4496 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4497 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4498 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4499 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 4500 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4501 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4502 | } |
| 4503 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | } |
| 4505 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4506 | void |
| 4507 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 4508 | { |
| 4509 | lpfc_els_flush_rscn(vport); |
| 4510 | lpfc_els_flush_cmd(vport); |
| 4511 | lpfc_disc_flush_list(vport); |
| 4512 | } |
| 4513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | /*****************************************************************************/ |
| 4515 | /* |
| 4516 | * NAME: lpfc_disc_timeout |
| 4517 | * |
| 4518 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 4519 | * |
| 4520 | * EXECUTION ENVIRONMENT: interrupt only |
| 4521 | * |
| 4522 | * CALLED FROM: |
| 4523 | * Timer function |
| 4524 | * |
| 4525 | * RETURNS: |
| 4526 | * none |
| 4527 | */ |
| 4528 | /*****************************************************************************/ |
| 4529 | void |
| 4530 | lpfc_disc_timeout(unsigned long ptr) |
| 4531 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4533 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4534 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4535 | unsigned long flags = 0; |
| 4536 | |
| 4537 | if (unlikely(!phba)) |
| 4538 | return; |
| 4539 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4540 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 4541 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 4542 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4544 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4546 | if (!tmo_posted) |
| 4547 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4548 | return; |
| 4549 | } |
| 4550 | |
| 4551 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4552 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4553 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4555 | struct lpfc_hba *phba = vport->phba; |
| 4556 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4557 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4558 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4559 | int rc, clrlaerr = 0; |
| 4560 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4561 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4562 | return; |
| 4563 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4564 | spin_lock_irq(shost->host_lock); |
| 4565 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4566 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4567 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4568 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4569 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 4570 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | |
| 4574 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 4576 | * FAN |
| 4577 | */ |
| 4578 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4579 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 4580 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4581 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4583 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4584 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4585 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4586 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 4587 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4588 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 4589 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4590 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4591 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4592 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4593 | /* Fail outstanding IO now since device |
| 4594 | * is marked for PLOGI. |
| 4595 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4596 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4597 | } |
| 4598 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4599 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4600 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4601 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4602 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4603 | break; |
| 4604 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4605 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4608 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4609 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4610 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4611 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4612 | |
| 4613 | /* Assume no Fabric and go on with discovery. |
| 4614 | * Check for outstanding ELS FLOGI to abort. |
| 4615 | */ |
| 4616 | |
| 4617 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4619 | |
| 4620 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | break; |
| 4623 | |
| 4624 | case LPFC_FABRIC_CFG_LINK: |
| 4625 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 4626 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4627 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4628 | "0223 Timeout while waiting for " |
| 4629 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4632 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4633 | lpfc_els_abort(phba, ndlp); |
| 4634 | |
| 4635 | /* ReStart discovery */ |
| 4636 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | |
| 4638 | case LPFC_NS_QRY: |
| 4639 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4640 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4641 | "0224 NameServer Query timeout " |
| 4642 | "Data: x%x x%x\n", |
| 4643 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4644 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4645 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 4646 | /* Try it one more time */ |
| 4647 | vport->fc_ns_retry++; |
| 4648 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 4649 | vport->fc_ns_retry, 0); |
| 4650 | if (rc == 0) |
| 4651 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4652 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4653 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4654 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4655 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4656 | /* |
| 4657 | * Discovery is over. |
| 4658 | * set port_state to PORT_READY if SLI2. |
| 4659 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4660 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4661 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4662 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4663 | lpfc_issue_reg_vpi(phba, vport); |
| 4664 | else { /* NPIV Not enabled */ |
| 4665 | lpfc_issue_clear_la(phba, vport); |
| 4666 | vport->port_state = LPFC_VPORT_READY; |
| 4667 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 4671 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4672 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4673 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4674 | "0206 Device Discovery " |
| 4675 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4676 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4677 | break; |
| 4678 | } |
| 4679 | |
| 4680 | lpfc_linkdown(phba); |
| 4681 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 4682 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4683 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4684 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4685 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4686 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4687 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4688 | if (rc == MBX_NOT_FINISHED) |
| 4689 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 4690 | |
| 4691 | break; |
| 4692 | |
| 4693 | case LPFC_DISC_AUTH: |
| 4694 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4695 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4696 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4697 | lpfc_disc_flush_list(vport); |
| 4698 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4699 | /* |
| 4700 | * set port_state to PORT_READY if SLI2. |
| 4701 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4702 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4703 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4704 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4705 | lpfc_issue_reg_vpi(phba, vport); |
| 4706 | else { /* NPIV Not enabled */ |
| 4707 | lpfc_issue_clear_la(phba, vport); |
| 4708 | vport->port_state = LPFC_VPORT_READY; |
| 4709 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4710 | } |
| 4711 | break; |
| 4712 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4713 | case LPFC_VPORT_READY: |
| 4714 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4715 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4716 | "0231 RSCN timeout Data: x%x " |
| 4717 | "x%x\n", |
| 4718 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4719 | |
| 4720 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4721 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | lpfc_els_flush_rscn(vport); |
| 4724 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4725 | } |
| 4726 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4728 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4729 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4730 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4731 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4732 | break; |
| 4733 | } |
| 4734 | |
| 4735 | switch (phba->link_state) { |
| 4736 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4737 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4738 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4739 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | clrlaerr = 1; |
| 4741 | break; |
| 4742 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4743 | case LPFC_LINK_UP: |
| 4744 | lpfc_issue_clear_la(phba, vport); |
| 4745 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4746 | case LPFC_LINK_UNKNOWN: |
| 4747 | case LPFC_WARM_START: |
| 4748 | case LPFC_INIT_START: |
| 4749 | case LPFC_INIT_MBX_CMDS: |
| 4750 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4751 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4752 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4753 | "0230 Unexpected timeout, hba link " |
| 4754 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4755 | clrlaerr = 1; |
| 4756 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4757 | |
| 4758 | case LPFC_HBA_READY: |
| 4759 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4763 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4764 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4766 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4767 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | return; |
| 4771 | } |
| 4772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | /* |
| 4774 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 4775 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4776 | * as the completion routine when the command is |
| 4777 | * handed off to the SLI layer. |
| 4778 | */ |
| 4779 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4780 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4782 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 4784 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4785 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4786 | |
| 4787 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4788 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4791 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4793 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4794 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4795 | /* |
| 4796 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 4797 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 4798 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4800 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4801 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4802 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 4803 | else |
| 4804 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4806 | /* decrement the node reference count held for this callback |
| 4807 | * function. |
| 4808 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4809 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4811 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4812 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4813 | |
| 4814 | return; |
| 4815 | } |
| 4816 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4817 | static int |
| 4818 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 4819 | { |
| 4820 | uint16_t *rpi = param; |
| 4821 | |
| 4822 | return ndlp->nlp_rpi == *rpi; |
| 4823 | } |
| 4824 | |
| 4825 | static int |
| 4826 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 4827 | { |
| 4828 | return memcmp(&ndlp->nlp_portname, param, |
| 4829 | sizeof(ndlp->nlp_portname)) == 0; |
| 4830 | } |
| 4831 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4832 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4833 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4835 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4837 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4838 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4839 | return ndlp; |
| 4840 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4841 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4842 | } |
| 4843 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4844 | /* |
| 4845 | * 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] | 4846 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4847 | */ |
| 4848 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4849 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4850 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4852 | } |
| 4853 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4854 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4855 | * 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] | 4856 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4857 | */ |
| 4858 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4859 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4860 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4861 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4862 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4863 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4864 | spin_lock_irq(shost->host_lock); |
| 4865 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 4866 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4867 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4868 | } |
| 4869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4871 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4872 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | { |
| 4874 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4875 | |
| 4876 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4877 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4878 | |
| 4879 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4880 | "node init: did:x%x", |
| 4881 | ndlp->nlp_DID, 0, 0); |
| 4882 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | return; |
| 4884 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4885 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4886 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 4887 | * and mempool_free's the nodelist. |
| 4888 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4889 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4890 | lpfc_nlp_release(struct kref *kref) |
| 4891 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4892 | struct lpfc_hba *phba; |
| 4893 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4894 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 4895 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4896 | |
| 4897 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4898 | "node release: did:x%x flg:x%x type:x%x", |
| 4899 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4900 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4901 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4902 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 4903 | "usgmap:x%x refcnt:%d\n", |
| 4904 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4905 | atomic_read(&ndlp->kref.refcount)); |
| 4906 | |
| 4907 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4908 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4909 | |
| 4910 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4911 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4912 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4913 | NLP_CLR_NODE_ACT(ndlp); |
| 4914 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4915 | |
| 4916 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4917 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4918 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4919 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4920 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4921 | } |
| 4922 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4923 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 4924 | * that one discovery thread won't free a ndlp while another discovery thread |
| 4925 | * is using it. |
| 4926 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4927 | struct lpfc_nodelist * |
| 4928 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 4929 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4930 | struct lpfc_hba *phba; |
| 4931 | unsigned long flags; |
| 4932 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4933 | if (ndlp) { |
| 4934 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4935 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 4936 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4937 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4938 | /* The check of ndlp usage to prevent incrementing the |
| 4939 | * ndlp reference count that is in the process of being |
| 4940 | * released. |
| 4941 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4942 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4943 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4944 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 4945 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4946 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4947 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 4948 | "usgmap:x%x refcnt:%d\n", |
| 4949 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4950 | atomic_read(&ndlp->kref.refcount)); |
| 4951 | return NULL; |
| 4952 | } else |
| 4953 | kref_get(&ndlp->kref); |
| 4954 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4955 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4956 | return ndlp; |
| 4957 | } |
| 4958 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4959 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4960 | * count goes to 0, this indicates the the associated nodelist should be |
| 4961 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 4962 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 4963 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4964 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4965 | int |
| 4966 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 4967 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4968 | struct lpfc_hba *phba; |
| 4969 | unsigned long flags; |
| 4970 | |
| 4971 | if (!ndlp) |
| 4972 | return 1; |
| 4973 | |
| 4974 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4975 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 4976 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4977 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4978 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4979 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4980 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 4981 | * possible race condition that kref_put got invoked again |
| 4982 | * after previous one has done ndlp memory free. |
| 4983 | */ |
| 4984 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 4985 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4986 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4987 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 4988 | "usgmap:x%x refcnt:%d\n", |
| 4989 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4990 | atomic_read(&ndlp->kref.refcount)); |
| 4991 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4992 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4993 | /* Check the ndlp inactivate log flag to avoid the possible |
| 4994 | * race condition that kref_put got invoked again after ndlp |
| 4995 | * is already in inactivating state. |
| 4996 | */ |
| 4997 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 4998 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4999 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 5000 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 5001 | "usgmap:x%x refcnt:%d\n", |
| 5002 | (void *)ndlp, ndlp->nlp_usg_map, |
| 5003 | atomic_read(&ndlp->kref.refcount)); |
| 5004 | return 1; |
| 5005 | } |
| 5006 | /* For last put, mark the ndlp usage flags to make sure no |
| 5007 | * other kref_get and kref_put on the same ndlp shall get |
| 5008 | * in between the process when the final kref_put has been |
| 5009 | * invoked on this ndlp. |
| 5010 | */ |
| 5011 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 5012 | /* Indicate ndlp is put to inactive state. */ |
| 5013 | NLP_SET_IACT_REQ(ndlp); |
| 5014 | /* Acknowledge ndlp memory free has been seen. */ |
| 5015 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 5016 | NLP_SET_FREE_ACK(ndlp); |
| 5017 | } |
| 5018 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5019 | /* Note, the kref_put returns 1 when decrementing a reference |
| 5020 | * count that was 1, it invokes the release callback function, |
| 5021 | * but it still left the reference count as 1 (not actually |
| 5022 | * performs the last decrementation). Otherwise, it actually |
| 5023 | * decrements the reference count and returns 0. |
| 5024 | */ |
| 5025 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5026 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5027 | |
| 5028 | /* 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] | 5029 | * by any other discovery thread. This routine returns 1 if the |
| 5030 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 5031 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5032 | */ |
| 5033 | int |
| 5034 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 5035 | { |
| 5036 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5037 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 5038 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5039 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5040 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 5041 | if (lpfc_nlp_put(ndlp)) |
| 5042 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5043 | return 0; |
| 5044 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5045 | |
| 5046 | /** |
| 5047 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 5048 | * @phba: Pointer to hba context object. |
| 5049 | * |
| 5050 | * This function iterate through all FC nodes associated |
| 5051 | * will all vports to check if there is any node with |
| 5052 | * fc_rports associated with it. If there is an fc_rport |
| 5053 | * associated with the node, then the node is either in |
| 5054 | * discovered state or its devloss_timer is pending. |
| 5055 | */ |
| 5056 | static int |
| 5057 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 5058 | { |
| 5059 | struct lpfc_vport **vports; |
| 5060 | int i, ret = 0; |
| 5061 | struct lpfc_nodelist *ndlp; |
| 5062 | struct Scsi_Host *shost; |
| 5063 | |
| 5064 | vports = lpfc_create_vport_work_array(phba); |
| 5065 | |
| 5066 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5067 | shost = lpfc_shost_from_vport(vports[i]); |
| 5068 | spin_lock_irq(shost->host_lock); |
| 5069 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 5070 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 5071 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 5072 | ret = 1; |
| 5073 | spin_unlock_irq(shost->host_lock); |
| 5074 | goto out; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5075 | } else { |
| 5076 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 5077 | "2624 RPI %x DID %x flg %x still " |
| 5078 | "logged in\n", |
| 5079 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5080 | ndlp->nlp_flag); |
| 5081 | if (ndlp->nlp_flag & NLP_RPI_VALID) |
| 5082 | ret = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5083 | } |
| 5084 | } |
| 5085 | spin_unlock_irq(shost->host_lock); |
| 5086 | } |
| 5087 | out: |
| 5088 | lpfc_destroy_vport_work_array(phba, vports); |
| 5089 | return ret; |
| 5090 | } |
| 5091 | |
| 5092 | /** |
| 5093 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 5094 | * @phba: Pointer to hba context object. |
| 5095 | * @mboxq: Pointer to mailbox object. |
| 5096 | * |
| 5097 | * This function frees memory associated with the mailbox command. |
| 5098 | */ |
| 5099 | static void |
| 5100 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5101 | { |
| 5102 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5103 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5104 | |
| 5105 | if (mboxq->u.mb.mbxStatus) { |
| 5106 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5107 | "2555 UNREG_VFI mbxStatus error x%x " |
| 5108 | "HBA state x%x\n", |
| 5109 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5110 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5111 | spin_lock_irq(shost->host_lock); |
| 5112 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
| 5113 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5114 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5115 | return; |
| 5116 | } |
| 5117 | |
| 5118 | /** |
| 5119 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 5120 | * @phba: Pointer to hba context object. |
| 5121 | * @mboxq: Pointer to mailbox object. |
| 5122 | * |
| 5123 | * This function frees memory associated with the mailbox command. |
| 5124 | */ |
| 5125 | static void |
| 5126 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5127 | { |
| 5128 | struct lpfc_vport *vport = mboxq->vport; |
| 5129 | |
| 5130 | if (mboxq->u.mb.mbxStatus) { |
| 5131 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5132 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 5133 | "HBA state x%x\n", |
| 5134 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5135 | } |
| 5136 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5137 | return; |
| 5138 | } |
| 5139 | |
| 5140 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5141 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5142 | * @phba: Pointer to hba context object. |
| 5143 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5144 | * This function prepare the HBA for unregistering the currently registered |
| 5145 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 5146 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5147 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5148 | int |
| 5149 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5150 | { |
| 5151 | LPFC_MBOXQ_t *mbox; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5152 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5153 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5154 | struct Scsi_Host *shost; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5155 | int i, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5156 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5157 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5158 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5159 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5160 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5161 | /* At this point, all discovery is aborted */ |
| 5162 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5163 | |
| 5164 | /* Unregister VPIs */ |
| 5165 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5166 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5167 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5168 | /* Stop FLOGI/FDISC retries */ |
| 5169 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 5170 | if (ndlp) |
| 5171 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5172 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5173 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5174 | shost = lpfc_shost_from_vport(vports[i]); |
| 5175 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5176 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5177 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5178 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5179 | } |
| 5180 | lpfc_destroy_vport_work_array(phba, vports); |
| 5181 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5182 | /* Cleanup any outstanding ELS commands */ |
| 5183 | lpfc_els_flush_all_cmd(phba); |
| 5184 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5185 | /* Unregister VFI */ |
| 5186 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5187 | if (!mbox) { |
| 5188 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5189 | "2556 UNREG_VFI mbox allocation failed" |
| 5190 | "HBA state x%x\n", phba->pport->port_state); |
| 5191 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5192 | } |
| 5193 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5194 | lpfc_unreg_vfi(mbox, phba->pport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5195 | mbox->vport = phba->pport; |
| 5196 | mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 5197 | |
| 5198 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5199 | if (rc == MBX_NOT_FINISHED) { |
| 5200 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5201 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 5202 | "HBA state x%x\n", |
| 5203 | rc, phba->pport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5204 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5205 | return -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5206 | } |
| 5207 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5208 | shost = lpfc_shost_from_vport(phba->pport); |
| 5209 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5210 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5211 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5212 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5213 | return 0; |
| 5214 | } |
| 5215 | |
| 5216 | /** |
| 5217 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5218 | * @phba: Pointer to hba context object. |
| 5219 | * |
| 5220 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5221 | * unregister the currently registered FCF record. The driver does not reset |
| 5222 | * the driver FCF usage state flags. |
| 5223 | * |
| 5224 | * Return 0 if successfully issued, none-zero otherwise. |
| 5225 | */ |
| 5226 | int |
| 5227 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 5228 | { |
| 5229 | LPFC_MBOXQ_t *mbox; |
| 5230 | int rc; |
| 5231 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5232 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5233 | if (!mbox) { |
| 5234 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5235 | "2551 UNREG_FCFI mbox allocation failed" |
| 5236 | "HBA state x%x\n", phba->pport->port_state); |
| 5237 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5238 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5239 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 5240 | mbox->vport = phba->pport; |
| 5241 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 5242 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5243 | |
| 5244 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5245 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5246 | "2552 Unregister FCFI command failed rc x%x " |
| 5247 | "HBA state x%x\n", |
| 5248 | rc, phba->pport->port_state); |
| 5249 | return -EINVAL; |
| 5250 | } |
| 5251 | return 0; |
| 5252 | } |
| 5253 | |
| 5254 | /** |
| 5255 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 5256 | * @phba: Pointer to hba context object. |
| 5257 | * |
| 5258 | * This function unregisters the currently reigstered FCF. This function |
| 5259 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 5260 | */ |
| 5261 | void |
| 5262 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 5263 | { |
| 5264 | int rc; |
| 5265 | |
| 5266 | /* Preparation for unregistering fcf */ |
| 5267 | rc = lpfc_unregister_fcf_prep(phba); |
| 5268 | if (rc) { |
| 5269 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5270 | "2748 Failed to prepare for unregistering " |
| 5271 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5272 | return; |
| 5273 | } |
| 5274 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5275 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5276 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5277 | if (rc) |
| 5278 | return; |
| 5279 | /* Reset HBA FCF states after successful unregister FCF */ |
| 5280 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5281 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5282 | |
| 5283 | /* |
| 5284 | * If driver is not unloading, check if there is any other |
| 5285 | * FCF record that can be used for discovery. |
| 5286 | */ |
| 5287 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5288 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5289 | return; |
| 5290 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5291 | /* This is considered as the initial FCF discovery scan */ |
| 5292 | spin_lock_irq(&phba->hbalock); |
| 5293 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 5294 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5295 | |
| 5296 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5297 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); |
| 5298 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5299 | 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] | 5300 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5301 | if (rc) { |
| 5302 | spin_lock_irq(&phba->hbalock); |
| 5303 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 5304 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5305 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5306 | "2553 lpfc_unregister_unused_fcf failed " |
| 5307 | "to read FCF record HBA state x%x\n", |
| 5308 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5309 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | /** |
| 5313 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 5314 | * @phba: Pointer to hba context object. |
| 5315 | * |
| 5316 | * This function just unregisters the currently reigstered FCF. It does not |
| 5317 | * try to find another FCF for discovery. |
| 5318 | */ |
| 5319 | void |
| 5320 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 5321 | { |
| 5322 | int rc; |
| 5323 | |
| 5324 | /* Preparation for unregistering fcf */ |
| 5325 | rc = lpfc_unregister_fcf_prep(phba); |
| 5326 | if (rc) { |
| 5327 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5328 | "2749 Failed to prepare for unregistering " |
| 5329 | "HBA's FCF record: rc=%d\n", rc); |
| 5330 | return; |
| 5331 | } |
| 5332 | |
| 5333 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5334 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5335 | if (rc) |
| 5336 | return; |
| 5337 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 5338 | spin_lock_irq(&phba->hbalock); |
| 5339 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 5340 | spin_unlock_irq(&phba->hbalock); |
| 5341 | } |
| 5342 | |
| 5343 | /** |
| 5344 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 5345 | * @phba: Pointer to hba context object. |
| 5346 | * |
| 5347 | * This function check if there are any connected remote port for the FCF and |
| 5348 | * if all the devices are disconnected, this function unregister FCFI. |
| 5349 | * This function also tries to use another FCF for discovery. |
| 5350 | */ |
| 5351 | void |
| 5352 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 5353 | { |
| 5354 | /* |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5355 | * If HBA is not running in FIP mode, if HBA does not support |
| 5356 | * FCoE, if FCF discovery is ongoing, or if FCF has not been |
| 5357 | * registered, do nothing. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5358 | */ |
| 5359 | spin_lock_irq(&phba->hbalock); |
| 5360 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT) || |
| 5361 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 5362 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5363 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 5364 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5365 | spin_unlock_irq(&phba->hbalock); |
| 5366 | return; |
| 5367 | } |
| 5368 | spin_unlock_irq(&phba->hbalock); |
| 5369 | |
| 5370 | if (lpfc_fcf_inuse(phba)) |
| 5371 | return; |
| 5372 | |
| 5373 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | /** |
| 5377 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 5378 | * @phba: Pointer to hba context object. |
| 5379 | * @buff: Buffer containing the FCF connection table as in the config |
| 5380 | * region. |
| 5381 | * This function create driver data structure for the FCF connection |
| 5382 | * record table read from config region 23. |
| 5383 | */ |
| 5384 | static void |
| 5385 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 5386 | uint8_t *buff) |
| 5387 | { |
| 5388 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5389 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 5390 | struct lpfc_fcf_conn_rec *conn_rec; |
| 5391 | uint32_t record_count; |
| 5392 | int i; |
| 5393 | |
| 5394 | /* Free the current connect table */ |
| 5395 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5396 | &phba->fcf_conn_rec_list, list) { |
| 5397 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5398 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5399 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5400 | |
| 5401 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 5402 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 5403 | sizeof(struct lpfc_fcf_conn_rec); |
| 5404 | |
| 5405 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 5406 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 5407 | |
| 5408 | for (i = 0; i < record_count; i++) { |
| 5409 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 5410 | continue; |
| 5411 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 5412 | GFP_KERNEL); |
| 5413 | if (!conn_entry) { |
| 5414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5415 | "2566 Failed to allocate connection" |
| 5416 | " table entry\n"); |
| 5417 | return; |
| 5418 | } |
| 5419 | |
| 5420 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 5421 | sizeof(struct lpfc_fcf_conn_rec)); |
| 5422 | conn_entry->conn_rec.vlan_tag = |
| 5423 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 5424 | conn_entry->conn_rec.flags = |
| 5425 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 5426 | list_add_tail(&conn_entry->list, |
| 5427 | &phba->fcf_conn_rec_list); |
| 5428 | } |
| 5429 | } |
| 5430 | |
| 5431 | /** |
| 5432 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 5433 | * @phba: Pointer to hba context object. |
| 5434 | * @buff: Buffer containing the FCoE parameter data structure. |
| 5435 | * |
| 5436 | * This function update driver data structure with config |
| 5437 | * parameters read from config region 23. |
| 5438 | */ |
| 5439 | static void |
| 5440 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 5441 | uint8_t *buff) |
| 5442 | { |
| 5443 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 5444 | struct lpfc_fcoe_params *fcoe_param; |
| 5445 | |
| 5446 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 5447 | buff; |
| 5448 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5449 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5450 | |
| 5451 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 5452 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 5453 | return; |
| 5454 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5455 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 5456 | phba->valid_vlan = 1; |
| 5457 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 5458 | 0xFFF; |
| 5459 | } |
| 5460 | |
| 5461 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 5462 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 5463 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 5464 | return; |
| 5465 | } |
| 5466 | |
| 5467 | /** |
| 5468 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 5469 | * @buff: Buffer containing config region 23 data. |
| 5470 | * @size: Size of the data buffer. |
| 5471 | * @rec_type: Record type to be searched. |
| 5472 | * |
| 5473 | * This function searches config region data to find the begining |
| 5474 | * of the record specified by record_type. If record found, this |
| 5475 | * function return pointer to the record else return NULL. |
| 5476 | */ |
| 5477 | static uint8_t * |
| 5478 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 5479 | { |
| 5480 | uint32_t offset = 0, rec_length; |
| 5481 | |
| 5482 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 5483 | (size < sizeof(uint32_t))) |
| 5484 | return NULL; |
| 5485 | |
| 5486 | rec_length = buff[offset + 1]; |
| 5487 | |
| 5488 | /* |
| 5489 | * One TLV record has one word header and number of data words |
| 5490 | * specified in the rec_length field of the record header. |
| 5491 | */ |
| 5492 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 5493 | <= size) { |
| 5494 | if (buff[offset] == rec_type) |
| 5495 | return &buff[offset]; |
| 5496 | |
| 5497 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 5498 | return NULL; |
| 5499 | |
| 5500 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 5501 | rec_length = buff[offset + 1]; |
| 5502 | } |
| 5503 | return NULL; |
| 5504 | } |
| 5505 | |
| 5506 | /** |
| 5507 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 5508 | * @phba: Pointer to lpfc_hba data structure. |
| 5509 | * @buff: Buffer containing config region 23 data. |
| 5510 | * @size: Size of the data buffer. |
| 5511 | * |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 5512 | * This function parses the FCoE config parameters in config region 23 and |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5513 | * populate driver data structure with the parameters. |
| 5514 | */ |
| 5515 | void |
| 5516 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 5517 | uint8_t *buff, |
| 5518 | uint32_t size) |
| 5519 | { |
| 5520 | uint32_t offset = 0, rec_length; |
| 5521 | uint8_t *rec_ptr; |
| 5522 | |
| 5523 | /* |
| 5524 | * If data size is less than 2 words signature and version cannot be |
| 5525 | * verified. |
| 5526 | */ |
| 5527 | if (size < 2*sizeof(uint32_t)) |
| 5528 | return; |
| 5529 | |
| 5530 | /* Check the region signature first */ |
| 5531 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 5532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5533 | "2567 Config region 23 has bad signature\n"); |
| 5534 | return; |
| 5535 | } |
| 5536 | |
| 5537 | offset += 4; |
| 5538 | |
| 5539 | /* Check the data structure version */ |
| 5540 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 5541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5542 | "2568 Config region 23 has bad version\n"); |
| 5543 | return; |
| 5544 | } |
| 5545 | offset += 4; |
| 5546 | |
| 5547 | rec_length = buff[offset + 1]; |
| 5548 | |
| 5549 | /* Read FCoE param record */ |
| 5550 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5551 | size - offset, FCOE_PARAM_TYPE); |
| 5552 | if (rec_ptr) |
| 5553 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 5554 | |
| 5555 | /* Read FCF connection table */ |
| 5556 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5557 | size - offset, FCOE_CONN_TBL_TYPE); |
| 5558 | if (rec_ptr) |
| 5559 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 5560 | |
| 5561 | } |