| 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) && |
| 279 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 280 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 281 | |
| 282 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 283 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 284 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 285 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 286 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 287 | * @phba: Pointer to hba context object. |
| 288 | * |
| 289 | * This function is called from the functions which need to post |
| 290 | * events from interrupt context. This function allocates data |
| 291 | * structure required for posting event. It also keeps track of |
| 292 | * number of events pending and prevent event storm when there are |
| 293 | * too many events. |
| 294 | **/ |
| 295 | struct lpfc_fast_path_event * |
| 296 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 297 | struct lpfc_fast_path_event *ret; |
| 298 | |
| 299 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 300 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 301 | return NULL; |
| 302 | |
| 303 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 304 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 305 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 306 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 307 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 308 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 309 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 314 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 315 | * @phba: Pointer to hba context object. |
| 316 | * @evt: Event object which need to be freed. |
| 317 | * |
| 318 | * This function frees the data structure required for posting |
| 319 | * events. |
| 320 | **/ |
| 321 | void |
| 322 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 323 | struct lpfc_fast_path_event *evt) { |
| 324 | |
| 325 | atomic_dec(&phba->fast_event_count); |
| 326 | kfree(evt); |
| 327 | } |
| 328 | |
| 329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 330 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 331 | * @phba: Pointer to hba context object. |
| 332 | * @evtp: Event data structure. |
| 333 | * |
| 334 | * This function is called from worker thread, when the interrupt |
| 335 | * context need to post an event. This function posts the event |
| 336 | * to fc transport netlink interface. |
| 337 | **/ |
| 338 | static void |
| 339 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 340 | struct lpfc_work_evt *evtp) |
| 341 | { |
| 342 | unsigned long evt_category, evt_sub_category; |
| 343 | struct lpfc_fast_path_event *fast_evt_data; |
| 344 | char *evt_data; |
| 345 | uint32_t evt_data_size; |
| 346 | struct Scsi_Host *shost; |
| 347 | |
| 348 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 349 | work_evt); |
| 350 | |
| 351 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 352 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 353 | fabric_evt.subcategory; |
| 354 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 355 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 356 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 357 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 358 | evt_data_size = sizeof(fast_evt_data->un. |
| 359 | read_check_error); |
| 360 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 361 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 362 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 363 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 364 | } else { |
| 365 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 366 | return; |
| 367 | } |
| 368 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 369 | switch (evt_sub_category) { |
| 370 | case LPFC_EVENT_QFULL: |
| 371 | case LPFC_EVENT_DEVBSY: |
| 372 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 373 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 374 | break; |
| 375 | case LPFC_EVENT_CHECK_COND: |
| 376 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 377 | evt_data_size = sizeof(fast_evt_data->un. |
| 378 | check_cond_evt); |
| 379 | break; |
| 380 | case LPFC_EVENT_VARQUEDEPTH: |
| 381 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 382 | evt_data_size = sizeof(fast_evt_data->un. |
| 383 | queue_depth_evt); |
| 384 | break; |
| 385 | default: |
| 386 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 387 | return; |
| 388 | } |
| 389 | } else { |
| 390 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | fc_host_post_vendor_event(shost, |
| 395 | fc_get_event_number(), |
| 396 | evt_data_size, |
| 397 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 398 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 399 | |
| 400 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 401 | return; |
| 402 | } |
| 403 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 405 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | { |
| 407 | struct lpfc_work_evt *evtp = NULL; |
| 408 | struct lpfc_nodelist *ndlp; |
| 409 | int free_evt; |
| 410 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | spin_lock_irq(&phba->hbalock); |
| 412 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 414 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 415 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 417 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 418 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 419 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 421 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 422 | /* decrement the node reference count held |
| 423 | * for this queued work |
| 424 | */ |
| 425 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 427 | case LPFC_EVT_DEV_LOSS: |
| 428 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 429 | lpfc_dev_loss_tmo_handler(ndlp); |
| 430 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 431 | /* decrement the node reference count held for |
| 432 | * this queued work |
| 433 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 434 | lpfc_nlp_put(ndlp); |
| 435 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 437 | if (phba->link_state < LPFC_LINK_DOWN) |
| 438 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 439 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 440 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 441 | complete((struct completion *)(evtp->evt_arg2)); |
| 442 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 443 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 444 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 445 | lpfc_offline_prep(phba); |
| 446 | *(int *)(evtp->evt_arg1) = 0; |
| 447 | complete((struct completion *)(evtp->evt_arg2)); |
| 448 | break; |
| 449 | case LPFC_EVT_OFFLINE: |
| 450 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 451 | lpfc_sli_brdrestart(phba); |
| 452 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 453 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 454 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 455 | complete((struct completion *)(evtp->evt_arg2)); |
| 456 | break; |
| 457 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 458 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 459 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 460 | lpfc_sli_brdreset(phba); |
| 461 | lpfc_hba_down_post(phba); |
| 462 | *(int *)(evtp->evt_arg1) = |
| 463 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 464 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 465 | complete((struct completion *)(evtp->evt_arg2)); |
| 466 | break; |
| 467 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 468 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 469 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 470 | = (phba->pport->stopped) |
| 471 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 472 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | complete((struct completion *)(evtp->evt_arg2)); |
| 474 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 475 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 476 | lpfc_send_fastpath_evt(phba, evtp); |
| 477 | free_evt = 0; |
| 478 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 479 | case LPFC_EVT_RESET_HBA: |
| 480 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 481 | lpfc_reset_hba(phba); |
| 482 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 483 | } |
| 484 | if (free_evt) |
| 485 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 486 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 487 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 488 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 489 | |
| 490 | } |
| 491 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 492 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 493 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 494 | { |
| 495 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 496 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 497 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 498 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 499 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 501 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | ha_copy = phba->work_ha; |
| 503 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 506 | /* First, try to post the next mailbox command to SLI4 device */ |
| 507 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 508 | lpfc_sli4_post_async_mbox(phba); |
| 509 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 510 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 511 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | lpfc_handle_eratt(phba); |
| 513 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 514 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | lpfc_sli_handle_mb_event(phba); |
| 516 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 517 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 519 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 520 | /* Process SLI4 events */ |
| 521 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
| 522 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 523 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 524 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 525 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 526 | if (phba->hba_flag & ASYNC_EVENT) |
| 527 | lpfc_sli4_async_event_proc(phba); |
| 528 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 529 | spin_lock_irq(&phba->hbalock); |
| 530 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 531 | spin_unlock_irq(&phba->hbalock); |
| 532 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 533 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 534 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
| 535 | lpfc_sli4_fcf_redisc_event_proc(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 536 | } |
| 537 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 538 | vports = lpfc_create_vport_work_array(phba); |
| 539 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 540 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 541 | /* |
| 542 | * We could have no vports in array if unloading, so if |
| 543 | * this happens then just use the pport |
| 544 | */ |
| 545 | if (vports[i] == NULL && i == 0) |
| 546 | vport = phba->pport; |
| 547 | else |
| 548 | vport = vports[i]; |
| 549 | if (vport == NULL) |
| 550 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 551 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 552 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 553 | vport->work_port_events &= ~work_port_events; |
| 554 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 555 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 556 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 557 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 558 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 559 | if (work_port_events & WORKER_HB_TMO) |
| 560 | lpfc_hb_timeout_handler(phba); |
| 561 | if (work_port_events & WORKER_MBOX_TMO) |
| 562 | lpfc_mbox_timeout_handler(phba); |
| 563 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 564 | lpfc_unblock_fabric_iocbs(phba); |
| 565 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 566 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 567 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 568 | lpfc_ramp_down_queue_handler(phba); |
| 569 | if (work_port_events & WORKER_RAMP_UP_QUEUE) |
| 570 | lpfc_ramp_up_queue_handler(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 571 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 572 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 573 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 574 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 575 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 576 | status >>= (4*LPFC_ELS_RING); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 577 | if ((status & HA_RXMASK) || |
| 578 | (pring->flag & LPFC_DEFERRED_RING_EVENT) || |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 579 | (phba->hba_flag & HBA_SP_QUEUE_EVT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 580 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 581 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 582 | /* Set the lpfc data pending flag */ |
| 583 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 584 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 585 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 586 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 587 | (status & |
| 588 | HA_RXMASK)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 589 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 590 | if (phba->pport->work_port_events & WORKER_SERVICE_TXQ) |
| 591 | lpfc_drain_txq(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 592 | /* |
| 593 | * Turn on Ring interrupts |
| 594 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 595 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 596 | spin_lock_irq(&phba->hbalock); |
| 597 | control = readl(phba->HCregaddr); |
| 598 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 599 | lpfc_debugfs_slow_ring_trc(phba, |
| 600 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 601 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 602 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 603 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 604 | writel(control, phba->HCregaddr); |
| 605 | readl(phba->HCregaddr); /* flush */ |
| 606 | } else { |
| 607 | lpfc_debugfs_slow_ring_trc(phba, |
| 608 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 609 | control, ha_copy, 0); |
| 610 | } |
| 611 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | } |
| 613 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 614 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | } |
| 616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | int |
| 618 | lpfc_do_work(void *p) |
| 619 | { |
| 620 | struct lpfc_hba *phba = p; |
| 621 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | |
| 623 | set_user_nice(current, -20); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 624 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 626 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 627 | /* wait and check worker queue activities */ |
| 628 | rc = wait_event_interruptible(phba->work_waitq, |
| 629 | (test_and_clear_bit(LPFC_DATA_READY, |
| 630 | &phba->data_flags) |
| 631 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 632 | /* Signal wakeup shall terminate the worker thread */ |
| 633 | if (rc) { |
| 634 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 635 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 637 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 638 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 639 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 640 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 642 | phba->worker_thread = NULL; |
| 643 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 644 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * This is only called to handle FC worker events. Since this a rare |
| 650 | * occurance, we allocate a struct lpfc_work_evt structure here instead of |
| 651 | * embedding it in the IOCB. |
| 652 | */ |
| 653 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 654 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 655 | uint32_t evt) |
| 656 | { |
| 657 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 658 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | |
| 660 | /* |
| 661 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 662 | * be queued to worker thread for processing |
| 663 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 664 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | if (!evtp) |
| 666 | return 0; |
| 667 | |
| 668 | evtp->evt_arg1 = arg1; |
| 669 | evtp->evt_arg2 = arg2; |
| 670 | evtp->evt = evt; |
| 671 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 672 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 673 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 674 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 676 | lpfc_worker_wake_up(phba); |
| 677 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | return 1; |
| 679 | } |
| 680 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 681 | void |
| 682 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 683 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 684 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 685 | struct lpfc_hba *phba = vport->phba; |
| 686 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 687 | int rc; |
| 688 | |
| 689 | 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] | 690 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 691 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 692 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 693 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 694 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 695 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 696 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 697 | lpfc_unreg_rpi(vport, ndlp); |
| 698 | |
| 699 | /* Leave Fabric nodes alone on link down */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 700 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 701 | (!remove && ndlp->nlp_type & NLP_FABRIC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 702 | continue; |
| 703 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 704 | remove |
| 705 | ? NLP_EVT_DEVICE_RM |
| 706 | : NLP_EVT_DEVICE_RECOVERY); |
| 707 | } |
| 708 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
| 709 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 710 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 711 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 712 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 716 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 717 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 718 | { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 719 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 720 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 721 | /* Cleanup any outstanding received buffers */ |
| 722 | lpfc_cleanup_rcv_buffers(vport); |
| 723 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 724 | /* Cleanup any outstanding RSCN activity */ |
| 725 | lpfc_els_flush_rscn(vport); |
| 726 | |
| 727 | /* Cleanup any outstanding ELS commands */ |
| 728 | lpfc_els_flush_cmd(vport); |
| 729 | |
| 730 | lpfc_cleanup_rpis(vport, 0); |
| 731 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 732 | /* Turn off discovery timer if its running */ |
| 733 | lpfc_can_disctmo(vport); |
| 734 | } |
| 735 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 736 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 737 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 738 | { |
| 739 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 740 | |
| 741 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 742 | |
| 743 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 744 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 745 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 746 | |
| 747 | lpfc_port_link_failure(vport); |
| 748 | |
| 749 | } |
| 750 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 752 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 754 | struct lpfc_vport *vport = phba->pport; |
| 755 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 756 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 757 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 758 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 759 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 760 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 761 | return 0; |
James Smart | aacc20e | 2009-12-21 17:02:51 -0500 | [diff] [blame] | 762 | |
| 763 | /* Block all SCSI stack I/Os */ |
| 764 | lpfc_scsi_dev_block(phba); |
| 765 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 766 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 767 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 768 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 769 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 770 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 771 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 772 | phba->pport->fc_flag &= ~FC_LBIT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 773 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 774 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 775 | vports = lpfc_create_vport_work_array(phba); |
| 776 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 777 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 778 | /* Issue a LINK DOWN event to all nodes */ |
| 779 | lpfc_linkdown_port(vports[i]); |
| 780 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 781 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 784 | if (mb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 785 | lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 788 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 794 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 795 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 796 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 797 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 798 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 800 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 801 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 802 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 803 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 804 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | } |
| 806 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 807 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 808 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 809 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 811 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 812 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 813 | } |
| 814 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 815 | static void |
| 816 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 817 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | struct lpfc_nodelist *ndlp; |
| 819 | |
| 820 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 821 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 822 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 823 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 824 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 825 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 826 | /* On Linkup its safe to clean up the ndlp |
| 827 | * from Fabric connections. |
| 828 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 829 | if (ndlp->nlp_DID != Fabric_DID) |
| 830 | lpfc_unreg_rpi(vport, ndlp); |
| 831 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 832 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 833 | /* Fail outstanding IO now since device is |
| 834 | * marked for PLOGI. |
| 835 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | lpfc_unreg_rpi(vport, ndlp); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | static void |
| 842 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 843 | { |
| 844 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | struct lpfc_hba *phba = vport->phba; |
| 846 | |
| 847 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 848 | return; |
| 849 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 850 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 851 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 852 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 853 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 854 | /* If NPIV is not enabled, only bring the physical port up */ |
| 855 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 856 | (vport != phba->pport)) |
| 857 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 858 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 859 | 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] | 860 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 861 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 862 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 863 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 864 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 865 | vport->fc_ns_retry = 0; |
| 866 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 868 | if (vport->fc_flag & FC_LBIT) |
| 869 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static int |
| 874 | lpfc_linkup(struct lpfc_hba *phba) |
| 875 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 876 | struct lpfc_vport **vports; |
| 877 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 878 | |
| 879 | phba->link_state = LPFC_LINK_UP; |
| 880 | |
| 881 | /* Unblock fabric iocbs if they are blocked */ |
| 882 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 883 | del_timer_sync(&phba->fabric_block_timer); |
| 884 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 885 | vports = lpfc_create_vport_work_array(phba); |
| 886 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 887 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 888 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 889 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 890 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 891 | (phba->sli_rev < LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 892 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * This routine handles processing a CLEAR_LA mailbox |
| 899 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 900 | * as the completion routine when the command is |
| 901 | * handed off to the SLI layer. |
| 902 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 903 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 904 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 906 | struct lpfc_vport *vport = pmb->vport; |
| 907 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 908 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 909 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | uint32_t control; |
| 911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 912 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 913 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 915 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 916 | |
| 917 | /* Check for error */ |
| 918 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 919 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 920 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 921 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 922 | "state x%x\n", |
| 923 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 924 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | goto out; |
| 926 | } |
| 927 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 928 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 929 | phba->link_state = LPFC_HBA_READY; |
| 930 | |
| 931 | spin_lock_irq(&phba->hbalock); |
| 932 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 933 | control = readl(phba->HCregaddr); |
| 934 | control |= HC_LAINT_ENA; |
| 935 | writel(control, phba->HCregaddr); |
| 936 | readl(phba->HCregaddr); /* flush */ |
| 937 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 938 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 939 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | out: |
| 942 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 943 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 944 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 945 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 947 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 948 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 951 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | |
| 953 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 954 | |
| 955 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 957 | control = readl(phba->HCregaddr); |
| 958 | control |= HC_LAINT_ENA; |
| 959 | writel(control, phba->HCregaddr); |
| 960 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 961 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 962 | |
| 963 | return; |
| 964 | } |
| 965 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 966 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 968 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 970 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 972 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 973 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 975 | mempool_free(pmb, phba->mbox_mem_pool); |
| 976 | |
| 977 | if (phba->fc_topology == TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 979 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 980 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 981 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 982 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 983 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 984 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 985 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 986 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 989 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 990 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 991 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 992 | lpfc_initial_flogi(vport); |
| 993 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 994 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 995 | |
| 996 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 997 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 998 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 999 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1000 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1001 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1002 | |
| 1003 | lpfc_linkdown(phba); |
| 1004 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1005 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1006 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 1007 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1009 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1014 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1015 | { |
| 1016 | struct lpfc_vport *vport = mboxq->vport; |
| 1017 | unsigned long flags; |
| 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 */ |
| 1031 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1032 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
| 1033 | spin_unlock_irqrestore(&phba->hbalock, flags); |
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 | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1039 | spin_lock_irqsave(&phba->hbalock, flags); |
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 | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1042 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 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; |
| 1242 | unsigned long flags; |
| 1243 | |
| 1244 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1245 | |
| 1246 | /* If the FCF is not availabe do nothing. */ |
| 1247 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1248 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1249 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | /* The FCF is already registered, start discovery */ |
| 1254 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1255 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1256 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1257 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1258 | if (phba->pport->port_state != LPFC_FLOGI) |
| 1259 | lpfc_initial_flogi(phba->pport); |
| 1260 | return; |
| 1261 | } |
| 1262 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1263 | |
| 1264 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, |
| 1265 | GFP_KERNEL); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1266 | if (!fcf_mbxq) { |
| 1267 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1268 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
| 1269 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1270 | return; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1271 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1272 | |
| 1273 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1274 | fcf_mbxq->vport = phba->pport; |
| 1275 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1276 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1277 | if (rc == MBX_NOT_FINISHED) { |
| 1278 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1279 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
| 1280 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1281 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1282 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1283 | |
| 1284 | return; |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1289 | * @phba: pointer to lpfc hba data structure. |
| 1290 | * @new_fcf_record: pointer to fcf record. |
| 1291 | * @boot_flag: Indicates if this record used by boot bios. |
| 1292 | * @addr_mode: The address mode to be used by this FCF |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1293 | * @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] | 1294 | * |
| 1295 | * This routine compare the fcf record with connect list obtained from the |
| 1296 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1297 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1298 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1299 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1300 | * used for this FCF when the function returns. |
| 1301 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1302 | * 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] | 1303 | * 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] | 1304 | **/ |
| 1305 | static int |
| 1306 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1307 | struct fcf_record *new_fcf_record, |
| 1308 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1309 | uint16_t *vlan_id) |
| 1310 | { |
| 1311 | struct lpfc_fcf_conn_entry *conn_entry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1312 | int i, j, fcf_vlan_id = 0; |
| 1313 | |
| 1314 | /* Find the lowest VLAN id in the FCF record */ |
| 1315 | for (i = 0; i < 512; i++) { |
| 1316 | if (new_fcf_record->vlan_bitmap[i]) { |
| 1317 | fcf_vlan_id = i * 8; |
| 1318 | j = 0; |
| 1319 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { |
| 1320 | j++; |
| 1321 | fcf_vlan_id++; |
| 1322 | } |
| 1323 | break; |
| 1324 | } |
| 1325 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1326 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1327 | /* If FCF not available return 0 */ |
| 1328 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
| 1329 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record)) |
| 1330 | return 0; |
| 1331 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1332 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1333 | *boot_flag = 0; |
| 1334 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1335 | new_fcf_record); |
| 1336 | if (phba->valid_vlan) |
| 1337 | *vlan_id = phba->vlan_id; |
| 1338 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1339 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1340 | return 1; |
| 1341 | } |
| 1342 | |
| 1343 | /* |
| 1344 | * If there are no FCF connection table entry, driver connect to all |
| 1345 | * FCFs. |
| 1346 | */ |
| 1347 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1348 | *boot_flag = 0; |
| 1349 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1350 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1351 | |
| 1352 | /* |
| 1353 | * When there are no FCF connect entries, use driver's default |
| 1354 | * addressing mode - FPMA. |
| 1355 | */ |
| 1356 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1357 | *addr_mode = LPFC_FCF_FPMA; |
| 1358 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1359 | /* If FCF record report a vlan id use that vlan id */ |
| 1360 | if (fcf_vlan_id) |
| 1361 | *vlan_id = fcf_vlan_id; |
| 1362 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1363 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1364 | return 1; |
| 1365 | } |
| 1366 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1367 | list_for_each_entry(conn_entry, |
| 1368 | &phba->fcf_conn_rec_list, list) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1369 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1370 | continue; |
| 1371 | |
| 1372 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1373 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1374 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1375 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1376 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1377 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1378 | new_fcf_record)) |
| 1379 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1380 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1381 | /* |
| 1382 | * If the vlan bit map does not have the bit set for the |
| 1383 | * vlan id to be used, then it is not a match. |
| 1384 | */ |
| 1385 | if (!(new_fcf_record->vlan_bitmap |
| 1386 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1387 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1388 | continue; |
| 1389 | } |
| 1390 | |
| 1391 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1392 | * If connection record does not support any addressing mode, |
| 1393 | * skip the FCF record. |
| 1394 | */ |
| 1395 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1396 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1397 | continue; |
| 1398 | |
| 1399 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1400 | * Check if the connection record specifies a required |
| 1401 | * addressing mode. |
| 1402 | */ |
| 1403 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1404 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1405 | |
| 1406 | /* |
| 1407 | * If SPMA required but FCF not support this continue. |
| 1408 | */ |
| 1409 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1410 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1411 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1412 | continue; |
| 1413 | |
| 1414 | /* |
| 1415 | * If FPMA required but FCF not support this continue. |
| 1416 | */ |
| 1417 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1418 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1419 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1420 | continue; |
| 1421 | } |
| 1422 | |
| 1423 | /* |
| 1424 | * This fcf record matches filtering criteria. |
| 1425 | */ |
| 1426 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1427 | *boot_flag = 1; |
| 1428 | else |
| 1429 | *boot_flag = 0; |
| 1430 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1431 | /* |
| 1432 | * If user did not specify any addressing mode, or if the |
| 1433 | * prefered addressing mode specified by user is not supported |
| 1434 | * by FCF, allow fabric to pick the addressing mode. |
| 1435 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1436 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1437 | new_fcf_record); |
| 1438 | /* |
| 1439 | * If the user specified a required address mode, assign that |
| 1440 | * address mode |
| 1441 | */ |
| 1442 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1443 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1444 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1445 | FCFCNCT_AM_SPMA) ? |
| 1446 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1447 | /* |
| 1448 | * If the user specified a prefered address mode, use the |
| 1449 | * addr mode only if FCF support the addr_mode. |
| 1450 | */ |
| 1451 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1452 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1453 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1454 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1455 | *addr_mode = LPFC_FCF_SPMA; |
| 1456 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1457 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1458 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1459 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1460 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1461 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1462 | /* If matching connect list has a vlan id, use it */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1463 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1464 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1465 | /* |
| 1466 | * If no vlan id is specified in connect list, use the vlan id |
| 1467 | * in the FCF record |
| 1468 | */ |
| 1469 | else if (fcf_vlan_id) |
| 1470 | *vlan_id = fcf_vlan_id; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1471 | else |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1472 | *vlan_id = LPFC_FCOE_NULL_VID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1473 | |
| 1474 | return 1; |
| 1475 | } |
| 1476 | |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1481 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1482 | * @phba: pointer to lpfc hba data structure. |
| 1483 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1484 | * |
| 1485 | * This function check if there is any fcoe event pending while driver |
| 1486 | * scan FCF entries. If there is any pending event, it will restart the |
| 1487 | * FCF saning and return 1 else return 0. |
| 1488 | */ |
| 1489 | int |
| 1490 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1491 | { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1492 | /* |
| 1493 | * If the Link is up and no FCoE events while in the |
| 1494 | * FCF discovery, no need to restart FCF discovery. |
| 1495 | */ |
| 1496 | if ((phba->link_state >= LPFC_LINK_UP) && |
| 1497 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
| 1498 | return 0; |
| 1499 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1500 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1501 | "2768 Pending link or FCF event during current " |
| 1502 | "handling of the previous event: link_state:x%x, " |
| 1503 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", |
| 1504 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, |
| 1505 | phba->fcoe_eventtag); |
| 1506 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1507 | spin_lock_irq(&phba->hbalock); |
| 1508 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1509 | spin_unlock_irq(&phba->hbalock); |
| 1510 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1511 | if (phba->link_state >= LPFC_LINK_UP) { |
| 1512 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1513 | "2780 Restart FCF table scan due to " |
| 1514 | "pending FCF event:evt_tag_at_scan:x%x, " |
| 1515 | "evt_tag_current:x%x\n", |
| 1516 | phba->fcoe_eventtag_at_fcf_scan, |
| 1517 | phba->fcoe_eventtag); |
| 1518 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1519 | } else { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1520 | /* |
| 1521 | * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS |
| 1522 | * flag |
| 1523 | */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1524 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 1525 | "2833 Stop FCF discovery process due to link " |
| 1526 | "state change (x%x)\n", phba->link_state); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1527 | spin_lock_irq(&phba->hbalock); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 1528 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1529 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 1530 | spin_unlock_irq(&phba->hbalock); |
| 1531 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1532 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1533 | /* Unregister the currently registered FCF if required */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1534 | if (unreg_fcf) { |
| 1535 | spin_lock_irq(&phba->hbalock); |
| 1536 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1537 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1538 | lpfc_sli4_unregister_fcf(phba); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1539 | } |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1540 | return 1; |
| 1541 | } |
| 1542 | |
| 1543 | /** |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1544 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
| 1545 | * @phba: pointer to lpfc hba data structure. |
| 1546 | * @fcf_cnt: number of eligible fcf record seen so far. |
| 1547 | * |
| 1548 | * This function makes an running random selection decision on FCF record to |
| 1549 | * use through a sequence of @fcf_cnt eligible FCF records with equal |
| 1550 | * probability. To perform integer manunipulation of random numbers with |
| 1551 | * size unit32_t, the lower 16 bits of the 32-bit random number returned |
| 1552 | * from random32() are taken as the random random number generated. |
| 1553 | * |
| 1554 | * Returns true when outcome is for the newly read FCF record should be |
| 1555 | * chosen; otherwise, return false when outcome is for keeping the previously |
| 1556 | * chosen FCF record. |
| 1557 | **/ |
| 1558 | static bool |
| 1559 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) |
| 1560 | { |
| 1561 | uint32_t rand_num; |
| 1562 | |
| 1563 | /* Get 16-bit uniform random number */ |
| 1564 | rand_num = (0xFFFF & random32()); |
| 1565 | |
| 1566 | /* Decision with probability 1/fcf_cnt */ |
| 1567 | if ((fcf_cnt * rand_num) < 0xFFFF) |
| 1568 | return true; |
| 1569 | else |
| 1570 | return false; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1575 | * @phba: pointer to lpfc hba data structure. |
| 1576 | * @mboxq: pointer to mailbox object. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1577 | * @next_fcf_index: pointer to holder of next fcf index. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1578 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1579 | * This routine parses the non-embedded fcf mailbox command by performing the |
| 1580 | * necessarily error checking, non-embedded read FCF record mailbox command |
| 1581 | * SGE parsing, and endianness swapping. |
| 1582 | * |
| 1583 | * Returns the pointer to the new FCF record in the non-embedded mailbox |
| 1584 | * command DMA memory if successfully, other NULL. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1585 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1586 | static struct fcf_record * |
| 1587 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 1588 | uint16_t *next_fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1589 | { |
| 1590 | void *virt_addr; |
| 1591 | dma_addr_t phys_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1592 | struct lpfc_mbx_sge sge; |
| 1593 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1594 | uint32_t shdr_status, shdr_add_status; |
| 1595 | union lpfc_sli4_cfg_shdr *shdr; |
| 1596 | struct fcf_record *new_fcf_record; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 1597 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1598 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1599 | * routine only uses a single SGE. |
| 1600 | */ |
| 1601 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1602 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1603 | if (unlikely(!mboxq->sge_array)) { |
| 1604 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1605 | "2524 Failed to get the non-embedded SGE " |
| 1606 | "virtual address\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1607 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1608 | } |
| 1609 | virt_addr = mboxq->sge_array->addr[0]; |
| 1610 | |
| 1611 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
| 1612 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1613 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1614 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1615 | if (shdr_status == STATUS_FCF_TABLE_EMPTY) |
| 1616 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1617 | "2726 READ_FCF_RECORD Indicates empty " |
| 1618 | "FCF table.\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1619 | else |
| 1620 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1621 | "2521 READ_FCF_RECORD mailbox failed " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1622 | "with status x%x add_status x%x, " |
| 1623 | "mbx\n", shdr_status, shdr_add_status); |
| 1624 | return NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1625 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1626 | |
| 1627 | /* Interpreting the returned information of the FCF record */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1628 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1629 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1630 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1631 | *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] | 1632 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1633 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1634 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 1635 | offsetof(struct fcf_record, vlan_bitmap)); |
| 1636 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); |
| 1637 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1638 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1639 | return new_fcf_record; |
| 1640 | } |
| 1641 | |
| 1642 | /** |
| 1643 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1644 | * @phba: pointer to lpfc hba data structure. |
| 1645 | * @fcf_record: pointer to the fcf record. |
| 1646 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1647 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1648 | * |
| 1649 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1650 | * enabled. |
| 1651 | **/ |
| 1652 | static void |
| 1653 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1654 | struct fcf_record *fcf_record, |
| 1655 | uint16_t vlan_id, |
| 1656 | uint16_t next_fcf_index) |
| 1657 | { |
| 1658 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1659 | "2764 READ_FCF_RECORD:\n" |
| 1660 | "\tFCF_Index : x%x\n" |
| 1661 | "\tFCF_Avail : x%x\n" |
| 1662 | "\tFCF_Valid : x%x\n" |
| 1663 | "\tFIP_Priority : x%x\n" |
| 1664 | "\tMAC_Provider : x%x\n" |
| 1665 | "\tLowest VLANID : x%x\n" |
| 1666 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1667 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1668 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1669 | "\tNext_FCF_Index: x%x\n", |
| 1670 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1671 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1672 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
| 1673 | fcf_record->fip_priority, |
| 1674 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1675 | vlan_id, |
| 1676 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1677 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1678 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1679 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1680 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1681 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1682 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1683 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1684 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1685 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1686 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1687 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1688 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1689 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1690 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1691 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1692 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1693 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1694 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1695 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1696 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1697 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1698 | next_fcf_index); |
| 1699 | } |
| 1700 | |
| 1701 | /** |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1702 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF |
| 1703 | * @phba: pointer to lpfc hba data structure. |
| 1704 | * @fcf_rec: pointer to an existing FCF record. |
| 1705 | * @new_fcf_record: pointer to a new FCF record. |
| 1706 | * @new_vlan_id: vlan id from the new FCF record. |
| 1707 | * |
| 1708 | * This function performs matching test of a new FCF record against an existing |
| 1709 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id |
| 1710 | * will not be used as part of the FCF record matching criteria. |
| 1711 | * |
| 1712 | * Returns true if all the fields matching, otherwise returns false. |
| 1713 | */ |
| 1714 | static bool |
| 1715 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, |
| 1716 | struct lpfc_fcf_rec *fcf_rec, |
| 1717 | struct fcf_record *new_fcf_record, |
| 1718 | uint16_t new_vlan_id) |
| 1719 | { |
| 1720 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) |
| 1721 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) |
| 1722 | return false; |
| 1723 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) |
| 1724 | return false; |
| 1725 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) |
| 1726 | return false; |
| 1727 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) |
| 1728 | return false; |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
| 1732 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1733 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 1734 | * @phba: pointer to lpfc hba data structure. |
| 1735 | * @mboxq: pointer to mailbox object. |
| 1736 | * |
| 1737 | * This function iterates through all the fcf records available in |
| 1738 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 1739 | * the FCF for discovery it registers the FCF record and kicks start |
| 1740 | * discovery. |
| 1741 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 1742 | * use an FCF record which matches fabric name and mac address of the |
| 1743 | * currently used FCF record. |
| 1744 | * If the driver supports only one FCF, it will try to use the FCF record |
| 1745 | * used by BOOT_BIOS. |
| 1746 | */ |
| 1747 | void |
| 1748 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1749 | { |
| 1750 | struct fcf_record *new_fcf_record; |
| 1751 | uint32_t boot_flag, addr_mode; |
| 1752 | uint16_t fcf_index, next_fcf_index; |
| 1753 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 1754 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1755 | uint32_t seed; |
| 1756 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1757 | int rc; |
| 1758 | |
| 1759 | /* If there is pending FCoE event restart FCF table scan */ |
| 1760 | if (lpfc_check_pending_fcoe_event(phba, 0)) { |
| 1761 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1762 | return; |
| 1763 | } |
| 1764 | |
| 1765 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 1766 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 1767 | &next_fcf_index); |
| 1768 | if (!new_fcf_record) { |
| 1769 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1770 | "2765 Mailbox command READ_FCF_RECORD " |
| 1771 | "failed to retrieve a FCF record.\n"); |
| 1772 | /* Let next new FCF event trigger fast failover */ |
| 1773 | spin_lock_irq(&phba->hbalock); |
| 1774 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
| 1775 | spin_unlock_irq(&phba->hbalock); |
| 1776 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1777 | return; |
| 1778 | } |
| 1779 | |
| 1780 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1781 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 1782 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1783 | |
| 1784 | /* Log the FCF record information if turned on */ |
| 1785 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 1786 | next_fcf_index); |
| 1787 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1788 | /* |
| 1789 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1790 | * read the next entry; otherwise, this is an eligible FCF |
| 1791 | * record for round robin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1792 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1793 | if (!rc) { |
| 1794 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1795 | "2781 FCF record (x%x) failed FCF " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1796 | "connection list check, fcf_avail:x%x, " |
| 1797 | "fcf_valid:x%x\n", |
| 1798 | bf_get(lpfc_fcf_record_fcf_index, |
| 1799 | new_fcf_record), |
| 1800 | bf_get(lpfc_fcf_record_fcf_avail, |
| 1801 | new_fcf_record), |
| 1802 | bf_get(lpfc_fcf_record_fcf_valid, |
| 1803 | new_fcf_record)); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1804 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
| 1805 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 1806 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { |
| 1807 | /* |
| 1808 | * In case the current in-use FCF record becomes |
| 1809 | * invalid/unavailable during FCF discovery that |
| 1810 | * was not triggered by fast FCF failover process, |
| 1811 | * treat it as fast FCF failover. |
| 1812 | */ |
| 1813 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && |
| 1814 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
| 1815 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1816 | "2835 Invalid in-use FCF " |
| 1817 | "record (x%x) reported, " |
| 1818 | "entering fast FCF failover " |
| 1819 | "mode scanning.\n", |
| 1820 | phba->fcf.current_rec.fcf_indx); |
| 1821 | spin_lock_irq(&phba->hbalock); |
| 1822 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 1823 | spin_unlock_irq(&phba->hbalock); |
| 1824 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1825 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 1826 | LPFC_FCOE_FCF_GET_FIRST); |
| 1827 | return; |
| 1828 | } |
| 1829 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1830 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1831 | } else { |
| 1832 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1833 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 1834 | if (rc) |
| 1835 | goto read_next_fcf; |
| 1836 | } |
| 1837 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1838 | /* |
| 1839 | * 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] | 1840 | * FCF record for the discovery. The condition that a rescan |
| 1841 | * matches the in-use FCF record: fabric name, switch name, mac |
| 1842 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1843 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1844 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1845 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1846 | if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, |
| 1847 | new_fcf_record, vlan_id)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1848 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1849 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 1850 | /* Stop FCF redisc wait timer if pending */ |
| 1851 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
| 1852 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1853 | /* If in fast failover, mark it's completed */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1854 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1855 | FCF_DISCOVERY); |
| 1856 | spin_unlock_irq(&phba->hbalock); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1857 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1858 | "2836 The new FCF record (x%x) " |
| 1859 | "matches the in-use FCF record " |
| 1860 | "(x%x)\n", |
| 1861 | phba->fcf.current_rec.fcf_indx, |
| 1862 | bf_get(lpfc_fcf_record_fcf_index, |
| 1863 | new_fcf_record)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1864 | goto out; |
| 1865 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1866 | /* |
| 1867 | * Read next FCF record from HBA searching for the matching |
| 1868 | * with in-use record only if not during the fast failover |
| 1869 | * period. In case of fast failover period, it shall try to |
| 1870 | * determine whether the FCF record just read should be the |
| 1871 | * next candidate. |
| 1872 | */ |
| 1873 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1874 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1875 | goto read_next_fcf; |
| 1876 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1877 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1878 | /* |
| 1879 | * Update on failover FCF record only if it's in FCF fast-failover |
| 1880 | * period; otherwise, update on current FCF record. |
| 1881 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1882 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1883 | fcf_rec = &phba->fcf.failover_rec; |
| 1884 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1885 | fcf_rec = &phba->fcf.current_rec; |
| 1886 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1887 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 1888 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1889 | * If the driver FCF record does not have boot flag |
| 1890 | * set and new hba fcf record has boot flag set, use |
| 1891 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1892 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1893 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 1894 | /* Choose this FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1895 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1896 | "2837 Update current FCF record " |
| 1897 | "(x%x) with new FCF record (x%x)\n", |
| 1898 | fcf_rec->fcf_indx, |
| 1899 | bf_get(lpfc_fcf_record_fcf_index, |
| 1900 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1901 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1902 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1903 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1904 | goto read_next_fcf; |
| 1905 | } |
| 1906 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1907 | * If the driver FCF record has boot flag set and the |
| 1908 | * new hba FCF record does not have boot flag, read |
| 1909 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1910 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1911 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1912 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1913 | goto read_next_fcf; |
| 1914 | } |
| 1915 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1916 | * If the new hba FCF record has lower priority value |
| 1917 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1918 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1919 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1920 | /* Choose the new FCF record with lower priority */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1921 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1922 | "2838 Update current FCF record " |
| 1923 | "(x%x) with new FCF record (x%x)\n", |
| 1924 | fcf_rec->fcf_indx, |
| 1925 | bf_get(lpfc_fcf_record_fcf_index, |
| 1926 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1927 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1928 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1929 | /* Reset running random FCF selection count */ |
| 1930 | phba->fcf.eligible_fcf_cnt = 1; |
| 1931 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 1932 | /* Update running random FCF selection count */ |
| 1933 | phba->fcf.eligible_fcf_cnt++; |
| 1934 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 1935 | phba->fcf.eligible_fcf_cnt); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1936 | if (select_new_fcf) { |
| 1937 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1938 | "2839 Update current FCF record " |
| 1939 | "(x%x) with new FCF record (x%x)\n", |
| 1940 | fcf_rec->fcf_indx, |
| 1941 | bf_get(lpfc_fcf_record_fcf_index, |
| 1942 | new_fcf_record)); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1943 | /* Choose the new FCF by random selection */ |
| 1944 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 1945 | new_fcf_record, |
| 1946 | addr_mode, vlan_id, 0); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1947 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1948 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1949 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1950 | goto read_next_fcf; |
| 1951 | } |
| 1952 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1953 | * This is the first suitable FCF record, choose this record for |
| 1954 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1955 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1956 | if (fcf_rec) { |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1957 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1958 | "2840 Update current FCF record " |
| 1959 | "with initial FCF record (x%x)\n", |
| 1960 | bf_get(lpfc_fcf_record_fcf_index, |
| 1961 | new_fcf_record)); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1962 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1963 | addr_mode, vlan_id, (boot_flag ? |
| 1964 | BOOT_ENABLE : 0)); |
| 1965 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1966 | /* Setup initial running random FCF selection count */ |
| 1967 | phba->fcf.eligible_fcf_cnt = 1; |
| 1968 | /* Seeding the random number generator for random selection */ |
| 1969 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
| 1970 | srandom32(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1971 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1972 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1973 | goto read_next_fcf; |
| 1974 | |
| 1975 | read_next_fcf: |
| 1976 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1977 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 1978 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 1979 | /* |
| 1980 | * Case of FCF fast failover scan |
| 1981 | */ |
| 1982 | |
| 1983 | /* |
| 1984 | * It has not found any suitable FCF record, cancel |
| 1985 | * FCF scan inprogress, and do nothing |
| 1986 | */ |
| 1987 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1988 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1989 | "2782 No suitable FCF record " |
| 1990 | "found during this round of " |
| 1991 | "post FCF rediscovery scan: " |
| 1992 | "fcf_evt_tag:x%x, fcf_index: " |
| 1993 | "x%x\n", |
| 1994 | phba->fcoe_eventtag_at_fcf_scan, |
| 1995 | bf_get(lpfc_fcf_record_fcf_index, |
| 1996 | new_fcf_record)); |
| 1997 | /* |
| 1998 | * Let next new FCF event trigger fast |
| 1999 | * failover |
| 2000 | */ |
| 2001 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2002 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2003 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2004 | return; |
| 2005 | } |
| 2006 | /* |
| 2007 | * It has found a suitable FCF record that is not |
| 2008 | * the same as in-use FCF record, unregister the |
| 2009 | * in-use FCF record, replace the in-use FCF record |
| 2010 | * with the new FCF record, mark FCF fast failover |
| 2011 | * completed, and then start register the new FCF |
| 2012 | * record. |
| 2013 | */ |
| 2014 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2015 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2016 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2017 | |
| 2018 | /* Replace in-use record with the new record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2019 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2020 | "2842 Replace the current in-use " |
| 2021 | "FCF record (x%x) with failover FCF " |
| 2022 | "record (x%x)\n", |
| 2023 | phba->fcf.current_rec.fcf_indx, |
| 2024 | phba->fcf.failover_rec.fcf_indx); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2025 | memcpy(&phba->fcf.current_rec, |
| 2026 | &phba->fcf.failover_rec, |
| 2027 | sizeof(struct lpfc_fcf_rec)); |
| 2028 | /* mark the FCF fast failover completed */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2029 | spin_lock_irq(&phba->hbalock); |
| 2030 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 2031 | spin_unlock_irq(&phba->hbalock); |
| 2032 | /* |
| 2033 | * Set up the initial registered FCF index for FLOGI |
| 2034 | * round robin FCF failover. |
| 2035 | */ |
| 2036 | phba->fcf.fcf_rr_init_indx = |
| 2037 | phba->fcf.failover_rec.fcf_indx; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2038 | /* Register to the new FCF record */ |
| 2039 | lpfc_register_fcf(phba); |
| 2040 | } else { |
| 2041 | /* |
| 2042 | * In case of transaction period to fast FCF failover, |
| 2043 | * do nothing when search to the end of the FCF table. |
| 2044 | */ |
| 2045 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 2046 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 2047 | return; |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2048 | |
| 2049 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
| 2050 | /* |
| 2051 | * In case the current in-use FCF record no |
| 2052 | * longer existed during FCF discovery that |
| 2053 | * was not triggered by fast FCF failover |
| 2054 | * process, treat it as fast FCF failover. |
| 2055 | */ |
| 2056 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2057 | "2841 In-use FCF record (x%x) " |
| 2058 | "not reported, entering fast " |
| 2059 | "FCF failover mode scanning.\n", |
| 2060 | phba->fcf.current_rec.fcf_indx); |
| 2061 | spin_lock_irq(&phba->hbalock); |
| 2062 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 2063 | spin_unlock_irq(&phba->hbalock); |
| 2064 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2065 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2066 | LPFC_FCOE_FCF_GET_FIRST); |
| 2067 | return; |
| 2068 | } |
| 2069 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2070 | /* |
| 2071 | * Otherwise, initial scan or post linkdown rescan, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2072 | * register with the best FCF record found so far |
| 2073 | * through the FCF scanning process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2074 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2075 | |
| 2076 | /* mark the initial FCF discovery completed */ |
| 2077 | spin_lock_irq(&phba->hbalock); |
| 2078 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 2079 | spin_unlock_irq(&phba->hbalock); |
| 2080 | /* |
| 2081 | * Set up the initial registered FCF index for FLOGI |
| 2082 | * round robin FCF failover |
| 2083 | */ |
| 2084 | phba->fcf.fcf_rr_init_indx = |
| 2085 | phba->fcf.current_rec.fcf_indx; |
| 2086 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2087 | lpfc_register_fcf(phba); |
| 2088 | } |
| 2089 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2090 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2091 | return; |
| 2092 | |
| 2093 | out: |
| 2094 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2095 | lpfc_register_fcf(phba); |
| 2096 | |
| 2097 | return; |
| 2098 | } |
| 2099 | |
| 2100 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2101 | * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler |
| 2102 | * @phba: pointer to lpfc hba data structure. |
| 2103 | * @mboxq: pointer to mailbox object. |
| 2104 | * |
| 2105 | * This is the callback function for FLOGI failure round robin FCF failover |
| 2106 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 2107 | * performing the failover. If the FCF read back is not valid/available, it |
| 2108 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 2109 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 2110 | * newly read FCF record to the failover FCF record, unregister currently |
| 2111 | * registered FCF record, copy the failover FCF record to the current |
| 2112 | * FCF record, and then register the current FCF record before proceeding |
| 2113 | * to trying FLOGI on the new failover FCF. |
| 2114 | */ |
| 2115 | void |
| 2116 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2117 | { |
| 2118 | struct fcf_record *new_fcf_record; |
| 2119 | uint32_t boot_flag, addr_mode; |
| 2120 | uint16_t next_fcf_index; |
| 2121 | uint16_t current_fcf_index; |
| 2122 | uint16_t vlan_id; |
| 2123 | |
| 2124 | /* If link state is not up, stop the round robin failover process */ |
| 2125 | if (phba->link_state < LPFC_LINK_UP) { |
| 2126 | spin_lock_irq(&phba->hbalock); |
| 2127 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 2128 | spin_unlock_irq(&phba->hbalock); |
| 2129 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
| 2133 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2134 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2135 | &next_fcf_index); |
| 2136 | if (!new_fcf_record) { |
| 2137 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2138 | "2766 Mailbox command READ_FCF_RECORD " |
| 2139 | "failed to retrieve a FCF record.\n"); |
| 2140 | goto out; |
| 2141 | } |
| 2142 | |
| 2143 | /* Get the needed parameters from FCF record */ |
| 2144 | lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2145 | &addr_mode, &vlan_id); |
| 2146 | |
| 2147 | /* Log the FCF record information if turned on */ |
| 2148 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2149 | next_fcf_index); |
| 2150 | |
| 2151 | /* Upload new FCF record to the failover FCF record */ |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2152 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2153 | "2834 Update the current FCF record (x%x) " |
| 2154 | "with the next FCF record (x%x)\n", |
| 2155 | phba->fcf.failover_rec.fcf_indx, |
| 2156 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record)); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2157 | spin_lock_irq(&phba->hbalock); |
| 2158 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2159 | new_fcf_record, addr_mode, vlan_id, |
| 2160 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2161 | spin_unlock_irq(&phba->hbalock); |
| 2162 | |
| 2163 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2164 | |
| 2165 | /* Unregister the current in-use FCF record */ |
| 2166 | lpfc_unregister_fcf(phba); |
| 2167 | |
| 2168 | /* Replace in-use record with the new record */ |
| 2169 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2170 | sizeof(struct lpfc_fcf_rec)); |
| 2171 | |
| 2172 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2173 | "2783 FLOGI round robin FCF failover from FCF " |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 2174 | "(x%x) to FCF (x%x).\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2175 | current_fcf_index, |
| 2176 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record)); |
| 2177 | |
| 2178 | out: |
| 2179 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2180 | lpfc_register_fcf(phba); |
| 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2185 | * @phba: pointer to lpfc hba data structure. |
| 2186 | * @mboxq: pointer to mailbox object. |
| 2187 | * |
| 2188 | * This is the callback function of read FCF record mailbox command for |
| 2189 | * updating the eligible FCF bmask for FLOGI failure round robin FCF |
| 2190 | * failover when a new FCF event happened. If the FCF read back is |
| 2191 | * valid/available and it passes the connection list check, it updates |
| 2192 | * the bmask for the eligible FCF record for round robin failover. |
| 2193 | */ |
| 2194 | void |
| 2195 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2196 | { |
| 2197 | struct fcf_record *new_fcf_record; |
| 2198 | uint32_t boot_flag, addr_mode; |
| 2199 | uint16_t fcf_index, next_fcf_index; |
| 2200 | uint16_t vlan_id; |
| 2201 | int rc; |
| 2202 | |
| 2203 | /* If link state is not up, no need to proceed */ |
| 2204 | if (phba->link_state < LPFC_LINK_UP) |
| 2205 | goto out; |
| 2206 | |
| 2207 | /* If FCF discovery period is over, no need to proceed */ |
| 2208 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) |
| 2209 | goto out; |
| 2210 | |
| 2211 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2212 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2213 | &next_fcf_index); |
| 2214 | if (!new_fcf_record) { |
| 2215 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2216 | "2767 Mailbox command READ_FCF_RECORD " |
| 2217 | "failed to retrieve a FCF record.\n"); |
| 2218 | goto out; |
| 2219 | } |
| 2220 | |
| 2221 | /* Check the connection list for eligibility */ |
| 2222 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2223 | &addr_mode, &vlan_id); |
| 2224 | |
| 2225 | /* Log the FCF record information if turned on */ |
| 2226 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2227 | next_fcf_index); |
| 2228 | |
| 2229 | if (!rc) |
| 2230 | goto out; |
| 2231 | |
| 2232 | /* Update the eligible FCF record index bmask */ |
| 2233 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2234 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 2235 | |
| 2236 | out: |
| 2237 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2241 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2242 | * @phba: pointer to lpfc hba data structure. |
| 2243 | * @mboxq: pointer to mailbox data structure. |
| 2244 | * |
| 2245 | * This function handles completion of init vpi mailbox command. |
| 2246 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2247 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2248 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2249 | { |
| 2250 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2251 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2252 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2253 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2254 | if (mboxq->u.mb.mbxStatus) { |
| 2255 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2256 | LOG_MBOX, |
| 2257 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2258 | mboxq->u.mb.mbxStatus); |
| 2259 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2260 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2261 | return; |
| 2262 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2263 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2264 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2265 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2266 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2267 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2268 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2269 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2270 | if (!ndlp) |
| 2271 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2272 | LOG_DISCOVERY, |
| 2273 | "2731 Cannot find fabric " |
| 2274 | "controller node\n"); |
| 2275 | else |
| 2276 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2277 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2278 | return; |
| 2279 | } |
| 2280 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2281 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2282 | lpfc_initial_fdisc(vport); |
| 2283 | else { |
| 2284 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2285 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2286 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2287 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2288 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2289 | return; |
| 2290 | } |
| 2291 | |
| 2292 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2293 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2294 | * @vport: pointer to lpfc_vport data structure. |
| 2295 | * |
| 2296 | * This function issue a init_vpi mailbox command to initialize |
| 2297 | * VPI for the vport. |
| 2298 | */ |
| 2299 | void |
| 2300 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2301 | { |
| 2302 | LPFC_MBOXQ_t *mboxq; |
| 2303 | int rc; |
| 2304 | |
| 2305 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2306 | if (!mboxq) { |
| 2307 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2308 | LOG_MBOX, "2607 Failed to allocate " |
| 2309 | "init_vpi mailbox\n"); |
| 2310 | return; |
| 2311 | } |
| 2312 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2313 | mboxq->vport = vport; |
| 2314 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2315 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2316 | if (rc == MBX_NOT_FINISHED) { |
| 2317 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2318 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2319 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2324 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2325 | * @phba: pointer to lpfc hba data structure. |
| 2326 | * |
| 2327 | * This function loops through the list of vports on the @phba and issues an |
| 2328 | * FDISC if possible. |
| 2329 | */ |
| 2330 | void |
| 2331 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2332 | { |
| 2333 | struct lpfc_vport **vports; |
| 2334 | int i; |
| 2335 | |
| 2336 | vports = lpfc_create_vport_work_array(phba); |
| 2337 | if (vports != NULL) { |
| 2338 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2339 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2340 | continue; |
| 2341 | /* There are no vpi for this vport */ |
| 2342 | if (vports[i]->vpi > phba->max_vpi) { |
| 2343 | lpfc_vport_set_state(vports[i], |
| 2344 | FC_VPORT_FAILED); |
| 2345 | continue; |
| 2346 | } |
| 2347 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2348 | lpfc_vport_set_state(vports[i], |
| 2349 | FC_VPORT_LINKDOWN); |
| 2350 | continue; |
| 2351 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2352 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2353 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2354 | continue; |
| 2355 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2356 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2357 | lpfc_initial_fdisc(vports[i]); |
| 2358 | else { |
| 2359 | lpfc_vport_set_state(vports[i], |
| 2360 | FC_VPORT_NO_FABRIC_SUPP); |
| 2361 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2362 | LOG_ELS, |
| 2363 | "0259 No NPIV " |
| 2364 | "Fabric support\n"); |
| 2365 | } |
| 2366 | } |
| 2367 | } |
| 2368 | lpfc_destroy_vport_work_array(phba, vports); |
| 2369 | } |
| 2370 | |
| 2371 | void |
| 2372 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2373 | { |
| 2374 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2375 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2376 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2377 | |
| 2378 | if (mboxq->u.mb.mbxStatus) { |
| 2379 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2380 | "2018 REG_VFI mbxStatus error x%x " |
| 2381 | "HBA state x%x\n", |
| 2382 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 2383 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2384 | /* FLOGI failed, use loop map to make discovery list */ |
| 2385 | lpfc_disc_list_loopmap(vport); |
| 2386 | /* Start discovery */ |
| 2387 | lpfc_disc_start(vport); |
| 2388 | goto fail_free_mem; |
| 2389 | } |
| 2390 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2391 | goto fail_free_mem; |
| 2392 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2393 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2394 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2395 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2396 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2397 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2398 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2399 | |
| 2400 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
| 2401 | lpfc_start_fdiscs(phba); |
| 2402 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2403 | } |
| 2404 | |
| 2405 | fail_free_mem: |
| 2406 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2407 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2408 | kfree(dmabuf); |
| 2409 | return; |
| 2410 | } |
| 2411 | |
| 2412 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2413 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2415 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | |
| 2419 | |
| 2420 | /* Check for error */ |
| 2421 | if (mb->mbxStatus) { |
| 2422 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2423 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2424 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2425 | "hba state x%x>\n", |
| 2426 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | goto out; |
| 2429 | } |
| 2430 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2432 | sizeof (struct serv_parm)); |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 2433 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 2435 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 2436 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 2438 | vport->fc_sparam.portName.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2439 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 2440 | sizeof(vport->fc_nodename)); |
| 2441 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 2442 | sizeof(vport->fc_portname)); |
| 2443 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2444 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2445 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2446 | } |
| 2447 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2449 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2450 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | return; |
| 2452 | |
| 2453 | out: |
| 2454 | pmb->context1 = NULL; |
| 2455 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2456 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2457 | lpfc_issue_clear_la(phba, vport); |
| 2458 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | return; |
| 2460 | } |
| 2461 | |
| 2462 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2463 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2465 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2466 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2468 | struct lpfc_dmabuf *mp; |
| 2469 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2470 | struct fcf_record *fcf_record; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2471 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2472 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2473 | switch (la->UlnkSpeed) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2474 | case LA_1GHZ_LINK: |
| 2475 | phba->fc_linkspeed = LA_1GHZ_LINK; |
| 2476 | break; |
| 2477 | case LA_2GHZ_LINK: |
| 2478 | phba->fc_linkspeed = LA_2GHZ_LINK; |
| 2479 | break; |
| 2480 | case LA_4GHZ_LINK: |
| 2481 | phba->fc_linkspeed = LA_4GHZ_LINK; |
| 2482 | break; |
| 2483 | case LA_8GHZ_LINK: |
| 2484 | phba->fc_linkspeed = LA_8GHZ_LINK; |
| 2485 | break; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2486 | case LA_10GHZ_LINK: |
| 2487 | phba->fc_linkspeed = LA_10GHZ_LINK; |
| 2488 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2489 | default: |
| 2490 | phba->fc_linkspeed = LA_UNKNW_LINK; |
| 2491 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | phba->fc_topology = la->topology; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2495 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | |
| 2497 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2498 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2500 | /* if npiv is enabled and this adapter supports npiv log |
| 2501 | * a message that npiv is not supported in this topology |
| 2502 | */ |
| 2503 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2504 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2505 | "1309 Link Up Event npiv not supported in loop " |
| 2506 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2507 | /* Get Loop Map information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | if (la->il) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2509 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2511 | vport->fc_myDID = la->granted_AL_PA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | i = la->un.lilpBde64.tus.f.bdeSize; |
| 2513 | |
| 2514 | if (i == 0) { |
| 2515 | phba->alpa_map[0] = 0; |
| 2516 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2517 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | int numalpa, j, k; |
| 2519 | union { |
| 2520 | uint8_t pamap[16]; |
| 2521 | struct { |
| 2522 | uint32_t wd1; |
| 2523 | uint32_t wd2; |
| 2524 | uint32_t wd3; |
| 2525 | uint32_t wd4; |
| 2526 | } pa; |
| 2527 | } un; |
| 2528 | numalpa = phba->alpa_map[0]; |
| 2529 | j = 0; |
| 2530 | while (j < numalpa) { |
| 2531 | memset(un.pamap, 0, 16); |
| 2532 | for (k = 1; j < numalpa; k++) { |
| 2533 | un.pamap[k - 1] = |
| 2534 | phba->alpa_map[j + 1]; |
| 2535 | j++; |
| 2536 | if (k == 16) |
| 2537 | break; |
| 2538 | } |
| 2539 | /* Link Up Event ALPA map */ |
| 2540 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2541 | KERN_WARNING, |
| 2542 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2543 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2544 | "ALPA map Data: x%x " |
| 2545 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2546 | un.pa.wd1, un.pa.wd2, |
| 2547 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | } |
| 2551 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2553 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2554 | (phba->sli_rev == 3)) |
| 2555 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 2556 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | vport->fc_myDID = phba->fc_pref_DID; |
| 2558 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2560 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | |
| 2562 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 2563 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2564 | if (!sparam_mbox) |
| 2565 | goto out; |
| 2566 | |
| 2567 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 2568 | if (rc) { |
| 2569 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2570 | goto out; |
| 2571 | } |
| 2572 | sparam_mbox->vport = vport; |
| 2573 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 2574 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 2575 | if (rc == MBX_NOT_FINISHED) { |
| 2576 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 2577 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2578 | kfree(mp); |
| 2579 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2580 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | } |
| 2582 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2583 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) { |
| 2584 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2585 | if (!cfglink_mbox) |
| 2586 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 2590 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2591 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2592 | if (rc == MBX_NOT_FINISHED) { |
| 2593 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 2594 | goto out; |
| 2595 | } |
| 2596 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2597 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2598 | /* |
| 2599 | * Add the driver's default FCF record at FCF index 0 now. This |
| 2600 | * is phase 1 implementation that support FCF index 0 and driver |
| 2601 | * defaults. |
| 2602 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2603 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2604 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 2605 | GFP_KERNEL); |
| 2606 | if (unlikely(!fcf_record)) { |
| 2607 | lpfc_printf_log(phba, KERN_ERR, |
| 2608 | LOG_MBOX | LOG_SLI, |
| 2609 | "2554 Could not allocate memmory for " |
| 2610 | "fcf record\n"); |
| 2611 | rc = -ENODEV; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | |
| 2615 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 2616 | LPFC_FCOE_FCF_DEF_INDEX); |
| 2617 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 2618 | if (unlikely(rc)) { |
| 2619 | lpfc_printf_log(phba, KERN_ERR, |
| 2620 | LOG_MBOX | LOG_SLI, |
| 2621 | "2013 Could not manually add FCF " |
| 2622 | "record 0, status %d\n", rc); |
| 2623 | rc = -ENODEV; |
| 2624 | kfree(fcf_record); |
| 2625 | goto out; |
| 2626 | } |
| 2627 | kfree(fcf_record); |
| 2628 | } |
| 2629 | /* |
| 2630 | * The driver is expected to do FIP/FCF. Call the port |
| 2631 | * and get the FCF Table. |
| 2632 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2633 | spin_lock_irq(&phba->hbalock); |
| 2634 | if (phba->hba_flag & FCF_DISC_INPROGRESS) { |
| 2635 | spin_unlock_irq(&phba->hbalock); |
| 2636 | return; |
| 2637 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2638 | /* This is the initial FCF discovery scan */ |
| 2639 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2640 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2641 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 2642 | "2778 Start FCF table scan at linkup\n"); |
| 2643 | |
| 2644 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2645 | LPFC_FCOE_FCF_GET_FIRST); |
| 2646 | if (rc) { |
| 2647 | spin_lock_irq(&phba->hbalock); |
| 2648 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 2649 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2650 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2651 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2653 | |
| 2654 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2655 | out: |
| 2656 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2657 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2658 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 2659 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | lpfc_issue_clear_la(phba, vport); |
| 2661 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2665 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | uint32_t control; |
| 2668 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2671 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 2672 | control = readl(phba->HCregaddr); |
| 2673 | control |= HC_LAINT_ENA; |
| 2674 | writel(control, phba->HCregaddr); |
| 2675 | readl(phba->HCregaddr); /* flush */ |
| 2676 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | } |
| 2679 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2680 | static void |
| 2681 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 2682 | { |
| 2683 | lpfc_linkdown(phba); |
| 2684 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2685 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2686 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 2687 | } |
| 2688 | |
| 2689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | /* |
| 2691 | * This routine handles processing a READ_LA mailbox |
| 2692 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2693 | * as the completion routine when the command is |
| 2694 | * handed off to the SLI layer. |
| 2695 | */ |
| 2696 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2699 | struct lpfc_vport *vport = pmb->vport; |
| 2700 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | READ_LA_VAR *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2702 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2704 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2705 | /* Unblock ELS traffic */ |
| 2706 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | /* Check for error */ |
| 2708 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2709 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2710 | "1307 READ_LA mbox error x%x state x%x\n", |
| 2711 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2713 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 2715 | } |
| 2716 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2717 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | |
| 2719 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 2720 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2721 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2722 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2723 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2724 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2725 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 2726 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2727 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 2728 | if ((phba->fc_eventTag < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2729 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | if (phba->fc_eventTag != 0) |
| 2733 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2734 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | |
| 2736 | phba->fc_eventTag = la->eventTag; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2737 | spin_lock_irq(&phba->hbalock); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2738 | if (la->mm) |
| 2739 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 2740 | else |
| 2741 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2742 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2744 | phba->link_events++; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2745 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2747 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2748 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2749 | "1306 Link Up Event in loop back mode " |
| 2750 | "x%x received Data: x%x x%x x%x x%x\n", |
| 2751 | la->eventTag, phba->fc_eventTag, |
| 2752 | la->granted_AL_PA, la->UlnkSpeed, |
| 2753 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2754 | } else { |
| 2755 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2756 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2757 | "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] | 2758 | la->eventTag, phba->fc_eventTag, |
| 2759 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2760 | phba->alpa_map[0], |
| 2761 | la->mm, la->fa, |
| 2762 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2763 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2764 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2765 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2767 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 2768 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2769 | "1308 Link Down Event in loop back mode " |
| 2770 | "x%x received " |
| 2771 | "Data: x%x x%x x%x\n", |
| 2772 | la->eventTag, phba->fc_eventTag, |
| 2773 | phba->pport->port_state, vport->fc_flag); |
| 2774 | } |
| 2775 | else { |
| 2776 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2777 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2778 | "Data: x%x x%x x%x x%x x%x\n", |
| 2779 | la->eventTag, phba->fc_eventTag, |
| 2780 | phba->pport->port_state, vport->fc_flag, |
| 2781 | la->mm, la->fa); |
| 2782 | } |
| 2783 | lpfc_mbx_issue_link_down(phba); |
| 2784 | } |
| 2785 | if (la->mm && la->attType == AT_LINK_UP) { |
| 2786 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 2787 | phba->fc_stat.LinkDown++; |
| 2788 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2789 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2791 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2792 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2793 | lpfc_mbx_issue_link_down(phba); |
| 2794 | } else |
| 2795 | lpfc_enable_la(phba); |
| 2796 | |
| 2797 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2798 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 2799 | "Data: x%x x%x x%x\n", |
| 2800 | la->eventTag, phba->fc_eventTag, |
| 2801 | phba->pport->port_state, vport->fc_flag); |
| 2802 | /* |
| 2803 | * The cmnd that triggered this will be waiting for this |
| 2804 | * signal. |
| 2805 | */ |
| 2806 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 2807 | if (phba->wait_4_mlo_maint_flg) { |
| 2808 | phba->wait_4_mlo_maint_flg = 0; |
| 2809 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2810 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | if (la->fa) { |
| 2814 | if (la->mm) |
| 2815 | lpfc_issue_clear_la(phba, vport); |
| 2816 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 2817 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 2821 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2822 | kfree(mp); |
| 2823 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2824 | return; |
| 2825 | } |
| 2826 | |
| 2827 | /* |
| 2828 | * This routine handles processing a REG_LOGIN mailbox |
| 2829 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2830 | * as the completion routine when the command is |
| 2831 | * handed off to the SLI layer. |
| 2832 | */ |
| 2833 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2834 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2836 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2837 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2838 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2839 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | pmb->context1 = NULL; |
| 2842 | |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2843 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
| 2844 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
| 2845 | |
| 2846 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
| 2847 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { |
| 2848 | /* We rcvd a rscn after issuing this |
| 2849 | * mbox reg login, we may have cycled |
| 2850 | * back through the state and be |
| 2851 | * back at reg login state so this |
| 2852 | * mbox needs to be ignored becase |
| 2853 | * there is another reg login in |
| 2854 | * proccess. |
| 2855 | */ |
| 2856 | spin_lock_irq(shost->host_lock); |
| 2857 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 2858 | spin_unlock_irq(shost->host_lock); |
| 2859 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2860 | lpfc_sli4_free_rpi(phba, |
| 2861 | pmb->u.mb.un.varRegLogin.rpi); |
| 2862 | |
| 2863 | } else |
| 2864 | /* Good status, call state machine */ |
| 2865 | lpfc_disc_state_machine(vport, ndlp, pmb, |
| 2866 | NLP_EVT_CMPL_REG_LOGIN); |
| 2867 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2869 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2870 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2871 | /* decrement the node reference count held for this callback |
| 2872 | * function. |
| 2873 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2874 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | |
| 2876 | return; |
| 2877 | } |
| 2878 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2879 | static void |
| 2880 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2881 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2882 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2883 | struct lpfc_vport *vport = pmb->vport; |
| 2884 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2885 | |
| 2886 | switch (mb->mbxStatus) { |
| 2887 | case 0x0011: |
| 2888 | case 0x0020: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2889 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2890 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 2891 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2892 | break; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 2893 | /* If VPI is busy, reset the HBA */ |
| 2894 | case 0x9700: |
| 2895 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 2896 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", |
| 2897 | vport->vpi, mb->mbxStatus); |
| 2898 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 2899 | lpfc_workq_post_event(phba, NULL, NULL, |
| 2900 | LPFC_EVT_RESET_HBA); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2901 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2902 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2903 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 2904 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2905 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2906 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 2907 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2908 | /* |
| 2909 | * This shost reference might have been taken at the beginning of |
| 2910 | * lpfc_vport_delete() |
| 2911 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2912 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2913 | scsi_host_put(shost); |
| 2914 | } |
| 2915 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2916 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2917 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 2918 | { |
| 2919 | struct lpfc_hba *phba = vport->phba; |
| 2920 | LPFC_MBOXQ_t *mbox; |
| 2921 | int rc; |
| 2922 | |
| 2923 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2924 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2925 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | |
| 2927 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 2928 | mbox->vport = vport; |
| 2929 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2930 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2931 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2932 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2933 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2934 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2935 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2936 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2937 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2938 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | static void |
| 2942 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2943 | { |
| 2944 | struct lpfc_vport *vport = pmb->vport; |
| 2945 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2946 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2947 | |
| 2948 | switch (mb->mbxStatus) { |
| 2949 | case 0x0011: |
| 2950 | case 0x9601: |
| 2951 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2952 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2953 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 2954 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2956 | spin_lock_irq(shost->host_lock); |
| 2957 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 2958 | spin_unlock_irq(shost->host_lock); |
| 2959 | vport->fc_myDID = 0; |
| 2960 | goto out; |
| 2961 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2962 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2963 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2964 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2965 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2966 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2967 | vport->num_disc_nodes = 0; |
| 2968 | /* go thru NPR list and issue ELS PLOGIs */ |
| 2969 | if (vport->fc_npr_cnt) |
| 2970 | lpfc_els_disc_plogi(vport); |
| 2971 | |
| 2972 | if (!vport->num_disc_nodes) { |
| 2973 | spin_lock_irq(shost->host_lock); |
| 2974 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2975 | spin_unlock_irq(shost->host_lock); |
| 2976 | lpfc_can_disctmo(vport); |
| 2977 | } |
| 2978 | vport->port_state = LPFC_VPORT_READY; |
| 2979 | |
| 2980 | out: |
| 2981 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2982 | return; |
| 2983 | } |
| 2984 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2985 | /** |
| 2986 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 2987 | * @phba: pointer to lpfc hba data structure. |
| 2988 | * |
| 2989 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 2990 | * the list of static vports to be created. The function create vports |
| 2991 | * based on the information returned from the HBA. |
| 2992 | **/ |
| 2993 | void |
| 2994 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 2995 | { |
| 2996 | LPFC_MBOXQ_t *pmb = NULL; |
| 2997 | MAILBOX_t *mb; |
| 2998 | struct static_vport_info *vport_info; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2999 | int rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3000 | struct fc_vport_identifiers vport_id; |
| 3001 | struct fc_vport *new_fc_vport; |
| 3002 | struct Scsi_Host *shost; |
| 3003 | struct lpfc_vport *vport; |
| 3004 | uint16_t offset = 0; |
| 3005 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3006 | struct lpfc_dmabuf *mp; |
| 3007 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3008 | |
| 3009 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3010 | if (!pmb) { |
| 3011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3012 | "0542 lpfc_create_static_vport failed to" |
| 3013 | " allocate mailbox memory\n"); |
| 3014 | return; |
| 3015 | } |
| 3016 | |
| 3017 | mb = &pmb->u.mb; |
| 3018 | |
| 3019 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 3020 | if (!vport_info) { |
| 3021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3022 | "0543 lpfc_create_static_vport failed to" |
| 3023 | " allocate vport_info\n"); |
| 3024 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | vport_buff = (uint8_t *) vport_info; |
| 3029 | do { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3030 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 3031 | goto out; |
| 3032 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3033 | pmb->vport = phba->pport; |
| 3034 | rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO); |
| 3035 | |
| 3036 | if ((rc != MBX_SUCCESS) || mb->mbxStatus) { |
| 3037 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3038 | "0544 lpfc_create_static_vport failed to" |
| 3039 | " issue dump mailbox command ret 0x%x " |
| 3040 | "status 0x%x\n", |
| 3041 | rc, mb->mbxStatus); |
| 3042 | goto out; |
| 3043 | } |
| 3044 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3045 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3046 | byte_count = pmb->u.mqe.un.mb_words[5]; |
| 3047 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 3048 | if (byte_count > sizeof(struct static_vport_info) - |
| 3049 | offset) |
| 3050 | byte_count = sizeof(struct static_vport_info) |
| 3051 | - offset; |
| 3052 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 3053 | offset += byte_count; |
| 3054 | } else { |
| 3055 | if (mb->un.varDmp.word_cnt > |
| 3056 | sizeof(struct static_vport_info) - offset) |
| 3057 | mb->un.varDmp.word_cnt = |
| 3058 | sizeof(struct static_vport_info) |
| 3059 | - offset; |
| 3060 | byte_count = mb->un.varDmp.word_cnt; |
| 3061 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 3062 | vport_buff + offset, |
| 3063 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3064 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3065 | offset += byte_count; |
| 3066 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3067 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3068 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3069 | offset < sizeof(struct static_vport_info)); |
| 3070 | |
| 3071 | |
| 3072 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 3073 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 3074 | != VPORT_INFO_REV)) { |
| 3075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3076 | "0545 lpfc_create_static_vport bad" |
| 3077 | " information header 0x%x 0x%x\n", |
| 3078 | le32_to_cpu(vport_info->signature), |
| 3079 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 3080 | |
| 3081 | goto out; |
| 3082 | } |
| 3083 | |
| 3084 | shost = lpfc_shost_from_vport(phba->pport); |
| 3085 | |
| 3086 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 3087 | memset(&vport_id, 0, sizeof(vport_id)); |
| 3088 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 3089 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 3090 | if (!vport_id.port_name || !vport_id.node_name) |
| 3091 | continue; |
| 3092 | |
| 3093 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 3094 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 3095 | vport_id.disable = false; |
| 3096 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 3097 | |
| 3098 | if (!new_fc_vport) { |
| 3099 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 3100 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3101 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3102 | continue; |
| 3103 | } |
| 3104 | |
| 3105 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 3106 | vport->vport_flag |= STATIC_VPORT; |
| 3107 | } |
| 3108 | |
| 3109 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3110 | kfree(vport_info); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3111 | if (rc != MBX_TIMEOUT) { |
| 3112 | if (pmb->context2) { |
| 3113 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 3114 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3115 | kfree(mp); |
| 3116 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3117 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3118 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3119 | |
| 3120 | return; |
| 3121 | } |
| 3122 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3123 | /* |
| 3124 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 3125 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3126 | * as the completion routine when the command is |
| 3127 | * handed off to the SLI layer. |
| 3128 | */ |
| 3129 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3130 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3131 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3132 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3133 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3134 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3135 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3137 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3138 | pmb->context1 = NULL; |
| 3139 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3141 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 3142 | "0258 Register Fabric login error: 0x%x\n", |
| 3143 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3145 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3146 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3147 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3148 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3149 | /* FLOGI failed, use loop map to make discovery list */ |
| 3150 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3152 | /* Start discovery */ |
| 3153 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3154 | /* Decrement the reference count to ndlp after the |
| 3155 | * reference to the ndlp are done. |
| 3156 | */ |
| 3157 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3158 | return; |
| 3159 | } |
| 3160 | |
| 3161 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3162 | /* Decrement the reference count to ndlp after the reference |
| 3163 | * to the ndlp are done. |
| 3164 | */ |
| 3165 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | return; |
| 3167 | } |
| 3168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3170 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3172 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3174 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 3175 | /* when physical port receive logo donot start |
| 3176 | * vport discovery */ |
| 3177 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
| 3178 | lpfc_start_fdiscs(phba); |
| 3179 | else |
| 3180 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3181 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3185 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3186 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3187 | |
| 3188 | /* Drop the reference count from the mbox at the end after |
| 3189 | * all the current reference to the ndlp have been done. |
| 3190 | */ |
| 3191 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | return; |
| 3193 | } |
| 3194 | |
| 3195 | /* |
| 3196 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3197 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3198 | * as the completion routine when the command is |
| 3199 | * handed off to the SLI layer. |
| 3200 | */ |
| 3201 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3202 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3204 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3206 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3207 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3208 | |
| 3209 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3210 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3211 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3212 | "0260 Register NameServer error: 0x%x\n", |
| 3213 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3214 | /* decrement the node reference count held for this |
| 3215 | * callback function. |
| 3216 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3217 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3219 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3220 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3221 | |
| 3222 | /* If no other thread is using the ndlp, free it */ |
| 3223 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3225 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3226 | /* |
| 3227 | * RegLogin failed, use loop map to make discovery |
| 3228 | * list |
| 3229 | */ |
| 3230 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3232 | /* Start discovery */ |
| 3233 | lpfc_disc_start(vport); |
| 3234 | return; |
| 3235 | } |
| 3236 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | return; |
| 3238 | } |
| 3239 | |
| 3240 | pmb->context1 = NULL; |
| 3241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3243 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3248 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3249 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3250 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3251 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3252 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3253 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3254 | |
| 3255 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3256 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | } |
| 3258 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3263 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | } |
| 3265 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3266 | /* decrement the node reference count held for this |
| 3267 | * callback function. |
| 3268 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3269 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3271 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3272 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | |
| 3274 | return; |
| 3275 | } |
| 3276 | |
| 3277 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3278 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3280 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3281 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | struct lpfc_rport_data *rdata; |
| 3283 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3284 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | |
| 3286 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3287 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3288 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3289 | rport_ids.port_id = ndlp->nlp_DID; |
| 3290 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3292 | /* |
| 3293 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3294 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3295 | * rport->dd_data points. So, if we're reusing a previously |
| 3296 | * registered port, drop the reference that we took the last time we |
| 3297 | * registered the port. |
| 3298 | */ |
| 3299 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3300 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3301 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3302 | |
| 3303 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3304 | "rport add: did:x%x flg:x%x type x%x", |
| 3305 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3306 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3307 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3308 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3310 | "Warning: fc_remote_port_add failed\n"); |
| 3311 | return; |
| 3312 | } |
| 3313 | |
| 3314 | /* initialize static port data */ |
| 3315 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3316 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3318 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3319 | |
| 3320 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3321 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3322 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3323 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3324 | |
| 3325 | |
| 3326 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3327 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3328 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3329 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3330 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3331 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3332 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3333 | return; |
| 3334 | } |
| 3335 | |
| 3336 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3337 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3338 | { |
| 3339 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3340 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3341 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3342 | "rport delete: did:x%x flg:x%x type x%x", |
| 3343 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3344 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3345 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | |
| 3347 | return; |
| 3348 | } |
| 3349 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3350 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3351 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3352 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3353 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3354 | |
| 3355 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3356 | switch (state) { |
| 3357 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3358 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3359 | break; |
| 3360 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3361 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3362 | break; |
| 3363 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3365 | break; |
| 3366 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3368 | break; |
| 3369 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3371 | break; |
| 3372 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3373 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3374 | break; |
| 3375 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3376 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3377 | break; |
| 3378 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3379 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3380 | break; |
| 3381 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3383 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3384 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3385 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3387 | int old_state, int new_state) |
| 3388 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3390 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3391 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3392 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3393 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3394 | } |
| 3395 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3396 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3397 | if (new_state == NLP_STE_NPR_NODE) |
| 3398 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3399 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3400 | /* Transport interface */ |
| 3401 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 3402 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | vport->phba->nport_event_cnt++; |
| 3404 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3405 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3407 | if (new_state == NLP_STE_MAPPED_NODE || |
| 3408 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3409 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3410 | /* |
| 3411 | * Tell the fc transport about the port, if we haven't |
| 3412 | * already. If we have, and it's a scsi entity, be |
| 3413 | * sure to unblock any attached scsi devices |
| 3414 | */ |
| 3415 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3416 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3417 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 3418 | (vport->stat_data_enabled)) { |
| 3419 | /* |
| 3420 | * A new target is discovered, if there is no buffer for |
| 3421 | * statistical data collection allocate buffer. |
| 3422 | */ |
| 3423 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 3424 | sizeof(struct lpfc_scsicmd_bkt), |
| 3425 | GFP_KERNEL); |
| 3426 | |
| 3427 | if (!ndlp->lat_data) |
| 3428 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3429 | "0286 lpfc_nlp_state_cleanup failed to " |
| 3430 | "allocate statistical data buffer DID " |
| 3431 | "0x%x\n", ndlp->nlp_DID); |
| 3432 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3433 | /* |
| 3434 | * if we added to Mapped list, but the remote port |
| 3435 | * registration failed or assigned a target id outside |
| 3436 | * our presentable range - move the node to the |
| 3437 | * Unmapped List |
| 3438 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3439 | if (new_state == NLP_STE_MAPPED_NODE && |
| 3440 | (!ndlp->rport || |
| 3441 | ndlp->rport->scsi_target_id == -1 || |
| 3442 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3444 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | spin_unlock_irq(shost->host_lock); |
| 3446 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3448 | } |
| 3449 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3450 | static char * |
| 3451 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 3452 | { |
| 3453 | static char *states[] = { |
| 3454 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 3455 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 3456 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 3457 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 3458 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 3459 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 3460 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 3461 | [NLP_STE_NPR_NODE] = "NPR", |
| 3462 | }; |
| 3463 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 3464 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3465 | strlcpy(buffer, states[state], size); |
| 3466 | else |
| 3467 | snprintf(buffer, size, "unknown (%d)", state); |
| 3468 | return buffer; |
| 3469 | } |
| 3470 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3471 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3472 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3473 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3474 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3475 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3476 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3477 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3478 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3479 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3480 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 3481 | ndlp->nlp_DID, |
| 3482 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 3483 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3484 | |
| 3485 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3486 | "node statechg did:x%x old:%d ste:%d", |
| 3487 | ndlp->nlp_DID, old_state, state); |
| 3488 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3489 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3490 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3491 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3492 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 3493 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 3494 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 3495 | } |
| 3496 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3497 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3498 | spin_lock_irq(shost->host_lock); |
| 3499 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3500 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3501 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3502 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3503 | |
| 3504 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3505 | lpfc_nlp_counters(vport, state, 1); |
| 3506 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3510 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3511 | { |
| 3512 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3513 | |
| 3514 | if (list_empty(&ndlp->nlp_listp)) { |
| 3515 | spin_lock_irq(shost->host_lock); |
| 3516 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3517 | spin_unlock_irq(shost->host_lock); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3523 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3524 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3525 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3526 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3527 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3528 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3529 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3530 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3531 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3532 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3533 | NLP_STE_UNUSED_NODE); |
| 3534 | } |
| 3535 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 3536 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3537 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3538 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3539 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3540 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 3541 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3542 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 3543 | NLP_STE_UNUSED_NODE); |
| 3544 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3546 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3547 | * @vport: Pointer to Virtual Port object. |
| 3548 | * @ndlp: Pointer to FC node object. |
| 3549 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3550 | * |
| 3551 | * This function is always called when node object need to be initialized. |
| 3552 | * It initializes all the fields of the node object. Although the reference |
| 3553 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 3554 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 3555 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 3556 | * the final release of ndlp is determined by its reference count. And, the |
| 3557 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3558 | **/ |
| 3559 | static inline void |
| 3560 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3561 | uint32_t did) |
| 3562 | { |
| 3563 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 3564 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 3565 | init_timer(&ndlp->nlp_delayfunc); |
| 3566 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 3567 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 3568 | ndlp->nlp_DID = did; |
| 3569 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3570 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3571 | ndlp->nlp_sid = NLP_NO_SID; |
| 3572 | kref_init(&ndlp->kref); |
| 3573 | NLP_INT_NODE_ACT(ndlp); |
| 3574 | atomic_set(&ndlp->cmd_pending, 0); |
| 3575 | ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; |
| 3576 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3577 | |
| 3578 | struct lpfc_nodelist * |
| 3579 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3580 | int state) |
| 3581 | { |
| 3582 | struct lpfc_hba *phba = vport->phba; |
| 3583 | uint32_t did; |
| 3584 | unsigned long flags; |
| 3585 | |
| 3586 | if (!ndlp) |
| 3587 | return NULL; |
| 3588 | |
| 3589 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3590 | /* The ndlp should not be in memory free mode */ |
| 3591 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3592 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3593 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3594 | "0277 lpfc_enable_node: ndlp:x%p " |
| 3595 | "usgmap:x%x refcnt:%d\n", |
| 3596 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3597 | atomic_read(&ndlp->kref.refcount)); |
| 3598 | return NULL; |
| 3599 | } |
| 3600 | /* The ndlp should not already be in active mode */ |
| 3601 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3602 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3603 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3604 | "0278 lpfc_enable_node: ndlp:x%p " |
| 3605 | "usgmap:x%x refcnt:%d\n", |
| 3606 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3607 | atomic_read(&ndlp->kref.refcount)); |
| 3608 | return NULL; |
| 3609 | } |
| 3610 | |
| 3611 | /* Keep the original DID */ |
| 3612 | did = ndlp->nlp_DID; |
| 3613 | |
| 3614 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 3615 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 3616 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3617 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3618 | |
| 3619 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3620 | |
| 3621 | if (state != NLP_STE_UNUSED_NODE) |
| 3622 | lpfc_nlp_set_state(vport, ndlp, state); |
| 3623 | |
| 3624 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3625 | "node enable: did:x%x", |
| 3626 | ndlp->nlp_DID, 0, 0); |
| 3627 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3631 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3632 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3633 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3634 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3635 | * 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] | 3636 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 3637 | * until ALL other outstanding threads have completed. We check |
| 3638 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3639 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3640 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3641 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3642 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3643 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3644 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /* |
| 3648 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 3649 | */ |
| 3650 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3651 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3652 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3653 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3654 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | uint32_t tmo; |
| 3656 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3658 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3659 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 3660 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3661 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3662 | * FC spec states we need 3 * ratov for CT requests |
| 3663 | */ |
| 3664 | tmo = ((phba->fc_ratov * 3) + 3); |
| 3665 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3667 | |
| 3668 | if (!timer_pending(&vport->fc_disctmo)) { |
| 3669 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3670 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 3671 | tmo, vport->port_state, vport->fc_flag); |
| 3672 | } |
| 3673 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3674 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 3675 | spin_lock_irq(shost->host_lock); |
| 3676 | vport->fc_flag |= FC_DISC_TMO; |
| 3677 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | |
| 3679 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3680 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3681 | "0247 Start Discovery Timer state x%x " |
| 3682 | "Data: x%x x%lx x%x x%x\n", |
| 3683 | vport->port_state, tmo, |
| 3684 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 3685 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | |
| 3687 | return; |
| 3688 | } |
| 3689 | |
| 3690 | /* |
| 3691 | * Cancel rescue timer for Discovery / RSCN handling |
| 3692 | */ |
| 3693 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3694 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3696 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3697 | unsigned long iflags; |
| 3698 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3699 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3700 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 3701 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 3702 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3704 | if (vport->fc_flag & FC_DISC_TMO) { |
| 3705 | spin_lock_irqsave(shost->host_lock, iflags); |
| 3706 | vport->fc_flag &= ~FC_DISC_TMO; |
| 3707 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 3708 | del_timer_sync(&vport->fc_disctmo); |
| 3709 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 3710 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 3711 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3715 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3716 | "0248 Cancel Discovery Timer state x%x " |
| 3717 | "Data: x%x x%x x%x\n", |
| 3718 | vport->port_state, vport->fc_flag, |
| 3719 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3720 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | /* |
| 3724 | * Check specified ring for outstanding IOCB on the SLI queue |
| 3725 | * Return true if iocb matches the specified nport |
| 3726 | */ |
| 3727 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3728 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 3729 | struct lpfc_sli_ring *pring, |
| 3730 | struct lpfc_iocbq *iocb, |
| 3731 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | struct lpfc_sli *psli = &phba->sli; |
| 3734 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3735 | struct lpfc_vport *vport = ndlp->vport; |
| 3736 | |
| 3737 | if (iocb->vport != vport) |
| 3738 | return 0; |
| 3739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | if (pring->ringno == LPFC_ELS_RING) { |
| 3741 | switch (icmd->ulpCommand) { |
| 3742 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3743 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3744 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 3746 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 3747 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | case CMD_XMIT_ELS_RSP64_CX: |
| 3749 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3750 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3752 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | |
| 3754 | } else if (pring->ringno == psli->fcp_ring) { |
| 3755 | /* Skip match check if waiting to relogin to FCP target */ |
| 3756 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3757 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3758 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | } |
| 3760 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3761 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | } |
| 3763 | } else if (pring->ringno == psli->next_ring) { |
| 3764 | |
| 3765 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3766 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /* |
| 3770 | * Free resources / clean up outstanding I/Os |
| 3771 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 3772 | */ |
| 3773 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3776 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | struct lpfc_sli *psli; |
| 3778 | struct lpfc_sli_ring *pring; |
| 3779 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3780 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3782 | lpfc_fabric_abort_nport(ndlp); |
| 3783 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | /* |
| 3785 | * Everything that matches on txcmplq will be returned |
| 3786 | * by firmware with a no rpi error. |
| 3787 | */ |
| 3788 | psli = &phba->sli; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3789 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | /* Now process each ring */ |
| 3791 | for (i = 0; i < psli->num_rings; i++) { |
| 3792 | pring = &psli->ring[i]; |
| 3793 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3794 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | /* |
| 3798 | * Check to see if iocb matches the nport we are |
| 3799 | * looking for |
| 3800 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3801 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 3802 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | /* It matches, so deque and call compl |
| 3804 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3805 | list_move_tail(&iocb->list, |
| 3806 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | } |
| 3809 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | } |
| 3812 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3813 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3814 | /* Cancel all the IOCBs from the completions list */ |
| 3815 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3816 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3817 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3818 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | /* |
| 3822 | * Free rpi associated with LPFC_NODELIST entry. |
| 3823 | * This routine is called from lpfc_freenode(), when we are removing |
| 3824 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 3825 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 3826 | * to the remote NPort. In addition, it is called after we receive |
| 3827 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 3828 | * we are waiting to PLOGI back to the remote NPort. |
| 3829 | */ |
| 3830 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3831 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | struct lpfc_hba *phba = vport->phba; |
| 3834 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | int rc; |
| 3836 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3837 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3838 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3839 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3840 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3841 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3842 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3843 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3845 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | lpfc_no_rpi(phba, ndlp); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame^] | 3848 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | ndlp->nlp_rpi = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3850 | ndlp->nlp_flag &= ~NLP_RPI_VALID; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 3851 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | return 1; |
| 3853 | } |
| 3854 | return 0; |
| 3855 | } |
| 3856 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3857 | /** |
| 3858 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 3859 | * @phba: pointer to lpfc hba data structure. |
| 3860 | * |
| 3861 | * This routine is invoked to unregister all the currently registered RPIs |
| 3862 | * to the HBA. |
| 3863 | **/ |
| 3864 | void |
| 3865 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 3866 | { |
| 3867 | struct lpfc_vport **vports; |
| 3868 | struct lpfc_nodelist *ndlp; |
| 3869 | struct Scsi_Host *shost; |
| 3870 | int i; |
| 3871 | |
| 3872 | vports = lpfc_create_vport_work_array(phba); |
| 3873 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3874 | shost = lpfc_shost_from_vport(vports[i]); |
| 3875 | spin_lock_irq(shost->host_lock); |
| 3876 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3877 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| 3878 | /* The mempool_alloc might sleep */ |
| 3879 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3880 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3881 | spin_lock_irq(shost->host_lock); |
| 3882 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3883 | } |
| 3884 | spin_unlock_irq(shost->host_lock); |
| 3885 | } |
| 3886 | lpfc_destroy_vport_work_array(phba, vports); |
| 3887 | } |
| 3888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3889 | void |
| 3890 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 3891 | { |
| 3892 | struct lpfc_hba *phba = vport->phba; |
| 3893 | LPFC_MBOXQ_t *mbox; |
| 3894 | int rc; |
| 3895 | |
| 3896 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3897 | if (mbox) { |
| 3898 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 3899 | mbox->vport = vport; |
| 3900 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3901 | mbox->context1 = NULL; |
| 3902 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3903 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3904 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3905 | |
| 3906 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 3907 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3908 | "1836 Could not issue " |
| 3909 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | void |
| 3914 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 3915 | { |
| 3916 | struct lpfc_hba *phba = vport->phba; |
| 3917 | LPFC_MBOXQ_t *mbox; |
| 3918 | int rc; |
| 3919 | |
| 3920 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3921 | if (mbox) { |
| 3922 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 3923 | mbox->vport = vport; |
| 3924 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3925 | mbox->context1 = NULL; |
| 3926 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3927 | if (rc != MBX_TIMEOUT) |
| 3928 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3929 | |
| 3930 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3931 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3932 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3933 | "unreg_did (default rpis) status %d\n", |
| 3934 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3935 | } |
| 3936 | } |
| 3937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | /* |
| 3939 | * Free resources associated with LPFC_NODELIST entry |
| 3940 | * so it can be freed. |
| 3941 | */ |
| 3942 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3943 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3944 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3945 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3946 | struct lpfc_hba *phba = vport->phba; |
| 3947 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | |
| 3950 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3951 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3952 | "0900 Cleanup node for NPort x%x " |
| 3953 | "Data: x%x x%x x%x\n", |
| 3954 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3955 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3956 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3957 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3958 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 3959 | "usgmap:x%x refcnt:%d\n", |
| 3960 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3961 | atomic_read(&ndlp->kref.refcount)); |
| 3962 | lpfc_dequeue_node(vport, ndlp); |
| 3963 | } else { |
| 3964 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3965 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 3966 | "usgmap:x%x refcnt:%d\n", |
| 3967 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3968 | atomic_read(&ndlp->kref.refcount)); |
| 3969 | lpfc_disable_node(vport, ndlp); |
| 3970 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 3973 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3974 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 3976 | mb->context2 = NULL; |
| 3977 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3978 | } |
| 3979 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3980 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3981 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3983 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3984 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 3986 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | kfree(mp); |
| 3989 | } |
| 3990 | list_del(&mb->list); |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3991 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3992 | lpfc_sli4_free_rpi(phba, |
| 3993 | mb->u.mb.un.varRegLogin.rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3995 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 3996 | * the ndlp reference count as we are in the process |
| 3997 | * of lpfc_nlp_release. |
| 3998 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | } |
| 4000 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4003 | lpfc_els_abort(phba, ndlp); |
| 4004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4005 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4006 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4009 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 4011 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4012 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 4013 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4015 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4017 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /* |
| 4021 | * Check to see if we can free the nlp back to the freelist. |
| 4022 | * If we are in the middle of using the nlp in the discovery state |
| 4023 | * machine, defer the free till we reach the end of the state machine. |
| 4024 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4025 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4026 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4028 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4029 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4030 | LPFC_MBOXQ_t *mbox; |
| 4031 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4033 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4034 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 4035 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4036 | !(ndlp->nlp_flag & NLP_RPI_VALID)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4037 | /* For this case we need to cleanup the default rpi |
| 4038 | * allocated by the firmware. |
| 4039 | */ |
| 4040 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 4041 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4042 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4043 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 4044 | if (rc) { |
| 4045 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4046 | } |
| 4047 | else { |
| 4048 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 4049 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 4050 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4051 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4052 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4053 | if (rc == MBX_NOT_FINISHED) { |
| 4054 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4055 | } |
| 4056 | } |
| 4057 | } |
| 4058 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4059 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4060 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4062 | * We can get here with a non-NULL ndlp->rport because when we |
| 4063 | * unregister a rport we don't break the rport/node linkage. So if we |
| 4064 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4066 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4067 | rdata = ndlp->rport->dd_data; |
| 4068 | rdata->pnode = NULL; |
| 4069 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4075 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | |
| 4079 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4080 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | /* First check for Direct match */ |
| 4083 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4084 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | |
| 4086 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4089 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | matchdid.un.word = did; |
| 4093 | ndlpdid.un.word = ndlp->nlp_DID; |
| 4094 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 4095 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 4096 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 4097 | if ((ndlpdid.un.b.domain == 0) && |
| 4098 | (ndlpdid.un.b.area == 0)) { |
| 4099 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4100 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | } |
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 = ndlp->nlp_DID; |
| 4106 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 4107 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 4108 | if ((matchdid.un.b.domain == 0) && |
| 4109 | (matchdid.un.b.area == 0)) { |
| 4110 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4111 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 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 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4118 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4119 | static struct lpfc_nodelist * |
| 4120 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 4122 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | uint32_t data1; |
| 4124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 4126 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4127 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 4128 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 4129 | ((uint32_t) ndlp->nlp_type << 8) | |
| 4130 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4131 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4132 | "0929 FIND node DID " |
| 4133 | "Data: x%p x%x x%x x%x\n", |
| 4134 | ndlp, ndlp->nlp_DID, |
| 4135 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4136 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | } |
| 4138 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 4139 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4141 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 4142 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | return NULL; |
| 4144 | } |
| 4145 | |
| 4146 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4147 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | spin_lock_irq(shost->host_lock); |
| 4153 | ndlp = __lpfc_findnode_did(vport, did); |
| 4154 | spin_unlock_irq(shost->host_lock); |
| 4155 | return ndlp; |
| 4156 | } |
| 4157 | |
| 4158 | struct lpfc_nodelist * |
| 4159 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 4160 | { |
| 4161 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4162 | struct lpfc_nodelist *ndlp; |
| 4163 | |
| 4164 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4165 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4166 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4167 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | return NULL; |
| 4169 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4170 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | if (!ndlp) |
| 4172 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | lpfc_nlp_init(vport, ndlp, did); |
| 4174 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4175 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4176 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4177 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4179 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4180 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4181 | if (!ndlp) |
| 4182 | return NULL; |
| 4183 | spin_lock_irq(shost->host_lock); |
| 4184 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4185 | spin_unlock_irq(shost->host_lock); |
| 4186 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4188 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4189 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4190 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4192 | /* If we've already recieved a PLOGI from this NPort |
| 4193 | * we don't need to try to discover it again. |
| 4194 | */ |
| 4195 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4196 | return NULL; |
| 4197 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4198 | /* Since this node is marked for discovery, |
| 4199 | * delay timeout is not needed. |
| 4200 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4201 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4202 | spin_lock_irq(shost->host_lock); |
| 4203 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4204 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4205 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4207 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4208 | /* If we've already recieved a PLOGI from this NPort, |
| 4209 | * or we are already in the process of discovery on it, |
| 4210 | * we don't need to try to discover it again. |
| 4211 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4212 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4213 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4214 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4217 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4219 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | } |
| 4221 | return ndlp; |
| 4222 | } |
| 4223 | |
| 4224 | /* Build a list of nodes to discover based on the loopmap */ |
| 4225 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4226 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4229 | int j; |
| 4230 | uint32_t alpa, index; |
| 4231 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4232 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | |
| 4235 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4237 | |
| 4238 | /* Check for loop map present or not */ |
| 4239 | if (phba->alpa_map[0]) { |
| 4240 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4241 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4244 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | } |
| 4246 | } else { |
| 4247 | /* No alpamap, so try all alpa's */ |
| 4248 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4249 | /* If cfg_scan_down is set, start from highest |
| 4250 | * ALPA (0xef) to lowest (0x1). |
| 4251 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4252 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | index = j; |
| 4254 | else |
| 4255 | index = FC_MAXLOOP - j - 1; |
| 4256 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4259 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | } |
| 4261 | } |
| 4262 | return; |
| 4263 | } |
| 4264 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4266 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4267 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | struct lpfc_sli *psli = &phba->sli; |
| 4270 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4271 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4272 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4273 | int rc; |
| 4274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4275 | /* |
| 4276 | * if it's not a physical port or if we already send |
| 4277 | * clear_la then don't send it. |
| 4278 | */ |
| 4279 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4280 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4281 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4282 | return; |
| 4283 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4284 | /* Link up discovery */ |
| 4285 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4286 | phba->link_state = LPFC_CLEAR_LA; |
| 4287 | lpfc_clear_la(phba, mbox); |
| 4288 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4289 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4290 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | if (rc == MBX_NOT_FINISHED) { |
| 4292 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4293 | lpfc_disc_flush_list(vport); |
| 4294 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4295 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4296 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4297 | phba->link_state = LPFC_HBA_ERROR; |
| 4298 | } |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4303 | void |
| 4304 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4305 | { |
| 4306 | LPFC_MBOXQ_t *regvpimbox; |
| 4307 | |
| 4308 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4309 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4310 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4311 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4312 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4313 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4314 | == MBX_NOT_FINISHED) { |
| 4315 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 4321 | void |
| 4322 | lpfc_disc_start(struct lpfc_vport *vport) |
| 4323 | { |
| 4324 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4325 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4326 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4328 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4329 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | |
| 4333 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | clear_la_pending = 1; |
| 4335 | else |
| 4336 | clear_la_pending = 0; |
| 4337 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4338 | if (vport->port_state < LPFC_VPORT_READY) |
| 4339 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | lpfc_set_disctmo(vport); |
| 4342 | |
| 4343 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4345 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | |
| 4348 | vport->fc_prevDID = vport->fc_myDID; |
| 4349 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | |
| 4351 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4352 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4353 | "0202 Start Discovery hba state x%x " |
| 4354 | "Data: x%x x%x x%x\n", |
| 4355 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 4356 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | |
| 4358 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4359 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | |
| 4361 | if (num_sent) |
| 4362 | return; |
| 4363 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4364 | /* |
| 4365 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 4366 | * continue discovery. |
| 4367 | */ |
| 4368 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4369 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4370 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 4371 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4372 | lpfc_issue_reg_vpi(phba, vport); |
| 4373 | return; |
| 4374 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4376 | /* |
| 4377 | * For SLI2, we need to set port_state to READY and continue |
| 4378 | * discovery. |
| 4379 | */ |
| 4380 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 4381 | /* If we get here, there is nothing to ADISC */ |
| 4382 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 4383 | lpfc_issue_clear_la(phba, vport); |
| 4384 | |
| 4385 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | vport->num_disc_nodes = 0; |
| 4387 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 4388 | if (vport->fc_npr_cnt) |
| 4389 | lpfc_els_disc_plogi(vport); |
| 4390 | |
| 4391 | if (!vport->num_disc_nodes) { |
| 4392 | spin_lock_irq(shost->host_lock); |
| 4393 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 4394 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4395 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | } |
| 4397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4398 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4399 | } else { |
| 4400 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4401 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | |
| 4403 | if (num_sent) |
| 4404 | return; |
| 4405 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4406 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | /* Check to see if more RSCNs came in while we |
| 4408 | * were processing this one. |
| 4409 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | if ((vport->fc_rscn_id_cnt == 0) && |
| 4411 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 4412 | spin_lock_irq(shost->host_lock); |
| 4413 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 4414 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4415 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4416 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4417 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | } |
| 4419 | } |
| 4420 | return; |
| 4421 | } |
| 4422 | |
| 4423 | /* |
| 4424 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 4425 | * ring the match the sppecified nodelist. |
| 4426 | */ |
| 4427 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4428 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4429 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4430 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | struct lpfc_sli *psli; |
| 4432 | IOCB_t *icmd; |
| 4433 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4434 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | |
| 4436 | psli = &phba->sli; |
| 4437 | pring = &psli->ring[LPFC_ELS_RING]; |
| 4438 | |
| 4439 | /* Error matching iocb on txq or txcmplq |
| 4440 | * First check the txq. |
| 4441 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4442 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4443 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4444 | if (iocb->context1 != ndlp) { |
| 4445 | continue; |
| 4446 | } |
| 4447 | icmd = &iocb->iocb; |
| 4448 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 4449 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 4450 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4451 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | /* Next check the txcmplq */ |
| 4457 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 4458 | if (iocb->context1 != ndlp) { |
| 4459 | continue; |
| 4460 | } |
| 4461 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4462 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 4463 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4464 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | } |
| 4466 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4467 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4468 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4469 | /* Cancel all the IOCBs from the completions list */ |
| 4470 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4471 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | } |
| 4473 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4474 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4475 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4476 | { |
| 4477 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4480 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 4481 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4482 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4483 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4484 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4485 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4486 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 4487 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4488 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | } |
| 4490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | } |
| 4492 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4493 | void |
| 4494 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 4495 | { |
| 4496 | lpfc_els_flush_rscn(vport); |
| 4497 | lpfc_els_flush_cmd(vport); |
| 4498 | lpfc_disc_flush_list(vport); |
| 4499 | } |
| 4500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | /*****************************************************************************/ |
| 4502 | /* |
| 4503 | * NAME: lpfc_disc_timeout |
| 4504 | * |
| 4505 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 4506 | * |
| 4507 | * EXECUTION ENVIRONMENT: interrupt only |
| 4508 | * |
| 4509 | * CALLED FROM: |
| 4510 | * Timer function |
| 4511 | * |
| 4512 | * RETURNS: |
| 4513 | * none |
| 4514 | */ |
| 4515 | /*****************************************************************************/ |
| 4516 | void |
| 4517 | lpfc_disc_timeout(unsigned long ptr) |
| 4518 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4520 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4521 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | unsigned long flags = 0; |
| 4523 | |
| 4524 | if (unlikely(!phba)) |
| 4525 | return; |
| 4526 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4527 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 4528 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 4529 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4531 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4533 | if (!tmo_posted) |
| 4534 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4535 | return; |
| 4536 | } |
| 4537 | |
| 4538 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4539 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4541 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4542 | struct lpfc_hba *phba = vport->phba; |
| 4543 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4544 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4545 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | int rc, clrlaerr = 0; |
| 4547 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4548 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | return; |
| 4550 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4551 | spin_lock_irq(shost->host_lock); |
| 4552 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4553 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4555 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4556 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 4557 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4558 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | |
| 4561 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 4563 | * FAN |
| 4564 | */ |
| 4565 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4566 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 4567 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4568 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4569 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4570 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4571 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4572 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4573 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 4574 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4575 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 4576 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4577 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4578 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4579 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4580 | /* Fail outstanding IO now since device |
| 4581 | * is marked for PLOGI. |
| 4582 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4583 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4584 | } |
| 4585 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4586 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4587 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4588 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4589 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4590 | break; |
| 4591 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4592 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4594 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4596 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4597 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4598 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | |
| 4600 | /* Assume no Fabric and go on with discovery. |
| 4601 | * Check for outstanding ELS FLOGI to abort. |
| 4602 | */ |
| 4603 | |
| 4604 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | |
| 4607 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4608 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | break; |
| 4610 | |
| 4611 | case LPFC_FABRIC_CFG_LINK: |
| 4612 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 4613 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4614 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4615 | "0223 Timeout while waiting for " |
| 4616 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4619 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4620 | lpfc_els_abort(phba, ndlp); |
| 4621 | |
| 4622 | /* ReStart discovery */ |
| 4623 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4624 | |
| 4625 | case LPFC_NS_QRY: |
| 4626 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4627 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4628 | "0224 NameServer Query timeout " |
| 4629 | "Data: x%x x%x\n", |
| 4630 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4632 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 4633 | /* Try it one more time */ |
| 4634 | vport->fc_ns_retry++; |
| 4635 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 4636 | vport->fc_ns_retry, 0); |
| 4637 | if (rc == 0) |
| 4638 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4639 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4640 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4641 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4642 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4643 | /* |
| 4644 | * Discovery is over. |
| 4645 | * set port_state to PORT_READY if SLI2. |
| 4646 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4647 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4648 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4649 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4650 | lpfc_issue_reg_vpi(phba, vport); |
| 4651 | else { /* NPIV Not enabled */ |
| 4652 | lpfc_issue_clear_la(phba, vport); |
| 4653 | vport->port_state = LPFC_VPORT_READY; |
| 4654 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 4658 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4659 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4660 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4661 | "0206 Device Discovery " |
| 4662 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4663 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | break; |
| 4665 | } |
| 4666 | |
| 4667 | lpfc_linkdown(phba); |
| 4668 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 4669 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4670 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4671 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4672 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4673 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4674 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | if (rc == MBX_NOT_FINISHED) |
| 4676 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 4677 | |
| 4678 | break; |
| 4679 | |
| 4680 | case LPFC_DISC_AUTH: |
| 4681 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4682 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4683 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | lpfc_disc_flush_list(vport); |
| 4685 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4686 | /* |
| 4687 | * set port_state to PORT_READY if SLI2. |
| 4688 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4689 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4690 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4691 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4692 | lpfc_issue_reg_vpi(phba, vport); |
| 4693 | else { /* NPIV Not enabled */ |
| 4694 | lpfc_issue_clear_la(phba, vport); |
| 4695 | vport->port_state = LPFC_VPORT_READY; |
| 4696 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4697 | } |
| 4698 | break; |
| 4699 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4700 | case LPFC_VPORT_READY: |
| 4701 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4702 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4703 | "0231 RSCN timeout Data: x%x " |
| 4704 | "x%x\n", |
| 4705 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | |
| 4707 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | lpfc_els_flush_rscn(vport); |
| 4711 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4712 | } |
| 4713 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4714 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4715 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4716 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4717 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4718 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | break; |
| 4720 | } |
| 4721 | |
| 4722 | switch (phba->link_state) { |
| 4723 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4724 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4726 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4727 | clrlaerr = 1; |
| 4728 | break; |
| 4729 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4730 | case LPFC_LINK_UP: |
| 4731 | lpfc_issue_clear_la(phba, vport); |
| 4732 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4733 | case LPFC_LINK_UNKNOWN: |
| 4734 | case LPFC_WARM_START: |
| 4735 | case LPFC_INIT_START: |
| 4736 | case LPFC_INIT_MBX_CMDS: |
| 4737 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4738 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4739 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4740 | "0230 Unexpected timeout, hba link " |
| 4741 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4742 | clrlaerr = 1; |
| 4743 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4744 | |
| 4745 | case LPFC_HBA_READY: |
| 4746 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4751 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4753 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4754 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | return; |
| 4758 | } |
| 4759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | /* |
| 4761 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 4762 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4763 | * as the completion routine when the command is |
| 4764 | * handed off to the SLI layer. |
| 4765 | */ |
| 4766 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4767 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4769 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4770 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 4771 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4772 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | |
| 4774 | pmb->context1 = NULL; |
| 4775 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4777 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4778 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4779 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4780 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4781 | /* |
| 4782 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 4783 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 4784 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4785 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4787 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4788 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 4789 | else |
| 4790 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4792 | /* decrement the node reference count held for this callback |
| 4793 | * function. |
| 4794 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4795 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4797 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4798 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | |
| 4800 | return; |
| 4801 | } |
| 4802 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4803 | static int |
| 4804 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 4805 | { |
| 4806 | uint16_t *rpi = param; |
| 4807 | |
| 4808 | return ndlp->nlp_rpi == *rpi; |
| 4809 | } |
| 4810 | |
| 4811 | static int |
| 4812 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 4813 | { |
| 4814 | return memcmp(&ndlp->nlp_portname, param, |
| 4815 | sizeof(ndlp->nlp_portname)) == 0; |
| 4816 | } |
| 4817 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4818 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4819 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4821 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4823 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4824 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4825 | return ndlp; |
| 4826 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4827 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | } |
| 4829 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4830 | /* |
| 4831 | * 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] | 4832 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4833 | */ |
| 4834 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4835 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4836 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4837 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4838 | } |
| 4839 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4840 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4841 | * 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] | 4842 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4843 | */ |
| 4844 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4845 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4846 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4847 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4848 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4849 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | spin_lock_irq(shost->host_lock); |
| 4851 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 4852 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4853 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4854 | } |
| 4855 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4857 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4858 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4859 | { |
| 4860 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4861 | |
| 4862 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4863 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4864 | |
| 4865 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4866 | "node init: did:x%x", |
| 4867 | ndlp->nlp_DID, 0, 0); |
| 4868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | return; |
| 4870 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4871 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4872 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 4873 | * and mempool_free's the nodelist. |
| 4874 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4875 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4876 | lpfc_nlp_release(struct kref *kref) |
| 4877 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4878 | struct lpfc_hba *phba; |
| 4879 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4880 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 4881 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4882 | |
| 4883 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4884 | "node release: did:x%x flg:x%x type:x%x", |
| 4885 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4886 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4887 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4888 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 4889 | "usgmap:x%x refcnt:%d\n", |
| 4890 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4891 | atomic_read(&ndlp->kref.refcount)); |
| 4892 | |
| 4893 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4894 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4895 | |
| 4896 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4897 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4898 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4899 | NLP_CLR_NODE_ACT(ndlp); |
| 4900 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4901 | |
| 4902 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4903 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4904 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4905 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4906 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4907 | } |
| 4908 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4909 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 4910 | * that one discovery thread won't free a ndlp while another discovery thread |
| 4911 | * is using it. |
| 4912 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4913 | struct lpfc_nodelist * |
| 4914 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 4915 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4916 | struct lpfc_hba *phba; |
| 4917 | unsigned long flags; |
| 4918 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4919 | if (ndlp) { |
| 4920 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4921 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 4922 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4923 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4924 | /* The check of ndlp usage to prevent incrementing the |
| 4925 | * ndlp reference count that is in the process of being |
| 4926 | * released. |
| 4927 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4928 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4929 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4930 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 4931 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4932 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4933 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 4934 | "usgmap:x%x refcnt:%d\n", |
| 4935 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4936 | atomic_read(&ndlp->kref.refcount)); |
| 4937 | return NULL; |
| 4938 | } else |
| 4939 | kref_get(&ndlp->kref); |
| 4940 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4941 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4942 | return ndlp; |
| 4943 | } |
| 4944 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4945 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4946 | * count goes to 0, this indicates the the associated nodelist should be |
| 4947 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 4948 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 4949 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4950 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4951 | int |
| 4952 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 4953 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4954 | struct lpfc_hba *phba; |
| 4955 | unsigned long flags; |
| 4956 | |
| 4957 | if (!ndlp) |
| 4958 | return 1; |
| 4959 | |
| 4960 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4961 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 4962 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4963 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4964 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4965 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4966 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 4967 | * possible race condition that kref_put got invoked again |
| 4968 | * after previous one has done ndlp memory free. |
| 4969 | */ |
| 4970 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 4971 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4972 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4973 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 4974 | "usgmap:x%x refcnt:%d\n", |
| 4975 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4976 | atomic_read(&ndlp->kref.refcount)); |
| 4977 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4978 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4979 | /* Check the ndlp inactivate log flag to avoid the possible |
| 4980 | * race condition that kref_put got invoked again after ndlp |
| 4981 | * is already in inactivating state. |
| 4982 | */ |
| 4983 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 4984 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4985 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4986 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 4987 | "usgmap:x%x refcnt:%d\n", |
| 4988 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4989 | atomic_read(&ndlp->kref.refcount)); |
| 4990 | return 1; |
| 4991 | } |
| 4992 | /* For last put, mark the ndlp usage flags to make sure no |
| 4993 | * other kref_get and kref_put on the same ndlp shall get |
| 4994 | * in between the process when the final kref_put has been |
| 4995 | * invoked on this ndlp. |
| 4996 | */ |
| 4997 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 4998 | /* Indicate ndlp is put to inactive state. */ |
| 4999 | NLP_SET_IACT_REQ(ndlp); |
| 5000 | /* Acknowledge ndlp memory free has been seen. */ |
| 5001 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 5002 | NLP_SET_FREE_ACK(ndlp); |
| 5003 | } |
| 5004 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 5005 | /* Note, the kref_put returns 1 when decrementing a reference |
| 5006 | * count that was 1, it invokes the release callback function, |
| 5007 | * but it still left the reference count as 1 (not actually |
| 5008 | * performs the last decrementation). Otherwise, it actually |
| 5009 | * decrements the reference count and returns 0. |
| 5010 | */ |
| 5011 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5012 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5013 | |
| 5014 | /* 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] | 5015 | * by any other discovery thread. This routine returns 1 if the |
| 5016 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 5017 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5018 | */ |
| 5019 | int |
| 5020 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 5021 | { |
| 5022 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 5023 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 5024 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 5025 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5026 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 5027 | if (lpfc_nlp_put(ndlp)) |
| 5028 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5029 | return 0; |
| 5030 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5031 | |
| 5032 | /** |
| 5033 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 5034 | * @phba: Pointer to hba context object. |
| 5035 | * |
| 5036 | * This function iterate through all FC nodes associated |
| 5037 | * will all vports to check if there is any node with |
| 5038 | * fc_rports associated with it. If there is an fc_rport |
| 5039 | * associated with the node, then the node is either in |
| 5040 | * discovered state or its devloss_timer is pending. |
| 5041 | */ |
| 5042 | static int |
| 5043 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 5044 | { |
| 5045 | struct lpfc_vport **vports; |
| 5046 | int i, ret = 0; |
| 5047 | struct lpfc_nodelist *ndlp; |
| 5048 | struct Scsi_Host *shost; |
| 5049 | |
| 5050 | vports = lpfc_create_vport_work_array(phba); |
| 5051 | |
| 5052 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 5053 | shost = lpfc_shost_from_vport(vports[i]); |
| 5054 | spin_lock_irq(shost->host_lock); |
| 5055 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 5056 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 5057 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 5058 | ret = 1; |
| 5059 | spin_unlock_irq(shost->host_lock); |
| 5060 | goto out; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5061 | } else { |
| 5062 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 5063 | "2624 RPI %x DID %x flg %x still " |
| 5064 | "logged in\n", |
| 5065 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 5066 | ndlp->nlp_flag); |
| 5067 | if (ndlp->nlp_flag & NLP_RPI_VALID) |
| 5068 | ret = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5069 | } |
| 5070 | } |
| 5071 | spin_unlock_irq(shost->host_lock); |
| 5072 | } |
| 5073 | out: |
| 5074 | lpfc_destroy_vport_work_array(phba, vports); |
| 5075 | return ret; |
| 5076 | } |
| 5077 | |
| 5078 | /** |
| 5079 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 5080 | * @phba: Pointer to hba context object. |
| 5081 | * @mboxq: Pointer to mailbox object. |
| 5082 | * |
| 5083 | * This function frees memory associated with the mailbox command. |
| 5084 | */ |
| 5085 | static void |
| 5086 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5087 | { |
| 5088 | struct lpfc_vport *vport = mboxq->vport; |
| 5089 | |
| 5090 | if (mboxq->u.mb.mbxStatus) { |
| 5091 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5092 | "2555 UNREG_VFI mbxStatus error x%x " |
| 5093 | "HBA state x%x\n", |
| 5094 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5095 | } |
| 5096 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5097 | return; |
| 5098 | } |
| 5099 | |
| 5100 | /** |
| 5101 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 5102 | * @phba: Pointer to hba context object. |
| 5103 | * @mboxq: Pointer to mailbox object. |
| 5104 | * |
| 5105 | * This function frees memory associated with the mailbox command. |
| 5106 | */ |
| 5107 | static void |
| 5108 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 5109 | { |
| 5110 | struct lpfc_vport *vport = mboxq->vport; |
| 5111 | |
| 5112 | if (mboxq->u.mb.mbxStatus) { |
| 5113 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 5114 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 5115 | "HBA state x%x\n", |
| 5116 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 5117 | } |
| 5118 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5119 | return; |
| 5120 | } |
| 5121 | |
| 5122 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5123 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5124 | * @phba: Pointer to hba context object. |
| 5125 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5126 | * This function prepare the HBA for unregistering the currently registered |
| 5127 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 5128 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5129 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5130 | int |
| 5131 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5132 | { |
| 5133 | LPFC_MBOXQ_t *mbox; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5134 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5135 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5136 | struct Scsi_Host *shost; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5137 | int i, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5138 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5139 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5140 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5141 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5142 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5143 | /* At this point, all discovery is aborted */ |
| 5144 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5145 | |
| 5146 | /* Unregister VPIs */ |
| 5147 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5148 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5149 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5150 | /* Stop FLOGI/FDISC retries */ |
| 5151 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 5152 | if (ndlp) |
| 5153 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5154 | lpfc_cleanup_pending_mbox(vports[i]); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5155 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5156 | shost = lpfc_shost_from_vport(vports[i]); |
| 5157 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 5158 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5159 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5160 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5161 | } |
| 5162 | lpfc_destroy_vport_work_array(phba, vports); |
| 5163 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5164 | /* Cleanup any outstanding ELS commands */ |
| 5165 | lpfc_els_flush_all_cmd(phba); |
| 5166 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5167 | /* Unregister VFI */ |
| 5168 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5169 | if (!mbox) { |
| 5170 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5171 | "2556 UNREG_VFI mbox allocation failed" |
| 5172 | "HBA state x%x\n", phba->pport->port_state); |
| 5173 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5174 | } |
| 5175 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5176 | lpfc_unreg_vfi(mbox, phba->pport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5177 | mbox->vport = phba->pport; |
| 5178 | mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 5179 | |
| 5180 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5181 | if (rc == MBX_NOT_FINISHED) { |
| 5182 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5183 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 5184 | "HBA state x%x\n", |
| 5185 | rc, phba->pport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5186 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5187 | return -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5188 | } |
| 5189 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5190 | shost = lpfc_shost_from_vport(phba->pport); |
| 5191 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5192 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5193 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5194 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5195 | return 0; |
| 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5200 | * @phba: Pointer to hba context object. |
| 5201 | * |
| 5202 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5203 | * unregister the currently registered FCF record. The driver does not reset |
| 5204 | * the driver FCF usage state flags. |
| 5205 | * |
| 5206 | * Return 0 if successfully issued, none-zero otherwise. |
| 5207 | */ |
| 5208 | int |
| 5209 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 5210 | { |
| 5211 | LPFC_MBOXQ_t *mbox; |
| 5212 | int rc; |
| 5213 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5214 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5215 | if (!mbox) { |
| 5216 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5217 | "2551 UNREG_FCFI mbox allocation failed" |
| 5218 | "HBA state x%x\n", phba->pport->port_state); |
| 5219 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5220 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5221 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 5222 | mbox->vport = phba->pport; |
| 5223 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 5224 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5225 | |
| 5226 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5227 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5228 | "2552 Unregister FCFI command failed rc x%x " |
| 5229 | "HBA state x%x\n", |
| 5230 | rc, phba->pport->port_state); |
| 5231 | return -EINVAL; |
| 5232 | } |
| 5233 | return 0; |
| 5234 | } |
| 5235 | |
| 5236 | /** |
| 5237 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 5238 | * @phba: Pointer to hba context object. |
| 5239 | * |
| 5240 | * This function unregisters the currently reigstered FCF. This function |
| 5241 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 5242 | */ |
| 5243 | void |
| 5244 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 5245 | { |
| 5246 | int rc; |
| 5247 | |
| 5248 | /* Preparation for unregistering fcf */ |
| 5249 | rc = lpfc_unregister_fcf_prep(phba); |
| 5250 | if (rc) { |
| 5251 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5252 | "2748 Failed to prepare for unregistering " |
| 5253 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5254 | return; |
| 5255 | } |
| 5256 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5257 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5258 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5259 | if (rc) |
| 5260 | return; |
| 5261 | /* Reset HBA FCF states after successful unregister FCF */ |
| 5262 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5263 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5264 | |
| 5265 | /* |
| 5266 | * If driver is not unloading, check if there is any other |
| 5267 | * FCF record that can be used for discovery. |
| 5268 | */ |
| 5269 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5270 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5271 | return; |
| 5272 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5273 | /* This is considered as the initial FCF discovery scan */ |
| 5274 | spin_lock_irq(&phba->hbalock); |
| 5275 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 5276 | spin_unlock_irq(&phba->hbalock); |
| 5277 | 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] | 5278 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5279 | if (rc) { |
| 5280 | spin_lock_irq(&phba->hbalock); |
| 5281 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 5282 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5283 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5284 | "2553 lpfc_unregister_unused_fcf failed " |
| 5285 | "to read FCF record HBA state x%x\n", |
| 5286 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5287 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /** |
| 5291 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 5292 | * @phba: Pointer to hba context object. |
| 5293 | * |
| 5294 | * This function just unregisters the currently reigstered FCF. It does not |
| 5295 | * try to find another FCF for discovery. |
| 5296 | */ |
| 5297 | void |
| 5298 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 5299 | { |
| 5300 | int rc; |
| 5301 | |
| 5302 | /* Preparation for unregistering fcf */ |
| 5303 | rc = lpfc_unregister_fcf_prep(phba); |
| 5304 | if (rc) { |
| 5305 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5306 | "2749 Failed to prepare for unregistering " |
| 5307 | "HBA's FCF record: rc=%d\n", rc); |
| 5308 | return; |
| 5309 | } |
| 5310 | |
| 5311 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5312 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5313 | if (rc) |
| 5314 | return; |
| 5315 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 5316 | spin_lock_irq(&phba->hbalock); |
| 5317 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 5318 | spin_unlock_irq(&phba->hbalock); |
| 5319 | } |
| 5320 | |
| 5321 | /** |
| 5322 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 5323 | * @phba: Pointer to hba context object. |
| 5324 | * |
| 5325 | * This function check if there are any connected remote port for the FCF and |
| 5326 | * if all the devices are disconnected, this function unregister FCFI. |
| 5327 | * This function also tries to use another FCF for discovery. |
| 5328 | */ |
| 5329 | void |
| 5330 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 5331 | { |
| 5332 | /* |
| 5333 | * If HBA is not running in FIP mode or if HBA does not support |
| 5334 | * FCoE or if FCF is not registered, do nothing. |
| 5335 | */ |
| 5336 | spin_lock_irq(&phba->hbalock); |
| 5337 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT) || |
| 5338 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 5339 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
| 5340 | (phba->pport->port_state == LPFC_FLOGI)) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5341 | spin_unlock_irq(&phba->hbalock); |
| 5342 | return; |
| 5343 | } |
| 5344 | spin_unlock_irq(&phba->hbalock); |
| 5345 | |
| 5346 | if (lpfc_fcf_inuse(phba)) |
| 5347 | return; |
| 5348 | |
| 5349 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | /** |
| 5353 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 5354 | * @phba: Pointer to hba context object. |
| 5355 | * @buff: Buffer containing the FCF connection table as in the config |
| 5356 | * region. |
| 5357 | * This function create driver data structure for the FCF connection |
| 5358 | * record table read from config region 23. |
| 5359 | */ |
| 5360 | static void |
| 5361 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 5362 | uint8_t *buff) |
| 5363 | { |
| 5364 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5365 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 5366 | struct lpfc_fcf_conn_rec *conn_rec; |
| 5367 | uint32_t record_count; |
| 5368 | int i; |
| 5369 | |
| 5370 | /* Free the current connect table */ |
| 5371 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5372 | &phba->fcf_conn_rec_list, list) { |
| 5373 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5374 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5375 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5376 | |
| 5377 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 5378 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 5379 | sizeof(struct lpfc_fcf_conn_rec); |
| 5380 | |
| 5381 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 5382 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 5383 | |
| 5384 | for (i = 0; i < record_count; i++) { |
| 5385 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 5386 | continue; |
| 5387 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 5388 | GFP_KERNEL); |
| 5389 | if (!conn_entry) { |
| 5390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5391 | "2566 Failed to allocate connection" |
| 5392 | " table entry\n"); |
| 5393 | return; |
| 5394 | } |
| 5395 | |
| 5396 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 5397 | sizeof(struct lpfc_fcf_conn_rec)); |
| 5398 | conn_entry->conn_rec.vlan_tag = |
| 5399 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 5400 | conn_entry->conn_rec.flags = |
| 5401 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 5402 | list_add_tail(&conn_entry->list, |
| 5403 | &phba->fcf_conn_rec_list); |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | /** |
| 5408 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 5409 | * @phba: Pointer to hba context object. |
| 5410 | * @buff: Buffer containing the FCoE parameter data structure. |
| 5411 | * |
| 5412 | * This function update driver data structure with config |
| 5413 | * parameters read from config region 23. |
| 5414 | */ |
| 5415 | static void |
| 5416 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 5417 | uint8_t *buff) |
| 5418 | { |
| 5419 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 5420 | struct lpfc_fcoe_params *fcoe_param; |
| 5421 | |
| 5422 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 5423 | buff; |
| 5424 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5425 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5426 | |
| 5427 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 5428 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 5429 | return; |
| 5430 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5431 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 5432 | phba->valid_vlan = 1; |
| 5433 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 5434 | 0xFFF; |
| 5435 | } |
| 5436 | |
| 5437 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 5438 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 5439 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 5440 | return; |
| 5441 | } |
| 5442 | |
| 5443 | /** |
| 5444 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 5445 | * @buff: Buffer containing config region 23 data. |
| 5446 | * @size: Size of the data buffer. |
| 5447 | * @rec_type: Record type to be searched. |
| 5448 | * |
| 5449 | * This function searches config region data to find the begining |
| 5450 | * of the record specified by record_type. If record found, this |
| 5451 | * function return pointer to the record else return NULL. |
| 5452 | */ |
| 5453 | static uint8_t * |
| 5454 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 5455 | { |
| 5456 | uint32_t offset = 0, rec_length; |
| 5457 | |
| 5458 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 5459 | (size < sizeof(uint32_t))) |
| 5460 | return NULL; |
| 5461 | |
| 5462 | rec_length = buff[offset + 1]; |
| 5463 | |
| 5464 | /* |
| 5465 | * One TLV record has one word header and number of data words |
| 5466 | * specified in the rec_length field of the record header. |
| 5467 | */ |
| 5468 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 5469 | <= size) { |
| 5470 | if (buff[offset] == rec_type) |
| 5471 | return &buff[offset]; |
| 5472 | |
| 5473 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 5474 | return NULL; |
| 5475 | |
| 5476 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 5477 | rec_length = buff[offset + 1]; |
| 5478 | } |
| 5479 | return NULL; |
| 5480 | } |
| 5481 | |
| 5482 | /** |
| 5483 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 5484 | * @phba: Pointer to lpfc_hba data structure. |
| 5485 | * @buff: Buffer containing config region 23 data. |
| 5486 | * @size: Size of the data buffer. |
| 5487 | * |
| 5488 | * This fuction parse the FCoE config parameters in config region 23 and |
| 5489 | * populate driver data structure with the parameters. |
| 5490 | */ |
| 5491 | void |
| 5492 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 5493 | uint8_t *buff, |
| 5494 | uint32_t size) |
| 5495 | { |
| 5496 | uint32_t offset = 0, rec_length; |
| 5497 | uint8_t *rec_ptr; |
| 5498 | |
| 5499 | /* |
| 5500 | * If data size is less than 2 words signature and version cannot be |
| 5501 | * verified. |
| 5502 | */ |
| 5503 | if (size < 2*sizeof(uint32_t)) |
| 5504 | return; |
| 5505 | |
| 5506 | /* Check the region signature first */ |
| 5507 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 5508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5509 | "2567 Config region 23 has bad signature\n"); |
| 5510 | return; |
| 5511 | } |
| 5512 | |
| 5513 | offset += 4; |
| 5514 | |
| 5515 | /* Check the data structure version */ |
| 5516 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 5517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5518 | "2568 Config region 23 has bad version\n"); |
| 5519 | return; |
| 5520 | } |
| 5521 | offset += 4; |
| 5522 | |
| 5523 | rec_length = buff[offset + 1]; |
| 5524 | |
| 5525 | /* Read FCoE param record */ |
| 5526 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5527 | size - offset, FCOE_PARAM_TYPE); |
| 5528 | if (rec_ptr) |
| 5529 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 5530 | |
| 5531 | /* Read FCF connection table */ |
| 5532 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5533 | size - offset, FCOE_CONN_TBL_TYPE); |
| 5534 | if (rec_ptr) |
| 5535 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 5536 | |
| 5537 | } |