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