| 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, |
| 1625 | sizeof(struct fcf_record)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1626 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1627 | return new_fcf_record; |
| 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record |
| 1632 | * @phba: pointer to lpfc hba data structure. |
| 1633 | * @fcf_record: pointer to the fcf record. |
| 1634 | * @vlan_id: the lowest vlan identifier associated to this fcf record. |
| 1635 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. |
| 1636 | * |
| 1637 | * This routine logs the detailed FCF record if the LOG_FIP loggin is |
| 1638 | * enabled. |
| 1639 | **/ |
| 1640 | static void |
| 1641 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, |
| 1642 | struct fcf_record *fcf_record, |
| 1643 | uint16_t vlan_id, |
| 1644 | uint16_t next_fcf_index) |
| 1645 | { |
| 1646 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 1647 | "2764 READ_FCF_RECORD:\n" |
| 1648 | "\tFCF_Index : x%x\n" |
| 1649 | "\tFCF_Avail : x%x\n" |
| 1650 | "\tFCF_Valid : x%x\n" |
| 1651 | "\tFIP_Priority : x%x\n" |
| 1652 | "\tMAC_Provider : x%x\n" |
| 1653 | "\tLowest VLANID : x%x\n" |
| 1654 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" |
| 1655 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1656 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" |
| 1657 | "\tNext_FCF_Index: x%x\n", |
| 1658 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), |
| 1659 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), |
| 1660 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), |
| 1661 | fcf_record->fip_priority, |
| 1662 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), |
| 1663 | vlan_id, |
| 1664 | bf_get(lpfc_fcf_record_mac_0, fcf_record), |
| 1665 | bf_get(lpfc_fcf_record_mac_1, fcf_record), |
| 1666 | bf_get(lpfc_fcf_record_mac_2, fcf_record), |
| 1667 | bf_get(lpfc_fcf_record_mac_3, fcf_record), |
| 1668 | bf_get(lpfc_fcf_record_mac_4, fcf_record), |
| 1669 | bf_get(lpfc_fcf_record_mac_5, fcf_record), |
| 1670 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), |
| 1671 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), |
| 1672 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), |
| 1673 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), |
| 1674 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), |
| 1675 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), |
| 1676 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), |
| 1677 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), |
| 1678 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), |
| 1679 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), |
| 1680 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), |
| 1681 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), |
| 1682 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), |
| 1683 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), |
| 1684 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), |
| 1685 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), |
| 1686 | next_fcf_index); |
| 1687 | } |
| 1688 | |
| 1689 | /** |
| 1690 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. |
| 1691 | * @phba: pointer to lpfc hba data structure. |
| 1692 | * @mboxq: pointer to mailbox object. |
| 1693 | * |
| 1694 | * This function iterates through all the fcf records available in |
| 1695 | * HBA and chooses the optimal FCF record for discovery. After finding |
| 1696 | * the FCF for discovery it registers the FCF record and kicks start |
| 1697 | * discovery. |
| 1698 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to |
| 1699 | * use an FCF record which matches fabric name and mac address of the |
| 1700 | * currently used FCF record. |
| 1701 | * If the driver supports only one FCF, it will try to use the FCF record |
| 1702 | * used by BOOT_BIOS. |
| 1703 | */ |
| 1704 | void |
| 1705 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1706 | { |
| 1707 | struct fcf_record *new_fcf_record; |
| 1708 | uint32_t boot_flag, addr_mode; |
| 1709 | uint16_t fcf_index, next_fcf_index; |
| 1710 | struct lpfc_fcf_rec *fcf_rec = NULL; |
| 1711 | uint16_t vlan_id; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame^] | 1712 | uint32_t seed; |
| 1713 | bool select_new_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1714 | int rc; |
| 1715 | |
| 1716 | /* If there is pending FCoE event restart FCF table scan */ |
| 1717 | if (lpfc_check_pending_fcoe_event(phba, 0)) { |
| 1718 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1719 | return; |
| 1720 | } |
| 1721 | |
| 1722 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 1723 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 1724 | &next_fcf_index); |
| 1725 | if (!new_fcf_record) { |
| 1726 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1727 | "2765 Mailbox command READ_FCF_RECORD " |
| 1728 | "failed to retrieve a FCF record.\n"); |
| 1729 | /* Let next new FCF event trigger fast failover */ |
| 1730 | spin_lock_irq(&phba->hbalock); |
| 1731 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
| 1732 | spin_unlock_irq(&phba->hbalock); |
| 1733 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1734 | return; |
| 1735 | } |
| 1736 | |
| 1737 | /* Check the FCF record against the connection list */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1738 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 1739 | &addr_mode, &vlan_id); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1740 | |
| 1741 | /* Log the FCF record information if turned on */ |
| 1742 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 1743 | next_fcf_index); |
| 1744 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1745 | /* |
| 1746 | * If the fcf record does not match with connect list entries |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1747 | * read the next entry; otherwise, this is an eligible FCF |
| 1748 | * record for round robin FCF failover. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1749 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1750 | if (!rc) { |
| 1751 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1752 | "2781 FCF record fcf_index:x%x failed FCF " |
| 1753 | "connection list check, fcf_avail:x%x, " |
| 1754 | "fcf_valid:x%x\n", |
| 1755 | bf_get(lpfc_fcf_record_fcf_index, |
| 1756 | new_fcf_record), |
| 1757 | bf_get(lpfc_fcf_record_fcf_avail, |
| 1758 | new_fcf_record), |
| 1759 | bf_get(lpfc_fcf_record_fcf_valid, |
| 1760 | new_fcf_record)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1761 | goto read_next_fcf; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1762 | } else { |
| 1763 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1764 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 1765 | if (rc) |
| 1766 | goto read_next_fcf; |
| 1767 | } |
| 1768 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1769 | /* |
| 1770 | * 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] | 1771 | * FCF record for the discovery. The condition that a rescan |
| 1772 | * matches the in-use FCF record: fabric name, switch name, mac |
| 1773 | * address, and vlan_id. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1774 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1775 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1776 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1777 | if (lpfc_fab_name_match(phba->fcf.current_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1778 | new_fcf_record) && |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1779 | lpfc_sw_name_match(phba->fcf.current_rec.switch_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_mac_addr_match(phba->fcf.current_rec.mac_addr, |
| 1782 | new_fcf_record) && |
| 1783 | lpfc_vlan_id_match(phba->fcf.current_rec.vlan_id, |
| 1784 | vlan_id)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1785 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1786 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) |
| 1787 | /* Stop FCF redisc wait timer if pending */ |
| 1788 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
| 1789 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1790 | /* If in fast failover, mark it's completed */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1791 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1792 | FCF_DISCOVERY); |
| 1793 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1794 | goto out; |
| 1795 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1796 | /* |
| 1797 | * Read next FCF record from HBA searching for the matching |
| 1798 | * with in-use record only if not during the fast failover |
| 1799 | * period. In case of fast failover period, it shall try to |
| 1800 | * determine whether the FCF record just read should be the |
| 1801 | * next candidate. |
| 1802 | */ |
| 1803 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1804 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1805 | goto read_next_fcf; |
| 1806 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1807 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1808 | /* |
| 1809 | * Update on failover FCF record only if it's in FCF fast-failover |
| 1810 | * period; otherwise, update on current FCF record. |
| 1811 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1812 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
| 1813 | fcf_rec = &phba->fcf.failover_rec; |
| 1814 | else |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1815 | fcf_rec = &phba->fcf.current_rec; |
| 1816 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1817 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 1818 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1819 | * If the driver FCF record does not have boot flag |
| 1820 | * set and new hba fcf record has boot flag set, use |
| 1821 | * the new hba fcf record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1822 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1823 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
| 1824 | /* Choose this FCF record */ |
| 1825 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1826 | addr_mode, vlan_id, BOOT_ENABLE); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1827 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1828 | goto read_next_fcf; |
| 1829 | } |
| 1830 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1831 | * If the driver FCF record has boot flag set and the |
| 1832 | * new hba FCF record does not have boot flag, read |
| 1833 | * the next FCF record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1834 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1835 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1836 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1837 | goto read_next_fcf; |
| 1838 | } |
| 1839 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1840 | * If the new hba FCF record has lower priority value |
| 1841 | * than the driver FCF record, use the new record. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1842 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 1843 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame^] | 1844 | /* Choose the new FCF record with lower priority */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1845 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1846 | addr_mode, vlan_id, 0); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame^] | 1847 | /* Reset running random FCF selection count */ |
| 1848 | phba->fcf.eligible_fcf_cnt = 1; |
| 1849 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { |
| 1850 | /* Update running random FCF selection count */ |
| 1851 | phba->fcf.eligible_fcf_cnt++; |
| 1852 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, |
| 1853 | phba->fcf.eligible_fcf_cnt); |
| 1854 | if (select_new_fcf) |
| 1855 | /* Choose the new FCF by random selection */ |
| 1856 | __lpfc_update_fcf_record(phba, fcf_rec, |
| 1857 | new_fcf_record, |
| 1858 | addr_mode, vlan_id, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1859 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1860 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1861 | goto read_next_fcf; |
| 1862 | } |
| 1863 | /* |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1864 | * This is the first suitable FCF record, choose this record for |
| 1865 | * initial best-fit FCF. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1866 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1867 | if (fcf_rec) { |
| 1868 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
| 1869 | addr_mode, vlan_id, (boot_flag ? |
| 1870 | BOOT_ENABLE : 0)); |
| 1871 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame^] | 1872 | /* Setup initial running random FCF selection count */ |
| 1873 | phba->fcf.eligible_fcf_cnt = 1; |
| 1874 | /* Seeding the random number generator for random selection */ |
| 1875 | seed = (uint32_t)(0xFFFFFFFF & jiffies); |
| 1876 | srandom32(seed); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1877 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1878 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1879 | goto read_next_fcf; |
| 1880 | |
| 1881 | read_next_fcf: |
| 1882 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1883 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
| 1884 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { |
| 1885 | /* |
| 1886 | * Case of FCF fast failover scan |
| 1887 | */ |
| 1888 | |
| 1889 | /* |
| 1890 | * It has not found any suitable FCF record, cancel |
| 1891 | * FCF scan inprogress, and do nothing |
| 1892 | */ |
| 1893 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1894 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 1895 | "2782 No suitable FCF record " |
| 1896 | "found during this round of " |
| 1897 | "post FCF rediscovery scan: " |
| 1898 | "fcf_evt_tag:x%x, fcf_index: " |
| 1899 | "x%x\n", |
| 1900 | phba->fcoe_eventtag_at_fcf_scan, |
| 1901 | bf_get(lpfc_fcf_record_fcf_index, |
| 1902 | new_fcf_record)); |
| 1903 | /* |
| 1904 | * Let next new FCF event trigger fast |
| 1905 | * failover |
| 1906 | */ |
| 1907 | spin_lock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1908 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1909 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1910 | return; |
| 1911 | } |
| 1912 | /* |
| 1913 | * It has found a suitable FCF record that is not |
| 1914 | * the same as in-use FCF record, unregister the |
| 1915 | * in-use FCF record, replace the in-use FCF record |
| 1916 | * with the new FCF record, mark FCF fast failover |
| 1917 | * completed, and then start register the new FCF |
| 1918 | * record. |
| 1919 | */ |
| 1920 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1921 | /* Unregister the current in-use FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1922 | lpfc_unregister_fcf(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1923 | |
| 1924 | /* Replace in-use record with the new record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1925 | memcpy(&phba->fcf.current_rec, |
| 1926 | &phba->fcf.failover_rec, |
| 1927 | sizeof(struct lpfc_fcf_rec)); |
| 1928 | /* mark the FCF fast failover completed */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1929 | spin_lock_irq(&phba->hbalock); |
| 1930 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
| 1931 | spin_unlock_irq(&phba->hbalock); |
| 1932 | /* |
| 1933 | * Set up the initial registered FCF index for FLOGI |
| 1934 | * round robin FCF failover. |
| 1935 | */ |
| 1936 | phba->fcf.fcf_rr_init_indx = |
| 1937 | phba->fcf.failover_rec.fcf_indx; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1938 | /* Register to the new FCF record */ |
| 1939 | lpfc_register_fcf(phba); |
| 1940 | } else { |
| 1941 | /* |
| 1942 | * In case of transaction period to fast FCF failover, |
| 1943 | * do nothing when search to the end of the FCF table. |
| 1944 | */ |
| 1945 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || |
| 1946 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) |
| 1947 | return; |
| 1948 | /* |
| 1949 | * Otherwise, initial scan or post linkdown rescan, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1950 | * register with the best FCF record found so far |
| 1951 | * through the FCF scanning process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1952 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1953 | |
| 1954 | /* mark the initial FCF discovery completed */ |
| 1955 | spin_lock_irq(&phba->hbalock); |
| 1956 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 1957 | spin_unlock_irq(&phba->hbalock); |
| 1958 | /* |
| 1959 | * Set up the initial registered FCF index for FLOGI |
| 1960 | * round robin FCF failover |
| 1961 | */ |
| 1962 | phba->fcf.fcf_rr_init_indx = |
| 1963 | phba->fcf.current_rec.fcf_indx; |
| 1964 | /* Register to the new FCF record */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1965 | lpfc_register_fcf(phba); |
| 1966 | } |
| 1967 | } else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1968 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1969 | return; |
| 1970 | |
| 1971 | out: |
| 1972 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1973 | lpfc_register_fcf(phba); |
| 1974 | |
| 1975 | return; |
| 1976 | } |
| 1977 | |
| 1978 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1979 | * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler |
| 1980 | * @phba: pointer to lpfc hba data structure. |
| 1981 | * @mboxq: pointer to mailbox object. |
| 1982 | * |
| 1983 | * This is the callback function for FLOGI failure round robin FCF failover |
| 1984 | * read FCF record mailbox command from the eligible FCF record bmask for |
| 1985 | * performing the failover. If the FCF read back is not valid/available, it |
| 1986 | * fails through to retrying FLOGI to the currently registered FCF again. |
| 1987 | * Otherwise, if the FCF read back is valid and available, it will set the |
| 1988 | * newly read FCF record to the failover FCF record, unregister currently |
| 1989 | * registered FCF record, copy the failover FCF record to the current |
| 1990 | * FCF record, and then register the current FCF record before proceeding |
| 1991 | * to trying FLOGI on the new failover FCF. |
| 1992 | */ |
| 1993 | void |
| 1994 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1995 | { |
| 1996 | struct fcf_record *new_fcf_record; |
| 1997 | uint32_t boot_flag, addr_mode; |
| 1998 | uint16_t next_fcf_index; |
| 1999 | uint16_t current_fcf_index; |
| 2000 | uint16_t vlan_id; |
| 2001 | |
| 2002 | /* If link state is not up, stop the round robin failover process */ |
| 2003 | if (phba->link_state < LPFC_LINK_UP) { |
| 2004 | spin_lock_irq(&phba->hbalock); |
| 2005 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 2006 | spin_unlock_irq(&phba->hbalock); |
| 2007 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2008 | return; |
| 2009 | } |
| 2010 | |
| 2011 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2012 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2013 | &next_fcf_index); |
| 2014 | if (!new_fcf_record) { |
| 2015 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 2016 | "2766 Mailbox command READ_FCF_RECORD " |
| 2017 | "failed to retrieve a FCF record.\n"); |
| 2018 | goto out; |
| 2019 | } |
| 2020 | |
| 2021 | /* Get the needed parameters from FCF record */ |
| 2022 | lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2023 | &addr_mode, &vlan_id); |
| 2024 | |
| 2025 | /* Log the FCF record information if turned on */ |
| 2026 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2027 | next_fcf_index); |
| 2028 | |
| 2029 | /* Upload new FCF record to the failover FCF record */ |
| 2030 | spin_lock_irq(&phba->hbalock); |
| 2031 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, |
| 2032 | new_fcf_record, addr_mode, vlan_id, |
| 2033 | (boot_flag ? BOOT_ENABLE : 0)); |
| 2034 | spin_unlock_irq(&phba->hbalock); |
| 2035 | |
| 2036 | current_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 2037 | |
| 2038 | /* Unregister the current in-use FCF record */ |
| 2039 | lpfc_unregister_fcf(phba); |
| 2040 | |
| 2041 | /* Replace in-use record with the new record */ |
| 2042 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, |
| 2043 | sizeof(struct lpfc_fcf_rec)); |
| 2044 | |
| 2045 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2046 | "2783 FLOGI round robin FCF failover from FCF " |
| 2047 | "(index:x%x) to FCF (index:x%x).\n", |
| 2048 | current_fcf_index, |
| 2049 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record)); |
| 2050 | |
| 2051 | out: |
| 2052 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2053 | lpfc_register_fcf(phba); |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. |
| 2058 | * @phba: pointer to lpfc hba data structure. |
| 2059 | * @mboxq: pointer to mailbox object. |
| 2060 | * |
| 2061 | * This is the callback function of read FCF record mailbox command for |
| 2062 | * updating the eligible FCF bmask for FLOGI failure round robin FCF |
| 2063 | * failover when a new FCF event happened. If the FCF read back is |
| 2064 | * valid/available and it passes the connection list check, it updates |
| 2065 | * the bmask for the eligible FCF record for round robin failover. |
| 2066 | */ |
| 2067 | void |
| 2068 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2069 | { |
| 2070 | struct fcf_record *new_fcf_record; |
| 2071 | uint32_t boot_flag, addr_mode; |
| 2072 | uint16_t fcf_index, next_fcf_index; |
| 2073 | uint16_t vlan_id; |
| 2074 | int rc; |
| 2075 | |
| 2076 | /* If link state is not up, no need to proceed */ |
| 2077 | if (phba->link_state < LPFC_LINK_UP) |
| 2078 | goto out; |
| 2079 | |
| 2080 | /* If FCF discovery period is over, no need to proceed */ |
| 2081 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) |
| 2082 | goto out; |
| 2083 | |
| 2084 | /* Parse the FCF record from the non-embedded mailbox command */ |
| 2085 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, |
| 2086 | &next_fcf_index); |
| 2087 | if (!new_fcf_record) { |
| 2088 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 2089 | "2767 Mailbox command READ_FCF_RECORD " |
| 2090 | "failed to retrieve a FCF record.\n"); |
| 2091 | goto out; |
| 2092 | } |
| 2093 | |
| 2094 | /* Check the connection list for eligibility */ |
| 2095 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
| 2096 | &addr_mode, &vlan_id); |
| 2097 | |
| 2098 | /* Log the FCF record information if turned on */ |
| 2099 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, |
| 2100 | next_fcf_index); |
| 2101 | |
| 2102 | if (!rc) |
| 2103 | goto out; |
| 2104 | |
| 2105 | /* Update the eligible FCF record index bmask */ |
| 2106 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 2107 | rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index); |
| 2108 | |
| 2109 | out: |
| 2110 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2111 | } |
| 2112 | |
| 2113 | /** |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2114 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. |
| 2115 | * @phba: pointer to lpfc hba data structure. |
| 2116 | * @mboxq: pointer to mailbox data structure. |
| 2117 | * |
| 2118 | * This function handles completion of init vpi mailbox command. |
| 2119 | */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2120 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2121 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2122 | { |
| 2123 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2124 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2125 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2126 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2127 | if (mboxq->u.mb.mbxStatus) { |
| 2128 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2129 | LOG_MBOX, |
| 2130 | "2609 Init VPI mailbox failed 0x%x\n", |
| 2131 | mboxq->u.mb.mbxStatus); |
| 2132 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2133 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2134 | return; |
| 2135 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2136 | spin_lock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2137 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2138 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2139 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2140 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
| 2141 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { |
| 2142 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 2143 | if (!ndlp) |
| 2144 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2145 | LOG_DISCOVERY, |
| 2146 | "2731 Cannot find fabric " |
| 2147 | "controller node\n"); |
| 2148 | else |
| 2149 | lpfc_register_new_vport(phba, vport, ndlp); |
| 2150 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2151 | return; |
| 2152 | } |
| 2153 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2154 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2155 | lpfc_initial_fdisc(vport); |
| 2156 | else { |
| 2157 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2158 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2159 | "2606 No NPIV Fabric support\n"); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2160 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2161 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2162 | return; |
| 2163 | } |
| 2164 | |
| 2165 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2166 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. |
| 2167 | * @vport: pointer to lpfc_vport data structure. |
| 2168 | * |
| 2169 | * This function issue a init_vpi mailbox command to initialize |
| 2170 | * VPI for the vport. |
| 2171 | */ |
| 2172 | void |
| 2173 | lpfc_issue_init_vpi(struct lpfc_vport *vport) |
| 2174 | { |
| 2175 | LPFC_MBOXQ_t *mboxq; |
| 2176 | int rc; |
| 2177 | |
| 2178 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); |
| 2179 | if (!mboxq) { |
| 2180 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2181 | LOG_MBOX, "2607 Failed to allocate " |
| 2182 | "init_vpi mailbox\n"); |
| 2183 | return; |
| 2184 | } |
| 2185 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); |
| 2186 | mboxq->vport = vport; |
| 2187 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 2188 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); |
| 2189 | if (rc == MBX_NOT_FINISHED) { |
| 2190 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2191 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); |
| 2192 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2197 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 2198 | * @phba: pointer to lpfc hba data structure. |
| 2199 | * |
| 2200 | * This function loops through the list of vports on the @phba and issues an |
| 2201 | * FDISC if possible. |
| 2202 | */ |
| 2203 | void |
| 2204 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 2205 | { |
| 2206 | struct lpfc_vport **vports; |
| 2207 | int i; |
| 2208 | |
| 2209 | vports = lpfc_create_vport_work_array(phba); |
| 2210 | if (vports != NULL) { |
| 2211 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2212 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 2213 | continue; |
| 2214 | /* There are no vpi for this vport */ |
| 2215 | if (vports[i]->vpi > phba->max_vpi) { |
| 2216 | lpfc_vport_set_state(vports[i], |
| 2217 | FC_VPORT_FAILED); |
| 2218 | continue; |
| 2219 | } |
| 2220 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2221 | lpfc_vport_set_state(vports[i], |
| 2222 | FC_VPORT_LINKDOWN); |
| 2223 | continue; |
| 2224 | } |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2225 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2226 | lpfc_issue_init_vpi(vports[i]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2227 | continue; |
| 2228 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2229 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 2230 | lpfc_initial_fdisc(vports[i]); |
| 2231 | else { |
| 2232 | lpfc_vport_set_state(vports[i], |
| 2233 | FC_VPORT_NO_FABRIC_SUPP); |
| 2234 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 2235 | LOG_ELS, |
| 2236 | "0259 No NPIV " |
| 2237 | "Fabric support\n"); |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | lpfc_destroy_vport_work_array(phba, vports); |
| 2242 | } |
| 2243 | |
| 2244 | void |
| 2245 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2246 | { |
| 2247 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 2248 | struct lpfc_vport *vport = mboxq->vport; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2249 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2250 | |
| 2251 | if (mboxq->u.mb.mbxStatus) { |
| 2252 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2253 | "2018 REG_VFI mbxStatus error x%x " |
| 2254 | "HBA state x%x\n", |
| 2255 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 2256 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2257 | /* FLOGI failed, use loop map to make discovery list */ |
| 2258 | lpfc_disc_list_loopmap(vport); |
| 2259 | /* Start discovery */ |
| 2260 | lpfc_disc_start(vport); |
| 2261 | goto fail_free_mem; |
| 2262 | } |
| 2263 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2264 | goto fail_free_mem; |
| 2265 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2266 | /* The VPI is implicitly registered when the VFI is registered */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2267 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2268 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2269 | vport->fc_flag |= FC_VFI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2270 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2271 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2272 | |
| 2273 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
| 2274 | lpfc_start_fdiscs(phba); |
| 2275 | lpfc_do_scr_ns_plogi(phba, vport); |
| 2276 | } |
| 2277 | |
| 2278 | fail_free_mem: |
| 2279 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 2280 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2281 | kfree(dmabuf); |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2286 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2288 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2290 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | |
| 2292 | |
| 2293 | /* Check for error */ |
| 2294 | if (mb->mbxStatus) { |
| 2295 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2296 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2297 | "0319 READ_SPARAM mbxStatus error x%x " |
| 2298 | "hba state x%x>\n", |
| 2299 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | goto out; |
| 2302 | } |
| 2303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | sizeof (struct serv_parm)); |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 2306 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2307 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 2308 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 2309 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 2311 | vport->fc_sparam.portName.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2312 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 2313 | sizeof(vport->fc_nodename)); |
| 2314 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 2315 | sizeof(vport->fc_portname)); |
| 2316 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 2317 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 2318 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 2319 | } |
| 2320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2322 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2323 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | return; |
| 2325 | |
| 2326 | out: |
| 2327 | pmb->context1 = NULL; |
| 2328 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2329 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2330 | lpfc_issue_clear_la(phba, vport); |
| 2331 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | return; |
| 2333 | } |
| 2334 | |
| 2335 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2336 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2338 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2339 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2340 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2341 | struct lpfc_dmabuf *mp; |
| 2342 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2343 | struct fcf_record *fcf_record; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2344 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2345 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2346 | switch (la->UlnkSpeed) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | case LA_1GHZ_LINK: |
| 2348 | phba->fc_linkspeed = LA_1GHZ_LINK; |
| 2349 | break; |
| 2350 | case LA_2GHZ_LINK: |
| 2351 | phba->fc_linkspeed = LA_2GHZ_LINK; |
| 2352 | break; |
| 2353 | case LA_4GHZ_LINK: |
| 2354 | phba->fc_linkspeed = LA_4GHZ_LINK; |
| 2355 | break; |
| 2356 | case LA_8GHZ_LINK: |
| 2357 | phba->fc_linkspeed = LA_8GHZ_LINK; |
| 2358 | break; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2359 | case LA_10GHZ_LINK: |
| 2360 | phba->fc_linkspeed = LA_10GHZ_LINK; |
| 2361 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2362 | default: |
| 2363 | phba->fc_linkspeed = LA_UNKNW_LINK; |
| 2364 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | phba->fc_topology = la->topology; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2368 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | |
| 2370 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2371 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2373 | /* if npiv is enabled and this adapter supports npiv log |
| 2374 | * a message that npiv is not supported in this topology |
| 2375 | */ |
| 2376 | if (phba->cfg_enable_npiv && phba->max_vpi) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2377 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2378 | "1309 Link Up Event npiv not supported in loop " |
| 2379 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2380 | /* Get Loop Map information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | if (la->il) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2384 | vport->fc_myDID = la->granted_AL_PA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | i = la->un.lilpBde64.tus.f.bdeSize; |
| 2386 | |
| 2387 | if (i == 0) { |
| 2388 | phba->alpa_map[0] = 0; |
| 2389 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2390 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | int numalpa, j, k; |
| 2392 | union { |
| 2393 | uint8_t pamap[16]; |
| 2394 | struct { |
| 2395 | uint32_t wd1; |
| 2396 | uint32_t wd2; |
| 2397 | uint32_t wd3; |
| 2398 | uint32_t wd4; |
| 2399 | } pa; |
| 2400 | } un; |
| 2401 | numalpa = phba->alpa_map[0]; |
| 2402 | j = 0; |
| 2403 | while (j < numalpa) { |
| 2404 | memset(un.pamap, 0, 16); |
| 2405 | for (k = 1; j < numalpa; k++) { |
| 2406 | un.pamap[k - 1] = |
| 2407 | phba->alpa_map[j + 1]; |
| 2408 | j++; |
| 2409 | if (k == 16) |
| 2410 | break; |
| 2411 | } |
| 2412 | /* Link Up Event ALPA map */ |
| 2413 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | KERN_WARNING, |
| 2415 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2416 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2417 | "ALPA map Data: x%x " |
| 2418 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2419 | un.pa.wd1, un.pa.wd2, |
| 2420 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | } |
| 2424 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2425 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2426 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2427 | (phba->sli_rev == 3)) |
| 2428 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 2429 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2430 | vport->fc_myDID = phba->fc_pref_DID; |
| 2431 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2432 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2433 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | |
| 2435 | lpfc_linkup(phba); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 2436 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2437 | if (!sparam_mbox) |
| 2438 | goto out; |
| 2439 | |
| 2440 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); |
| 2441 | if (rc) { |
| 2442 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2443 | goto out; |
| 2444 | } |
| 2445 | sparam_mbox->vport = vport; |
| 2446 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
| 2447 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
| 2448 | if (rc == MBX_NOT_FINISHED) { |
| 2449 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 2450 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2451 | kfree(mp); |
| 2452 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 2453 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | } |
| 2455 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2456 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) { |
| 2457 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2458 | if (!cfglink_mbox) |
| 2459 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2462 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 2463 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2464 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2465 | if (rc == MBX_NOT_FINISHED) { |
| 2466 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 2467 | goto out; |
| 2468 | } |
| 2469 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2470 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2471 | /* |
| 2472 | * Add the driver's default FCF record at FCF index 0 now. This |
| 2473 | * is phase 1 implementation that support FCF index 0 and driver |
| 2474 | * defaults. |
| 2475 | */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2476 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2477 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 2478 | GFP_KERNEL); |
| 2479 | if (unlikely(!fcf_record)) { |
| 2480 | lpfc_printf_log(phba, KERN_ERR, |
| 2481 | LOG_MBOX | LOG_SLI, |
| 2482 | "2554 Could not allocate memmory for " |
| 2483 | "fcf record\n"); |
| 2484 | rc = -ENODEV; |
| 2485 | goto out; |
| 2486 | } |
| 2487 | |
| 2488 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 2489 | LPFC_FCOE_FCF_DEF_INDEX); |
| 2490 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 2491 | if (unlikely(rc)) { |
| 2492 | lpfc_printf_log(phba, KERN_ERR, |
| 2493 | LOG_MBOX | LOG_SLI, |
| 2494 | "2013 Could not manually add FCF " |
| 2495 | "record 0, status %d\n", rc); |
| 2496 | rc = -ENODEV; |
| 2497 | kfree(fcf_record); |
| 2498 | goto out; |
| 2499 | } |
| 2500 | kfree(fcf_record); |
| 2501 | } |
| 2502 | /* |
| 2503 | * The driver is expected to do FIP/FCF. Call the port |
| 2504 | * and get the FCF Table. |
| 2505 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2506 | spin_lock_irq(&phba->hbalock); |
| 2507 | if (phba->hba_flag & FCF_DISC_INPROGRESS) { |
| 2508 | spin_unlock_irq(&phba->hbalock); |
| 2509 | return; |
| 2510 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2511 | /* This is the initial FCF discovery scan */ |
| 2512 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 2513 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2514 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 2515 | "2778 Start FCF table scan at linkup\n"); |
| 2516 | |
| 2517 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 2518 | LPFC_FCOE_FCF_GET_FIRST); |
| 2519 | if (rc) { |
| 2520 | spin_lock_irq(&phba->hbalock); |
| 2521 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 2522 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2523 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2524 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2526 | |
| 2527 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2528 | out: |
| 2529 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2530 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2531 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 2532 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2533 | lpfc_issue_clear_la(phba, vport); |
| 2534 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2538 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | uint32_t control; |
| 2541 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2542 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2544 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 2545 | control = readl(phba->HCregaddr); |
| 2546 | control |= HC_LAINT_ENA; |
| 2547 | writel(control, phba->HCregaddr); |
| 2548 | readl(phba->HCregaddr); /* flush */ |
| 2549 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2550 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2551 | } |
| 2552 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2553 | static void |
| 2554 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 2555 | { |
| 2556 | lpfc_linkdown(phba); |
| 2557 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2558 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2559 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 2560 | } |
| 2561 | |
| 2562 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2563 | /* |
| 2564 | * This routine handles processing a READ_LA mailbox |
| 2565 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2566 | * as the completion routine when the command is |
| 2567 | * handed off to the SLI layer. |
| 2568 | */ |
| 2569 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2572 | struct lpfc_vport *vport = pmb->vport; |
| 2573 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | READ_LA_VAR *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2575 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2577 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2578 | /* Unblock ELS traffic */ |
| 2579 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | /* Check for error */ |
| 2581 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2582 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2583 | "1307 READ_LA mbox error x%x state x%x\n", |
| 2584 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2585 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2586 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 2588 | } |
| 2589 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2590 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | |
| 2592 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 2593 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2594 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2595 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2596 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2597 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 2599 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2600 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 2601 | if ((phba->fc_eventTag < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2602 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2605 | if (phba->fc_eventTag != 0) |
| 2606 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2607 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | |
| 2609 | phba->fc_eventTag = la->eventTag; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2610 | spin_lock_irq(&phba->hbalock); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2611 | if (la->mm) |
| 2612 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 2613 | else |
| 2614 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2615 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2617 | phba->link_events++; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2618 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2620 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2621 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2622 | "1306 Link Up Event in loop back mode " |
| 2623 | "x%x received Data: x%x x%x x%x x%x\n", |
| 2624 | la->eventTag, phba->fc_eventTag, |
| 2625 | la->granted_AL_PA, la->UlnkSpeed, |
| 2626 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2627 | } else { |
| 2628 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2629 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2630 | "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] | 2631 | la->eventTag, phba->fc_eventTag, |
| 2632 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2633 | phba->alpa_map[0], |
| 2634 | la->mm, la->fa, |
| 2635 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2636 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2637 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2638 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2640 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 2641 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2642 | "1308 Link Down Event in loop back mode " |
| 2643 | "x%x received " |
| 2644 | "Data: x%x x%x x%x\n", |
| 2645 | la->eventTag, phba->fc_eventTag, |
| 2646 | phba->pport->port_state, vport->fc_flag); |
| 2647 | } |
| 2648 | else { |
| 2649 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2650 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2651 | "Data: x%x x%x x%x x%x x%x\n", |
| 2652 | la->eventTag, phba->fc_eventTag, |
| 2653 | phba->pport->port_state, vport->fc_flag, |
| 2654 | la->mm, la->fa); |
| 2655 | } |
| 2656 | lpfc_mbx_issue_link_down(phba); |
| 2657 | } |
| 2658 | if (la->mm && la->attType == AT_LINK_UP) { |
| 2659 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 2660 | phba->fc_stat.LinkDown++; |
| 2661 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2662 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2664 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2666 | lpfc_mbx_issue_link_down(phba); |
| 2667 | } else |
| 2668 | lpfc_enable_la(phba); |
| 2669 | |
| 2670 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2671 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 2672 | "Data: x%x x%x x%x\n", |
| 2673 | la->eventTag, phba->fc_eventTag, |
| 2674 | phba->pport->port_state, vport->fc_flag); |
| 2675 | /* |
| 2676 | * The cmnd that triggered this will be waiting for this |
| 2677 | * signal. |
| 2678 | */ |
| 2679 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 2680 | if (phba->wait_4_mlo_maint_flg) { |
| 2681 | phba->wait_4_mlo_maint_flg = 0; |
| 2682 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2683 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | if (la->fa) { |
| 2687 | if (la->mm) |
| 2688 | lpfc_issue_clear_la(phba, vport); |
| 2689 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 2690 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 2694 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2695 | kfree(mp); |
| 2696 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2697 | return; |
| 2698 | } |
| 2699 | |
| 2700 | /* |
| 2701 | * This routine handles processing a REG_LOGIN mailbox |
| 2702 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2703 | * as the completion routine when the command is |
| 2704 | * handed off to the SLI layer. |
| 2705 | */ |
| 2706 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2710 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2711 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2713 | pmb->context1 = NULL; |
| 2714 | |
| 2715 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2716 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2718 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2719 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2720 | /* decrement the node reference count held for this callback |
| 2721 | * function. |
| 2722 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2723 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | |
| 2725 | return; |
| 2726 | } |
| 2727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2728 | static void |
| 2729 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2730 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2731 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2732 | struct lpfc_vport *vport = pmb->vport; |
| 2733 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2734 | |
| 2735 | switch (mb->mbxStatus) { |
| 2736 | case 0x0011: |
| 2737 | case 0x0020: |
| 2738 | case 0x9700: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2739 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2740 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 2741 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2742 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | } |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2744 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2745 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 2746 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2747 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2748 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 2749 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2750 | /* |
| 2751 | * This shost reference might have been taken at the beginning of |
| 2752 | * lpfc_vport_delete() |
| 2753 | */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2754 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2755 | scsi_host_put(shost); |
| 2756 | } |
| 2757 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2758 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2759 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 2760 | { |
| 2761 | struct lpfc_hba *phba = vport->phba; |
| 2762 | LPFC_MBOXQ_t *mbox; |
| 2763 | int rc; |
| 2764 | |
| 2765 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2766 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2767 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2768 | |
| 2769 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 2770 | mbox->vport = vport; |
| 2771 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2772 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2774 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2775 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2776 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2777 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2778 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2779 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2780 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | static void |
| 2784 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2785 | { |
| 2786 | struct lpfc_vport *vport = pmb->vport; |
| 2787 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2788 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2789 | |
| 2790 | switch (mb->mbxStatus) { |
| 2791 | case 0x0011: |
| 2792 | case 0x9601: |
| 2793 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2794 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2795 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 2796 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2797 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2798 | spin_lock_irq(shost->host_lock); |
| 2799 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 2800 | spin_unlock_irq(shost->host_lock); |
| 2801 | vport->fc_myDID = 0; |
| 2802 | goto out; |
| 2803 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2804 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2805 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2806 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2807 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2808 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2809 | vport->num_disc_nodes = 0; |
| 2810 | /* go thru NPR list and issue ELS PLOGIs */ |
| 2811 | if (vport->fc_npr_cnt) |
| 2812 | lpfc_els_disc_plogi(vport); |
| 2813 | |
| 2814 | if (!vport->num_disc_nodes) { |
| 2815 | spin_lock_irq(shost->host_lock); |
| 2816 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2817 | spin_unlock_irq(shost->host_lock); |
| 2818 | lpfc_can_disctmo(vport); |
| 2819 | } |
| 2820 | vport->port_state = LPFC_VPORT_READY; |
| 2821 | |
| 2822 | out: |
| 2823 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2824 | return; |
| 2825 | } |
| 2826 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2827 | /** |
| 2828 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 2829 | * @phba: pointer to lpfc hba data structure. |
| 2830 | * |
| 2831 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 2832 | * the list of static vports to be created. The function create vports |
| 2833 | * based on the information returned from the HBA. |
| 2834 | **/ |
| 2835 | void |
| 2836 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 2837 | { |
| 2838 | LPFC_MBOXQ_t *pmb = NULL; |
| 2839 | MAILBOX_t *mb; |
| 2840 | struct static_vport_info *vport_info; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2841 | int rc = 0, i; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2842 | struct fc_vport_identifiers vport_id; |
| 2843 | struct fc_vport *new_fc_vport; |
| 2844 | struct Scsi_Host *shost; |
| 2845 | struct lpfc_vport *vport; |
| 2846 | uint16_t offset = 0; |
| 2847 | uint8_t *vport_buff; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2848 | struct lpfc_dmabuf *mp; |
| 2849 | uint32_t byte_count = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2850 | |
| 2851 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2852 | if (!pmb) { |
| 2853 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2854 | "0542 lpfc_create_static_vport failed to" |
| 2855 | " allocate mailbox memory\n"); |
| 2856 | return; |
| 2857 | } |
| 2858 | |
| 2859 | mb = &pmb->u.mb; |
| 2860 | |
| 2861 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 2862 | if (!vport_info) { |
| 2863 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2864 | "0543 lpfc_create_static_vport failed to" |
| 2865 | " allocate vport_info\n"); |
| 2866 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2867 | return; |
| 2868 | } |
| 2869 | |
| 2870 | vport_buff = (uint8_t *) vport_info; |
| 2871 | do { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2872 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
| 2873 | goto out; |
| 2874 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2875 | pmb->vport = phba->pport; |
| 2876 | rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO); |
| 2877 | |
| 2878 | if ((rc != MBX_SUCCESS) || mb->mbxStatus) { |
| 2879 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2880 | "0544 lpfc_create_static_vport failed to" |
| 2881 | " issue dump mailbox command ret 0x%x " |
| 2882 | "status 0x%x\n", |
| 2883 | rc, mb->mbxStatus); |
| 2884 | goto out; |
| 2885 | } |
| 2886 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2887 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2888 | byte_count = pmb->u.mqe.un.mb_words[5]; |
| 2889 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 2890 | if (byte_count > sizeof(struct static_vport_info) - |
| 2891 | offset) |
| 2892 | byte_count = sizeof(struct static_vport_info) |
| 2893 | - offset; |
| 2894 | memcpy(vport_buff + offset, mp->virt, byte_count); |
| 2895 | offset += byte_count; |
| 2896 | } else { |
| 2897 | if (mb->un.varDmp.word_cnt > |
| 2898 | sizeof(struct static_vport_info) - offset) |
| 2899 | mb->un.varDmp.word_cnt = |
| 2900 | sizeof(struct static_vport_info) |
| 2901 | - offset; |
| 2902 | byte_count = mb->un.varDmp.word_cnt; |
| 2903 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 2904 | vport_buff + offset, |
| 2905 | byte_count); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2906 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2907 | offset += byte_count; |
| 2908 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2909 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2910 | } while (byte_count && |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2911 | offset < sizeof(struct static_vport_info)); |
| 2912 | |
| 2913 | |
| 2914 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 2915 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 2916 | != VPORT_INFO_REV)) { |
| 2917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2918 | "0545 lpfc_create_static_vport bad" |
| 2919 | " information header 0x%x 0x%x\n", |
| 2920 | le32_to_cpu(vport_info->signature), |
| 2921 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 2922 | |
| 2923 | goto out; |
| 2924 | } |
| 2925 | |
| 2926 | shost = lpfc_shost_from_vport(phba->pport); |
| 2927 | |
| 2928 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 2929 | memset(&vport_id, 0, sizeof(vport_id)); |
| 2930 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 2931 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 2932 | if (!vport_id.port_name || !vport_id.node_name) |
| 2933 | continue; |
| 2934 | |
| 2935 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 2936 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 2937 | vport_id.disable = false; |
| 2938 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 2939 | |
| 2940 | if (!new_fc_vport) { |
| 2941 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2942 | "0546 lpfc_create_static_vport failed to" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 2943 | " create vport\n"); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2944 | continue; |
| 2945 | } |
| 2946 | |
| 2947 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 2948 | vport->vport_flag |= STATIC_VPORT; |
| 2949 | } |
| 2950 | |
| 2951 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2952 | kfree(vport_info); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2953 | if (rc != MBX_TIMEOUT) { |
| 2954 | if (pmb->context2) { |
| 2955 | mp = (struct lpfc_dmabuf *) pmb->context2; |
| 2956 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2957 | kfree(mp); |
| 2958 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2959 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2960 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2961 | |
| 2962 | return; |
| 2963 | } |
| 2964 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2965 | /* |
| 2966 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 2967 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2968 | * as the completion routine when the command is |
| 2969 | * handed off to the SLI layer. |
| 2970 | */ |
| 2971 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2974 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2975 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2977 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2979 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2980 | pmb->context1 = NULL; |
| 2981 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2983 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2984 | "0258 Register Fabric login error: 0x%x\n", |
| 2985 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2987 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2988 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2990 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2991 | /* FLOGI failed, use loop map to make discovery list */ |
| 2992 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2994 | /* Start discovery */ |
| 2995 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2996 | /* Decrement the reference count to ndlp after the |
| 2997 | * reference to the ndlp are done. |
| 2998 | */ |
| 2999 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3000 | return; |
| 3001 | } |
| 3002 | |
| 3003 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3004 | /* Decrement the reference count to ndlp after the reference |
| 3005 | * to the ndlp are done. |
| 3006 | */ |
| 3007 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | return; |
| 3009 | } |
| 3010 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3012 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3014 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3016 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3017 | lpfc_start_fdiscs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3022 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3023 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3024 | |
| 3025 | /* Drop the reference count from the mbox at the end after |
| 3026 | * all the current reference to the ndlp have been done. |
| 3027 | */ |
| 3028 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | return; |
| 3030 | } |
| 3031 | |
| 3032 | /* |
| 3033 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3034 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3035 | * as the completion routine when the command is |
| 3036 | * handed off to the SLI layer. |
| 3037 | */ |
| 3038 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3041 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3043 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3044 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | |
| 3046 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3047 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3048 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3049 | "0260 Register NameServer error: 0x%x\n", |
| 3050 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3051 | /* decrement the node reference count held for this |
| 3052 | * callback function. |
| 3053 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3054 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3056 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3057 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3058 | |
| 3059 | /* If no other thread is using the ndlp, free it */ |
| 3060 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3062 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3063 | /* |
| 3064 | * RegLogin failed, use loop map to make discovery |
| 3065 | * list |
| 3066 | */ |
| 3067 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | /* Start discovery */ |
| 3070 | lpfc_disc_start(vport); |
| 3071 | return; |
| 3072 | } |
| 3073 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3074 | return; |
| 3075 | } |
| 3076 | |
| 3077 | pmb->context1 = NULL; |
| 3078 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3080 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3082 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | if (vport->port_state < LPFC_VPORT_READY) { |
| 3085 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3086 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 3087 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 3088 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 3089 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 3090 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 3091 | |
| 3092 | /* Issue SCR just before NameServer GID_FT Query */ |
| 3093 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | } |
| 3095 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3098 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3099 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3100 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | } |
| 3102 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3103 | /* decrement the node reference count held for this |
| 3104 | * callback function. |
| 3105 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3106 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3108 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | |
| 3111 | return; |
| 3112 | } |
| 3113 | |
| 3114 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3115 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3117 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3118 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | struct lpfc_rport_data *rdata; |
| 3120 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | |
| 3123 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 3124 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 3125 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3126 | rport_ids.port_id = ndlp->nlp_DID; |
| 3127 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3128 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3129 | /* |
| 3130 | * We leave our node pointer in rport->dd_data when we unregister a |
| 3131 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 3132 | * rport->dd_data points. So, if we're reusing a previously |
| 3133 | * registered port, drop the reference that we took the last time we |
| 3134 | * registered the port. |
| 3135 | */ |
| 3136 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3137 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3138 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3139 | |
| 3140 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 3141 | "rport add: did:x%x flg:x%x type x%x", |
| 3142 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3143 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3144 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3145 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 3147 | "Warning: fc_remote_port_add failed\n"); |
| 3148 | return; |
| 3149 | } |
| 3150 | |
| 3151 | /* initialize static port data */ |
| 3152 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 3153 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3155 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 3156 | |
| 3157 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 3158 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 3159 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 3160 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3161 | |
| 3162 | |
| 3163 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 3164 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 3165 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3166 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3167 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3168 | ndlp->nlp_sid = rport->scsi_target_id; |
| 3169 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3170 | return; |
| 3171 | } |
| 3172 | |
| 3173 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3174 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3175 | { |
| 3176 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3177 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3178 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 3179 | "rport delete: did:x%x flg:x%x type x%x", |
| 3180 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3181 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3182 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | |
| 3184 | return; |
| 3185 | } |
| 3186 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3187 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3188 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3189 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3191 | |
| 3192 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3193 | switch (state) { |
| 3194 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3196 | break; |
| 3197 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3198 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3199 | break; |
| 3200 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3201 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3202 | break; |
| 3203 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3204 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3205 | break; |
| 3206 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3207 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3208 | break; |
| 3209 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3211 | break; |
| 3212 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3213 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3214 | break; |
| 3215 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3217 | break; |
| 3218 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3219 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3220 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3221 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3222 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3223 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3224 | int old_state, int new_state) |
| 3225 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3226 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3227 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3228 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
| 3229 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 3230 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3231 | ndlp->nlp_type |= NLP_FC_NODE; |
| 3232 | } |
| 3233 | if (new_state == NLP_STE_MAPPED_NODE) |
| 3234 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 3235 | if (new_state == NLP_STE_NPR_NODE) |
| 3236 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3238 | /* Transport interface */ |
| 3239 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 3240 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3241 | vport->phba->nport_event_cnt++; |
| 3242 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3245 | if (new_state == NLP_STE_MAPPED_NODE || |
| 3246 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3248 | /* |
| 3249 | * Tell the fc transport about the port, if we haven't |
| 3250 | * already. If we have, and it's a scsi entity, be |
| 3251 | * sure to unblock any attached scsi devices |
| 3252 | */ |
| 3253 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3254 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3255 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 3256 | (vport->stat_data_enabled)) { |
| 3257 | /* |
| 3258 | * A new target is discovered, if there is no buffer for |
| 3259 | * statistical data collection allocate buffer. |
| 3260 | */ |
| 3261 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 3262 | sizeof(struct lpfc_scsicmd_bkt), |
| 3263 | GFP_KERNEL); |
| 3264 | |
| 3265 | if (!ndlp->lat_data) |
| 3266 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 3267 | "0286 lpfc_nlp_state_cleanup failed to " |
| 3268 | "allocate statistical data buffer DID " |
| 3269 | "0x%x\n", ndlp->nlp_DID); |
| 3270 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3271 | /* |
| 3272 | * if we added to Mapped list, but the remote port |
| 3273 | * registration failed or assigned a target id outside |
| 3274 | * our presentable range - move the node to the |
| 3275 | * Unmapped List |
| 3276 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3277 | if (new_state == NLP_STE_MAPPED_NODE && |
| 3278 | (!ndlp->rport || |
| 3279 | ndlp->rport->scsi_target_id == -1 || |
| 3280 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3281 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3282 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | spin_unlock_irq(shost->host_lock); |
| 3284 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3286 | } |
| 3287 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3288 | static char * |
| 3289 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 3290 | { |
| 3291 | static char *states[] = { |
| 3292 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 3293 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 3294 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 3295 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 3296 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 3297 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 3298 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 3299 | [NLP_STE_NPR_NODE] = "NPR", |
| 3300 | }; |
| 3301 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 3302 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3303 | strlcpy(buffer, states[state], size); |
| 3304 | else |
| 3305 | snprintf(buffer, size, "unknown (%d)", state); |
| 3306 | return buffer; |
| 3307 | } |
| 3308 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3309 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3310 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3311 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3312 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3313 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3314 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3315 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3316 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3317 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3318 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 3319 | ndlp->nlp_DID, |
| 3320 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 3321 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3322 | |
| 3323 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3324 | "node statechg did:x%x old:%d ste:%d", |
| 3325 | ndlp->nlp_DID, old_state, state); |
| 3326 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3327 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3328 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3329 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3330 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 3331 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 3332 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 3333 | } |
| 3334 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3335 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3336 | spin_lock_irq(shost->host_lock); |
| 3337 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3338 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3339 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3340 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3341 | |
| 3342 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3343 | lpfc_nlp_counters(vport, state, 1); |
| 3344 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3348 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3349 | { |
| 3350 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3351 | |
| 3352 | if (list_empty(&ndlp->nlp_listp)) { |
| 3353 | spin_lock_irq(shost->host_lock); |
| 3354 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 3355 | spin_unlock_irq(shost->host_lock); |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3361 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3363 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3364 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3365 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3366 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3367 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3368 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3369 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3370 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3371 | NLP_STE_UNUSED_NODE); |
| 3372 | } |
| 3373 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 3374 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3375 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 3376 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3377 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3378 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 3379 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 3380 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 3381 | NLP_STE_UNUSED_NODE); |
| 3382 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3384 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3385 | * @vport: Pointer to Virtual Port object. |
| 3386 | * @ndlp: Pointer to FC node object. |
| 3387 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3388 | * |
| 3389 | * This function is always called when node object need to be initialized. |
| 3390 | * It initializes all the fields of the node object. Although the reference |
| 3391 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 3392 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 3393 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 3394 | * the final release of ndlp is determined by its reference count. And, the |
| 3395 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3396 | **/ |
| 3397 | static inline void |
| 3398 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3399 | uint32_t did) |
| 3400 | { |
| 3401 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 3402 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 3403 | init_timer(&ndlp->nlp_delayfunc); |
| 3404 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 3405 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 3406 | ndlp->nlp_DID = did; |
| 3407 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3408 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3409 | ndlp->nlp_sid = NLP_NO_SID; |
| 3410 | kref_init(&ndlp->kref); |
| 3411 | NLP_INT_NODE_ACT(ndlp); |
| 3412 | atomic_set(&ndlp->cmd_pending, 0); |
| 3413 | ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; |
| 3414 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3415 | |
| 3416 | struct lpfc_nodelist * |
| 3417 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3418 | int state) |
| 3419 | { |
| 3420 | struct lpfc_hba *phba = vport->phba; |
| 3421 | uint32_t did; |
| 3422 | unsigned long flags; |
| 3423 | |
| 3424 | if (!ndlp) |
| 3425 | return NULL; |
| 3426 | |
| 3427 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3428 | /* The ndlp should not be in memory free mode */ |
| 3429 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3430 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3431 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3432 | "0277 lpfc_enable_node: ndlp:x%p " |
| 3433 | "usgmap:x%x refcnt:%d\n", |
| 3434 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3435 | atomic_read(&ndlp->kref.refcount)); |
| 3436 | return NULL; |
| 3437 | } |
| 3438 | /* The ndlp should not already be in active mode */ |
| 3439 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 3440 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3441 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3442 | "0278 lpfc_enable_node: ndlp:x%p " |
| 3443 | "usgmap:x%x refcnt:%d\n", |
| 3444 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3445 | atomic_read(&ndlp->kref.refcount)); |
| 3446 | return NULL; |
| 3447 | } |
| 3448 | |
| 3449 | /* Keep the original DID */ |
| 3450 | did = ndlp->nlp_DID; |
| 3451 | |
| 3452 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 3453 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 3454 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3455 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3456 | |
| 3457 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3458 | |
| 3459 | if (state != NLP_STE_UNUSED_NODE) |
| 3460 | lpfc_nlp_set_state(vport, ndlp, state); |
| 3461 | |
| 3462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3463 | "node enable: did:x%x", |
| 3464 | ndlp->nlp_DID, 0, 0); |
| 3465 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3469 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3470 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3471 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3472 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3473 | * 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] | 3474 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 3475 | * until ALL other outstanding threads have completed. We check |
| 3476 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3477 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3478 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3479 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3480 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3481 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3482 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | /* |
| 3486 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 3487 | */ |
| 3488 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3489 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3490 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3491 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3492 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | uint32_t tmo; |
| 3494 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3495 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3496 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3497 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 3498 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3499 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3500 | * FC spec states we need 3 * ratov for CT requests |
| 3501 | */ |
| 3502 | tmo = ((phba->fc_ratov * 3) + 3); |
| 3503 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3505 | |
| 3506 | if (!timer_pending(&vport->fc_disctmo)) { |
| 3507 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3508 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 3509 | tmo, vport->port_state, vport->fc_flag); |
| 3510 | } |
| 3511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3512 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 3513 | spin_lock_irq(shost->host_lock); |
| 3514 | vport->fc_flag |= FC_DISC_TMO; |
| 3515 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | |
| 3517 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3518 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3519 | "0247 Start Discovery Timer state x%x " |
| 3520 | "Data: x%x x%lx x%x x%x\n", |
| 3521 | vport->port_state, tmo, |
| 3522 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 3523 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | |
| 3525 | return; |
| 3526 | } |
| 3527 | |
| 3528 | /* |
| 3529 | * Cancel rescue timer for Discovery / RSCN handling |
| 3530 | */ |
| 3531 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3532 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3533 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3535 | unsigned long iflags; |
| 3536 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3537 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3538 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 3539 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 3540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3541 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3542 | if (vport->fc_flag & FC_DISC_TMO) { |
| 3543 | spin_lock_irqsave(shost->host_lock, iflags); |
| 3544 | vport->fc_flag &= ~FC_DISC_TMO; |
| 3545 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 3546 | del_timer_sync(&vport->fc_disctmo); |
| 3547 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 3548 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 3549 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3554 | "0248 Cancel Discovery Timer state x%x " |
| 3555 | "Data: x%x x%x x%x\n", |
| 3556 | vport->port_state, vport->fc_flag, |
| 3557 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3558 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | /* |
| 3562 | * Check specified ring for outstanding IOCB on the SLI queue |
| 3563 | * Return true if iocb matches the specified nport |
| 3564 | */ |
| 3565 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3566 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 3567 | struct lpfc_sli_ring *pring, |
| 3568 | struct lpfc_iocbq *iocb, |
| 3569 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3571 | struct lpfc_sli *psli = &phba->sli; |
| 3572 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3573 | struct lpfc_vport *vport = ndlp->vport; |
| 3574 | |
| 3575 | if (iocb->vport != vport) |
| 3576 | return 0; |
| 3577 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | if (pring->ringno == LPFC_ELS_RING) { |
| 3579 | switch (icmd->ulpCommand) { |
| 3580 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3581 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3582 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 3584 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 3585 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | case CMD_XMIT_ELS_RSP64_CX: |
| 3587 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3588 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3590 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | |
| 3592 | } else if (pring->ringno == psli->fcp_ring) { |
| 3593 | /* Skip match check if waiting to relogin to FCP target */ |
| 3594 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3595 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3596 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | } |
| 3598 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3599 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3600 | } |
| 3601 | } else if (pring->ringno == psli->next_ring) { |
| 3602 | |
| 3603 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3604 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | /* |
| 3608 | * Free resources / clean up outstanding I/Os |
| 3609 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 3610 | */ |
| 3611 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3612 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3613 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3614 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | struct lpfc_sli *psli; |
| 3616 | struct lpfc_sli_ring *pring; |
| 3617 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3618 | uint32_t i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3620 | lpfc_fabric_abort_nport(ndlp); |
| 3621 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | /* |
| 3623 | * Everything that matches on txcmplq will be returned |
| 3624 | * by firmware with a no rpi error. |
| 3625 | */ |
| 3626 | psli = &phba->sli; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3627 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | /* Now process each ring */ |
| 3629 | for (i = 0; i < psli->num_rings; i++) { |
| 3630 | pring = &psli->ring[i]; |
| 3631 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3632 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | /* |
| 3636 | * Check to see if iocb matches the nport we are |
| 3637 | * looking for |
| 3638 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3639 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 3640 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | /* It matches, so deque and call compl |
| 3642 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3643 | list_move_tail(&iocb->list, |
| 3644 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | } |
| 3647 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | } |
| 3650 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3651 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3652 | /* Cancel all the IOCBs from the completions list */ |
| 3653 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3654 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3655 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3656 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | /* |
| 3660 | * Free rpi associated with LPFC_NODELIST entry. |
| 3661 | * This routine is called from lpfc_freenode(), when we are removing |
| 3662 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 3663 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 3664 | * to the remote NPort. In addition, it is called after we receive |
| 3665 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 3666 | * we are waiting to PLOGI back to the remote NPort. |
| 3667 | */ |
| 3668 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3669 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3671 | struct lpfc_hba *phba = vport->phba; |
| 3672 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | int rc; |
| 3674 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3675 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3676 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3677 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3678 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3679 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3680 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3681 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3683 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | lpfc_no_rpi(phba, ndlp); |
| 3686 | ndlp->nlp_rpi = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3687 | ndlp->nlp_flag &= ~NLP_RPI_VALID; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 3688 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | return 1; |
| 3690 | } |
| 3691 | return 0; |
| 3692 | } |
| 3693 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3694 | /** |
| 3695 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. |
| 3696 | * @phba: pointer to lpfc hba data structure. |
| 3697 | * |
| 3698 | * This routine is invoked to unregister all the currently registered RPIs |
| 3699 | * to the HBA. |
| 3700 | **/ |
| 3701 | void |
| 3702 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) |
| 3703 | { |
| 3704 | struct lpfc_vport **vports; |
| 3705 | struct lpfc_nodelist *ndlp; |
| 3706 | struct Scsi_Host *shost; |
| 3707 | int i; |
| 3708 | |
| 3709 | vports = lpfc_create_vport_work_array(phba); |
| 3710 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3711 | shost = lpfc_shost_from_vport(vports[i]); |
| 3712 | spin_lock_irq(shost->host_lock); |
| 3713 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3714 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| 3715 | /* The mempool_alloc might sleep */ |
| 3716 | spin_unlock_irq(shost->host_lock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3717 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3718 | spin_lock_irq(shost->host_lock); |
| 3719 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3720 | } |
| 3721 | spin_unlock_irq(shost->host_lock); |
| 3722 | } |
| 3723 | lpfc_destroy_vport_work_array(phba, vports); |
| 3724 | } |
| 3725 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3726 | void |
| 3727 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 3728 | { |
| 3729 | struct lpfc_hba *phba = vport->phba; |
| 3730 | LPFC_MBOXQ_t *mbox; |
| 3731 | int rc; |
| 3732 | |
| 3733 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3734 | if (mbox) { |
| 3735 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 3736 | mbox->vport = vport; |
| 3737 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3738 | mbox->context1 = NULL; |
| 3739 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3740 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3741 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3742 | |
| 3743 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 3744 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3745 | "1836 Could not issue " |
| 3746 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | void |
| 3751 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 3752 | { |
| 3753 | struct lpfc_hba *phba = vport->phba; |
| 3754 | LPFC_MBOXQ_t *mbox; |
| 3755 | int rc; |
| 3756 | |
| 3757 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3758 | if (mbox) { |
| 3759 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 3760 | mbox->vport = vport; |
| 3761 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3762 | mbox->context1 = NULL; |
| 3763 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3764 | if (rc != MBX_TIMEOUT) |
| 3765 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3766 | |
| 3767 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3768 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3769 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3770 | "unreg_did (default rpis) status %d\n", |
| 3771 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | /* |
| 3776 | * Free resources associated with LPFC_NODELIST entry |
| 3777 | * so it can be freed. |
| 3778 | */ |
| 3779 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3782 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3783 | struct lpfc_hba *phba = vport->phba; |
| 3784 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | |
| 3787 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3788 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3789 | "0900 Cleanup node for NPort x%x " |
| 3790 | "Data: x%x x%x x%x\n", |
| 3791 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3792 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3793 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3794 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3795 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 3796 | "usgmap:x%x refcnt:%d\n", |
| 3797 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3798 | atomic_read(&ndlp->kref.refcount)); |
| 3799 | lpfc_dequeue_node(vport, ndlp); |
| 3800 | } else { |
| 3801 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3802 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 3803 | "usgmap:x%x refcnt:%d\n", |
| 3804 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3805 | atomic_read(&ndlp->kref.refcount)); |
| 3806 | lpfc_disable_node(vport, ndlp); |
| 3807 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 3810 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3811 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 3813 | mb->context2 = NULL; |
| 3814 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3815 | } |
| 3816 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3817 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3820 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3821 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 3823 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3824 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | kfree(mp); |
| 3826 | } |
| 3827 | list_del(&mb->list); |
| 3828 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3829 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 3830 | * the ndlp reference count as we are in the process |
| 3831 | * of lpfc_nlp_release. |
| 3832 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | } |
| 3834 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3837 | lpfc_els_abort(phba, ndlp); |
| 3838 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3840 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3841 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3842 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3843 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 3845 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3846 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 3847 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3849 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3851 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | /* |
| 3855 | * Check to see if we can free the nlp back to the freelist. |
| 3856 | * If we are in the middle of using the nlp in the discovery state |
| 3857 | * machine, defer the free till we reach the end of the state machine. |
| 3858 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3859 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3862 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3863 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3864 | LPFC_MBOXQ_t *mbox; |
| 3865 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3867 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3868 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
| 3869 | !(ndlp->nlp_flag & NLP_RPI_VALID)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3870 | /* For this case we need to cleanup the default rpi |
| 3871 | * allocated by the firmware. |
| 3872 | */ |
| 3873 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 3874 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3875 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3876 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 3877 | if (rc) { |
| 3878 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3879 | } |
| 3880 | else { |
| 3881 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3882 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3883 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3884 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3885 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 3886 | if (rc == MBX_NOT_FINISHED) { |
| 3887 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3888 | } |
| 3889 | } |
| 3890 | } |
| 3891 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3892 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3893 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3894 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3895 | * We can get here with a non-NULL ndlp->rport because when we |
| 3896 | * unregister a rport we don't break the rport/node linkage. So if we |
| 3897 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3899 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3900 | rdata = ndlp->rport->dd_data; |
| 3901 | rdata->pnode = NULL; |
| 3902 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3908 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3910 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | |
| 3912 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3913 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | /* First check for Direct match */ |
| 3916 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3917 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | |
| 3919 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3920 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3921 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3922 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | matchdid.un.word = did; |
| 3926 | ndlpdid.un.word = ndlp->nlp_DID; |
| 3927 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 3928 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 3929 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 3930 | if ((ndlpdid.un.b.domain == 0) && |
| 3931 | (ndlpdid.un.b.area == 0)) { |
| 3932 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3933 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3935 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | matchdid.un.word = ndlp->nlp_DID; |
| 3939 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 3940 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 3941 | if ((matchdid.un.b.domain == 0) && |
| 3942 | (matchdid.un.b.area == 0)) { |
| 3943 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3944 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | } |
| 3946 | } |
| 3947 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3948 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | } |
| 3950 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3951 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | static struct lpfc_nodelist * |
| 3953 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 3955 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | uint32_t data1; |
| 3957 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3958 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 3959 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3960 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 3961 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 3962 | ((uint32_t) ndlp->nlp_type << 8) | |
| 3963 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3964 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3965 | "0929 FIND node DID " |
| 3966 | "Data: x%p x%x x%x x%x\n", |
| 3967 | ndlp, ndlp->nlp_DID, |
| 3968 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3969 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | } |
| 3971 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3972 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3974 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3975 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3976 | return NULL; |
| 3977 | } |
| 3978 | |
| 3979 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3980 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3982 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3983 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3985 | spin_lock_irq(shost->host_lock); |
| 3986 | ndlp = __lpfc_findnode_did(vport, did); |
| 3987 | spin_unlock_irq(shost->host_lock); |
| 3988 | return ndlp; |
| 3989 | } |
| 3990 | |
| 3991 | struct lpfc_nodelist * |
| 3992 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 3993 | { |
| 3994 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3995 | struct lpfc_nodelist *ndlp; |
| 3996 | |
| 3997 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3998 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 4000 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | return NULL; |
| 4002 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4003 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4004 | if (!ndlp) |
| 4005 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4006 | lpfc_nlp_init(vport, ndlp, did); |
| 4007 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4008 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4012 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4013 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 4014 | if (!ndlp) |
| 4015 | return NULL; |
| 4016 | spin_lock_irq(shost->host_lock); |
| 4017 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4018 | spin_unlock_irq(shost->host_lock); |
| 4019 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4021 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4022 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 4023 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4025 | /* If we've already recieved a PLOGI from this NPort |
| 4026 | * we don't need to try to discover it again. |
| 4027 | */ |
| 4028 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 4029 | return NULL; |
| 4030 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4031 | /* Since this node is marked for discovery, |
| 4032 | * delay timeout is not needed. |
| 4033 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4034 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4035 | spin_lock_irq(shost->host_lock); |
| 4036 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 4037 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 4038 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4040 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4041 | /* If we've already recieved a PLOGI from this NPort, |
| 4042 | * or we are already in the process of discovery on it, |
| 4043 | * we don't need to try to discover it again. |
| 4044 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4045 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4046 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4047 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4049 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4050 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4052 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | } |
| 4054 | return ndlp; |
| 4055 | } |
| 4056 | |
| 4057 | /* Build a list of nodes to discover based on the loopmap */ |
| 4058 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4059 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4062 | int j; |
| 4063 | uint32_t alpa, index; |
| 4064 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4067 | |
| 4068 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | |
| 4071 | /* Check for loop map present or not */ |
| 4072 | if (phba->alpa_map[0]) { |
| 4073 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 4074 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4075 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | } |
| 4079 | } else { |
| 4080 | /* No alpamap, so try all alpa's */ |
| 4081 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 4082 | /* If cfg_scan_down is set, start from highest |
| 4083 | * ALPA (0xef) to lowest (0x1). |
| 4084 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4085 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | index = j; |
| 4087 | else |
| 4088 | index = FC_MAXLOOP - j - 1; |
| 4089 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4092 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | } |
| 4094 | } |
| 4095 | return; |
| 4096 | } |
| 4097 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | struct lpfc_sli *psli = &phba->sli; |
| 4103 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 4104 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 4105 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 4106 | int rc; |
| 4107 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4108 | /* |
| 4109 | * if it's not a physical port or if we already send |
| 4110 | * clear_la then don't send it. |
| 4111 | */ |
| 4112 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4113 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 4114 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4115 | return; |
| 4116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | /* Link up discovery */ |
| 4118 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 4119 | phba->link_state = LPFC_CLEAR_LA; |
| 4120 | lpfc_clear_la(phba, mbox); |
| 4121 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 4122 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4123 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | if (rc == MBX_NOT_FINISHED) { |
| 4125 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4126 | lpfc_disc_flush_list(vport); |
| 4127 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4128 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4129 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4130 | phba->link_state = LPFC_HBA_ERROR; |
| 4131 | } |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 4136 | void |
| 4137 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4138 | { |
| 4139 | LPFC_MBOXQ_t *regvpimbox; |
| 4140 | |
| 4141 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4142 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4143 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4144 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 4145 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4146 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4147 | == MBX_NOT_FINISHED) { |
| 4148 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | } |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 4154 | void |
| 4155 | lpfc_disc_start(struct lpfc_vport *vport) |
| 4156 | { |
| 4157 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4158 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4159 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4161 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4162 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4163 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | |
| 4166 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | clear_la_pending = 1; |
| 4168 | else |
| 4169 | clear_la_pending = 0; |
| 4170 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4171 | if (vport->port_state < LPFC_VPORT_READY) |
| 4172 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | lpfc_set_disctmo(vport); |
| 4175 | |
| 4176 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | |
| 4181 | vport->fc_prevDID = vport->fc_myDID; |
| 4182 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | |
| 4184 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4185 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4186 | "0202 Start Discovery hba state x%x " |
| 4187 | "Data: x%x x%x x%x\n", |
| 4188 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 4189 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4190 | |
| 4191 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4192 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | |
| 4194 | if (num_sent) |
| 4195 | return; |
| 4196 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4197 | /* |
| 4198 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 4199 | * continue discovery. |
| 4200 | */ |
| 4201 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4202 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4203 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 4204 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4205 | lpfc_issue_reg_vpi(phba, vport); |
| 4206 | return; |
| 4207 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4209 | /* |
| 4210 | * For SLI2, we need to set port_state to READY and continue |
| 4211 | * discovery. |
| 4212 | */ |
| 4213 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 4214 | /* If we get here, there is nothing to ADISC */ |
| 4215 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 4216 | lpfc_issue_clear_la(phba, vport); |
| 4217 | |
| 4218 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4219 | vport->num_disc_nodes = 0; |
| 4220 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 4221 | if (vport->fc_npr_cnt) |
| 4222 | lpfc_els_disc_plogi(vport); |
| 4223 | |
| 4224 | if (!vport->num_disc_nodes) { |
| 4225 | spin_lock_irq(shost->host_lock); |
| 4226 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 4227 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4228 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4229 | } |
| 4230 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4231 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4232 | } else { |
| 4233 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 | |
| 4236 | if (num_sent) |
| 4237 | return; |
| 4238 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4239 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | /* Check to see if more RSCNs came in while we |
| 4241 | * were processing this one. |
| 4242 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | if ((vport->fc_rscn_id_cnt == 0) && |
| 4244 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 4245 | spin_lock_irq(shost->host_lock); |
| 4246 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 4247 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4248 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4249 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | } |
| 4252 | } |
| 4253 | return; |
| 4254 | } |
| 4255 | |
| 4256 | /* |
| 4257 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 4258 | * ring the match the sppecified nodelist. |
| 4259 | */ |
| 4260 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4263 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | struct lpfc_sli *psli; |
| 4265 | IOCB_t *icmd; |
| 4266 | struct lpfc_iocbq *iocb, *next_iocb; |
| 4267 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | |
| 4269 | psli = &phba->sli; |
| 4270 | pring = &psli->ring[LPFC_ELS_RING]; |
| 4271 | |
| 4272 | /* Error matching iocb on txq or txcmplq |
| 4273 | * First check the txq. |
| 4274 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4275 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4277 | if (iocb->context1 != ndlp) { |
| 4278 | continue; |
| 4279 | } |
| 4280 | icmd = &iocb->iocb; |
| 4281 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 4282 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 4283 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4284 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | /* Next check the txcmplq */ |
| 4290 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 4291 | if (iocb->context1 != ndlp) { |
| 4292 | continue; |
| 4293 | } |
| 4294 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 4296 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4297 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | } |
| 4299 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4301 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4302 | /* Cancel all the IOCBs from the completions list */ |
| 4303 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4304 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | } |
| 4306 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4307 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | { |
| 4310 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 4314 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4315 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4316 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4317 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4318 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 4319 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 4320 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4321 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | } |
| 4323 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | } |
| 4325 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4326 | void |
| 4327 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 4328 | { |
| 4329 | lpfc_els_flush_rscn(vport); |
| 4330 | lpfc_els_flush_cmd(vport); |
| 4331 | lpfc_disc_flush_list(vport); |
| 4332 | } |
| 4333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | /*****************************************************************************/ |
| 4335 | /* |
| 4336 | * NAME: lpfc_disc_timeout |
| 4337 | * |
| 4338 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 4339 | * |
| 4340 | * EXECUTION ENVIRONMENT: interrupt only |
| 4341 | * |
| 4342 | * CALLED FROM: |
| 4343 | * Timer function |
| 4344 | * |
| 4345 | * RETURNS: |
| 4346 | * none |
| 4347 | */ |
| 4348 | /*****************************************************************************/ |
| 4349 | void |
| 4350 | lpfc_disc_timeout(unsigned long ptr) |
| 4351 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4353 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4354 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | unsigned long flags = 0; |
| 4356 | |
| 4357 | if (unlikely(!phba)) |
| 4358 | return; |
| 4359 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4360 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 4361 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 4362 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4363 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4364 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4365 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4366 | if (!tmo_posted) |
| 4367 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | return; |
| 4369 | } |
| 4370 | |
| 4371 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4374 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4375 | struct lpfc_hba *phba = vport->phba; |
| 4376 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4377 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4378 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4379 | int rc, clrlaerr = 0; |
| 4380 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4382 | return; |
| 4383 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | spin_lock_irq(shost->host_lock); |
| 4385 | vport->fc_flag &= ~FC_DISC_TMO; |
| 4386 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4389 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 4390 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 4391 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | |
| 4394 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 4396 | * FAN |
| 4397 | */ |
| 4398 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4399 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 4400 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4401 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4402 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4403 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4404 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4405 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4406 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 4407 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4408 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 4409 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4411 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4412 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4413 | /* Fail outstanding IO now since device |
| 4414 | * is marked for PLOGI. |
| 4415 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4416 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4417 | } |
| 4418 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4419 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4420 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4421 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4422 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | break; |
| 4424 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4425 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4426 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4429 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4430 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4431 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | |
| 4433 | /* Assume no Fabric and go on with discovery. |
| 4434 | * Check for outstanding ELS FLOGI to abort. |
| 4435 | */ |
| 4436 | |
| 4437 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4438 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | |
| 4440 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | break; |
| 4443 | |
| 4444 | case LPFC_FABRIC_CFG_LINK: |
| 4445 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 4446 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4447 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4448 | "0223 Timeout while waiting for " |
| 4449 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4450 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4451 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4452 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4453 | lpfc_els_abort(phba, ndlp); |
| 4454 | |
| 4455 | /* ReStart discovery */ |
| 4456 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | |
| 4458 | case LPFC_NS_QRY: |
| 4459 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4460 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4461 | "0224 NameServer Query timeout " |
| 4462 | "Data: x%x x%x\n", |
| 4463 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4464 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4465 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 4466 | /* Try it one more time */ |
| 4467 | vport->fc_ns_retry++; |
| 4468 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 4469 | vport->fc_ns_retry, 0); |
| 4470 | if (rc == 0) |
| 4471 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4473 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4475 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4476 | /* |
| 4477 | * Discovery is over. |
| 4478 | * set port_state to PORT_READY if SLI2. |
| 4479 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4480 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4481 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4482 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4483 | lpfc_issue_reg_vpi(phba, vport); |
| 4484 | else { /* NPIV Not enabled */ |
| 4485 | lpfc_issue_clear_la(phba, vport); |
| 4486 | vport->port_state = LPFC_VPORT_READY; |
| 4487 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 4491 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4492 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4493 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4494 | "0206 Device Discovery " |
| 4495 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4496 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | break; |
| 4498 | } |
| 4499 | |
| 4500 | lpfc_linkdown(phba); |
| 4501 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 4502 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4503 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4504 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4505 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4506 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4507 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | if (rc == MBX_NOT_FINISHED) |
| 4509 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 4510 | |
| 4511 | break; |
| 4512 | |
| 4513 | case LPFC_DISC_AUTH: |
| 4514 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4515 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4516 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4517 | lpfc_disc_flush_list(vport); |
| 4518 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4519 | /* |
| 4520 | * set port_state to PORT_READY if SLI2. |
| 4521 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 4522 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4523 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4524 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 4525 | lpfc_issue_reg_vpi(phba, vport); |
| 4526 | else { /* NPIV Not enabled */ |
| 4527 | lpfc_issue_clear_la(phba, vport); |
| 4528 | vport->port_state = LPFC_VPORT_READY; |
| 4529 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4530 | } |
| 4531 | break; |
| 4532 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | case LPFC_VPORT_READY: |
| 4534 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4535 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4536 | "0231 RSCN timeout Data: x%x " |
| 4537 | "x%x\n", |
| 4538 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | |
| 4540 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4541 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | lpfc_els_flush_rscn(vport); |
| 4544 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | } |
| 4546 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4547 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4548 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4549 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4550 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4551 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4552 | break; |
| 4553 | } |
| 4554 | |
| 4555 | switch (phba->link_state) { |
| 4556 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4557 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4558 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4559 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4560 | clrlaerr = 1; |
| 4561 | break; |
| 4562 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4563 | case LPFC_LINK_UP: |
| 4564 | lpfc_issue_clear_la(phba, vport); |
| 4565 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4566 | case LPFC_LINK_UNKNOWN: |
| 4567 | case LPFC_WARM_START: |
| 4568 | case LPFC_INIT_START: |
| 4569 | case LPFC_INIT_MBX_CMDS: |
| 4570 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4571 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4572 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 4573 | "0230 Unexpected timeout, hba link " |
| 4574 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | clrlaerr = 1; |
| 4576 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4577 | |
| 4578 | case LPFC_HBA_READY: |
| 4579 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4583 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4584 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4585 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 4586 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | return; |
| 4591 | } |
| 4592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | /* |
| 4594 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 4595 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 4596 | * as the completion routine when the command is |
| 4597 | * handed off to the SLI layer. |
| 4598 | */ |
| 4599 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4600 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4602 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4603 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 4604 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4605 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | |
| 4607 | pmb->context1 = NULL; |
| 4608 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 4610 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4612 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | /* |
| 4615 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 4616 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 4617 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4618 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4620 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 4622 | else |
| 4623 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4624 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4625 | /* decrement the node reference count held for this callback |
| 4626 | * function. |
| 4627 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4628 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4630 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4631 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 | |
| 4633 | return; |
| 4634 | } |
| 4635 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4636 | static int |
| 4637 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 4638 | { |
| 4639 | uint16_t *rpi = param; |
| 4640 | |
| 4641 | return ndlp->nlp_rpi == *rpi; |
| 4642 | } |
| 4643 | |
| 4644 | static int |
| 4645 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 4646 | { |
| 4647 | return memcmp(&ndlp->nlp_portname, param, |
| 4648 | sizeof(ndlp->nlp_portname)) == 0; |
| 4649 | } |
| 4650 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4651 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4652 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4653 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4654 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4656 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4657 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4658 | return ndlp; |
| 4659 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4660 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4661 | } |
| 4662 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4663 | /* |
| 4664 | * 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] | 4665 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4666 | */ |
| 4667 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4668 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4669 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4670 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4671 | } |
| 4672 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4673 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4674 | * 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] | 4675 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4676 | */ |
| 4677 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4678 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4679 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4680 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4681 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4682 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4683 | spin_lock_irq(shost->host_lock); |
| 4684 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 4685 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4686 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4687 | } |
| 4688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4689 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4691 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4692 | { |
| 4693 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4694 | |
| 4695 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4696 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4697 | |
| 4698 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4699 | "node init: did:x%x", |
| 4700 | ndlp->nlp_DID, 0, 0); |
| 4701 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | return; |
| 4703 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4704 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4705 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 4706 | * and mempool_free's the nodelist. |
| 4707 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4708 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4709 | lpfc_nlp_release(struct kref *kref) |
| 4710 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4711 | struct lpfc_hba *phba; |
| 4712 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4713 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 4714 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4715 | |
| 4716 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4717 | "node release: did:x%x flg:x%x type:x%x", |
| 4718 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4719 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4720 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4721 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 4722 | "usgmap:x%x refcnt:%d\n", |
| 4723 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4724 | atomic_read(&ndlp->kref.refcount)); |
| 4725 | |
| 4726 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4727 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4728 | |
| 4729 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4730 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4731 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4732 | NLP_CLR_NODE_ACT(ndlp); |
| 4733 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4734 | |
| 4735 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4736 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4737 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4738 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4739 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4742 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 4743 | * that one discovery thread won't free a ndlp while another discovery thread |
| 4744 | * is using it. |
| 4745 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4746 | struct lpfc_nodelist * |
| 4747 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 4748 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4749 | struct lpfc_hba *phba; |
| 4750 | unsigned long flags; |
| 4751 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4752 | if (ndlp) { |
| 4753 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4754 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 4755 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4756 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4757 | /* The check of ndlp usage to prevent incrementing the |
| 4758 | * ndlp reference count that is in the process of being |
| 4759 | * released. |
| 4760 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4761 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4762 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4763 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 4764 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4765 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4766 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 4767 | "usgmap:x%x refcnt:%d\n", |
| 4768 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4769 | atomic_read(&ndlp->kref.refcount)); |
| 4770 | return NULL; |
| 4771 | } else |
| 4772 | kref_get(&ndlp->kref); |
| 4773 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4774 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4775 | return ndlp; |
| 4776 | } |
| 4777 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4778 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4779 | * count goes to 0, this indicates the the associated nodelist should be |
| 4780 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 4781 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 4782 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4783 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4784 | int |
| 4785 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 4786 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4787 | struct lpfc_hba *phba; |
| 4788 | unsigned long flags; |
| 4789 | |
| 4790 | if (!ndlp) |
| 4791 | return 1; |
| 4792 | |
| 4793 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4794 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 4795 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4796 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4797 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4798 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4799 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 4800 | * possible race condition that kref_put got invoked again |
| 4801 | * after previous one has done ndlp memory free. |
| 4802 | */ |
| 4803 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 4804 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4805 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4806 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 4807 | "usgmap:x%x refcnt:%d\n", |
| 4808 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4809 | atomic_read(&ndlp->kref.refcount)); |
| 4810 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4811 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4812 | /* Check the ndlp inactivate log flag to avoid the possible |
| 4813 | * race condition that kref_put got invoked again after ndlp |
| 4814 | * is already in inactivating state. |
| 4815 | */ |
| 4816 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 4817 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4818 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4819 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 4820 | "usgmap:x%x refcnt:%d\n", |
| 4821 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4822 | atomic_read(&ndlp->kref.refcount)); |
| 4823 | return 1; |
| 4824 | } |
| 4825 | /* For last put, mark the ndlp usage flags to make sure no |
| 4826 | * other kref_get and kref_put on the same ndlp shall get |
| 4827 | * in between the process when the final kref_put has been |
| 4828 | * invoked on this ndlp. |
| 4829 | */ |
| 4830 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 4831 | /* Indicate ndlp is put to inactive state. */ |
| 4832 | NLP_SET_IACT_REQ(ndlp); |
| 4833 | /* Acknowledge ndlp memory free has been seen. */ |
| 4834 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 4835 | NLP_SET_FREE_ACK(ndlp); |
| 4836 | } |
| 4837 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4838 | /* Note, the kref_put returns 1 when decrementing a reference |
| 4839 | * count that was 1, it invokes the release callback function, |
| 4840 | * but it still left the reference count as 1 (not actually |
| 4841 | * performs the last decrementation). Otherwise, it actually |
| 4842 | * decrements the reference count and returns 0. |
| 4843 | */ |
| 4844 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4845 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4846 | |
| 4847 | /* 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] | 4848 | * by any other discovery thread. This routine returns 1 if the |
| 4849 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 4850 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4851 | */ |
| 4852 | int |
| 4853 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 4854 | { |
| 4855 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4856 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 4857 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4858 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4859 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 4860 | if (lpfc_nlp_put(ndlp)) |
| 4861 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4862 | return 0; |
| 4863 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4864 | |
| 4865 | /** |
| 4866 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 4867 | * @phba: Pointer to hba context object. |
| 4868 | * |
| 4869 | * This function iterate through all FC nodes associated |
| 4870 | * will all vports to check if there is any node with |
| 4871 | * fc_rports associated with it. If there is an fc_rport |
| 4872 | * associated with the node, then the node is either in |
| 4873 | * discovered state or its devloss_timer is pending. |
| 4874 | */ |
| 4875 | static int |
| 4876 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 4877 | { |
| 4878 | struct lpfc_vport **vports; |
| 4879 | int i, ret = 0; |
| 4880 | struct lpfc_nodelist *ndlp; |
| 4881 | struct Scsi_Host *shost; |
| 4882 | |
| 4883 | vports = lpfc_create_vport_work_array(phba); |
| 4884 | |
| 4885 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4886 | shost = lpfc_shost_from_vport(vports[i]); |
| 4887 | spin_lock_irq(shost->host_lock); |
| 4888 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 4889 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 4890 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 4891 | ret = 1; |
| 4892 | spin_unlock_irq(shost->host_lock); |
| 4893 | goto out; |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 4894 | } else { |
| 4895 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 4896 | "2624 RPI %x DID %x flg %x still " |
| 4897 | "logged in\n", |
| 4898 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 4899 | ndlp->nlp_flag); |
| 4900 | if (ndlp->nlp_flag & NLP_RPI_VALID) |
| 4901 | ret = 1; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | spin_unlock_irq(shost->host_lock); |
| 4905 | } |
| 4906 | out: |
| 4907 | lpfc_destroy_vport_work_array(phba, vports); |
| 4908 | return ret; |
| 4909 | } |
| 4910 | |
| 4911 | /** |
| 4912 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 4913 | * @phba: Pointer to hba context object. |
| 4914 | * @mboxq: Pointer to mailbox object. |
| 4915 | * |
| 4916 | * This function frees memory associated with the mailbox command. |
| 4917 | */ |
| 4918 | static void |
| 4919 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 4920 | { |
| 4921 | struct lpfc_vport *vport = mboxq->vport; |
| 4922 | |
| 4923 | if (mboxq->u.mb.mbxStatus) { |
| 4924 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4925 | "2555 UNREG_VFI mbxStatus error x%x " |
| 4926 | "HBA state x%x\n", |
| 4927 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 4928 | } |
| 4929 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4930 | return; |
| 4931 | } |
| 4932 | |
| 4933 | /** |
| 4934 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 4935 | * @phba: Pointer to hba context object. |
| 4936 | * @mboxq: Pointer to mailbox object. |
| 4937 | * |
| 4938 | * This function frees memory associated with the mailbox command. |
| 4939 | */ |
| 4940 | static void |
| 4941 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 4942 | { |
| 4943 | struct lpfc_vport *vport = mboxq->vport; |
| 4944 | |
| 4945 | if (mboxq->u.mb.mbxStatus) { |
| 4946 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4947 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 4948 | "HBA state x%x\n", |
| 4949 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 4950 | } |
| 4951 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4952 | return; |
| 4953 | } |
| 4954 | |
| 4955 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4956 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4957 | * @phba: Pointer to hba context object. |
| 4958 | * |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4959 | * This function prepare the HBA for unregistering the currently registered |
| 4960 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and |
| 4961 | * VFIs. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4962 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4963 | int |
| 4964 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4965 | { |
| 4966 | LPFC_MBOXQ_t *mbox; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4967 | struct lpfc_vport **vports; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4968 | struct lpfc_nodelist *ndlp; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 4969 | struct Scsi_Host *shost; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4970 | int i, rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4971 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4972 | /* Unregister RPIs */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4973 | if (lpfc_fcf_inuse(phba)) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4974 | lpfc_unreg_hba_rpis(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4975 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4976 | /* At this point, all discovery is aborted */ |
| 4977 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4978 | |
| 4979 | /* Unregister VPIs */ |
| 4980 | vports = lpfc_create_vport_work_array(phba); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4981 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4982 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4983 | /* Stop FLOGI/FDISC retries */ |
| 4984 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 4985 | if (ndlp) |
| 4986 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4987 | lpfc_mbx_unreg_vpi(vports[i]); |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 4988 | shost = lpfc_shost_from_vport(vports[i]); |
| 4989 | spin_lock_irq(shost->host_lock); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 4990 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 4991 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 4992 | spin_unlock_irq(shost->host_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4993 | } |
| 4994 | lpfc_destroy_vport_work_array(phba, vports); |
| 4995 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4996 | /* Cleanup any outstanding ELS commands */ |
| 4997 | lpfc_els_flush_all_cmd(phba); |
| 4998 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4999 | /* Unregister VFI */ |
| 5000 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5001 | if (!mbox) { |
| 5002 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5003 | "2556 UNREG_VFI mbox allocation failed" |
| 5004 | "HBA state x%x\n", phba->pport->port_state); |
| 5005 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5006 | } |
| 5007 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5008 | lpfc_unreg_vfi(mbox, phba->pport); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5009 | mbox->vport = phba->pport; |
| 5010 | mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 5011 | |
| 5012 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5013 | if (rc == MBX_NOT_FINISHED) { |
| 5014 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5015 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 5016 | "HBA state x%x\n", |
| 5017 | rc, phba->pport->port_state); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5018 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5019 | return -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5020 | } |
| 5021 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5022 | shost = lpfc_shost_from_vport(phba->pport); |
| 5023 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5024 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 5025 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5026 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5027 | return 0; |
| 5028 | } |
| 5029 | |
| 5030 | /** |
| 5031 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record |
| 5032 | * @phba: Pointer to hba context object. |
| 5033 | * |
| 5034 | * This function issues synchronous unregister FCF mailbox command to HBA to |
| 5035 | * unregister the currently registered FCF record. The driver does not reset |
| 5036 | * the driver FCF usage state flags. |
| 5037 | * |
| 5038 | * Return 0 if successfully issued, none-zero otherwise. |
| 5039 | */ |
| 5040 | int |
| 5041 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) |
| 5042 | { |
| 5043 | LPFC_MBOXQ_t *mbox; |
| 5044 | int rc; |
| 5045 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5046 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5047 | if (!mbox) { |
| 5048 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5049 | "2551 UNREG_FCFI mbox allocation failed" |
| 5050 | "HBA state x%x\n", phba->pport->port_state); |
| 5051 | return -ENOMEM; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5052 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5053 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 5054 | mbox->vport = phba->pport; |
| 5055 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 5056 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 5057 | |
| 5058 | if (rc == MBX_NOT_FINISHED) { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5059 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5060 | "2552 Unregister FCFI command failed rc x%x " |
| 5061 | "HBA state x%x\n", |
| 5062 | rc, phba->pport->port_state); |
| 5063 | return -EINVAL; |
| 5064 | } |
| 5065 | return 0; |
| 5066 | } |
| 5067 | |
| 5068 | /** |
| 5069 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan |
| 5070 | * @phba: Pointer to hba context object. |
| 5071 | * |
| 5072 | * This function unregisters the currently reigstered FCF. This function |
| 5073 | * also tries to find another FCF for discovery by rescan the HBA FCF table. |
| 5074 | */ |
| 5075 | void |
| 5076 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) |
| 5077 | { |
| 5078 | int rc; |
| 5079 | |
| 5080 | /* Preparation for unregistering fcf */ |
| 5081 | rc = lpfc_unregister_fcf_prep(phba); |
| 5082 | if (rc) { |
| 5083 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5084 | "2748 Failed to prepare for unregistering " |
| 5085 | "HBA's FCF record: rc=%d\n", rc); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5086 | return; |
| 5087 | } |
| 5088 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5089 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5090 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5091 | if (rc) |
| 5092 | return; |
| 5093 | /* Reset HBA FCF states after successful unregister FCF */ |
| 5094 | phba->fcf.fcf_flag = 0; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5095 | phba->fcf.current_rec.flag = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5096 | |
| 5097 | /* |
| 5098 | * If driver is not unloading, check if there is any other |
| 5099 | * FCF record that can be used for discovery. |
| 5100 | */ |
| 5101 | if ((phba->pport->load_flag & FC_UNLOADING) || |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5102 | (phba->link_state < LPFC_LINK_UP)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5103 | return; |
| 5104 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5105 | /* This is considered as the initial FCF discovery scan */ |
| 5106 | spin_lock_irq(&phba->hbalock); |
| 5107 | phba->fcf.fcf_flag |= FCF_INIT_DISC; |
| 5108 | spin_unlock_irq(&phba->hbalock); |
| 5109 | 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] | 5110 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5111 | if (rc) { |
| 5112 | spin_lock_irq(&phba->hbalock); |
| 5113 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
| 5114 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5115 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5116 | "2553 lpfc_unregister_unused_fcf failed " |
| 5117 | "to read FCF record HBA state x%x\n", |
| 5118 | phba->pport->port_state); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5119 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | /** |
| 5123 | * lpfc_unregister_fcf - Unregister the currently registered fcf record |
| 5124 | * @phba: Pointer to hba context object. |
| 5125 | * |
| 5126 | * This function just unregisters the currently reigstered FCF. It does not |
| 5127 | * try to find another FCF for discovery. |
| 5128 | */ |
| 5129 | void |
| 5130 | lpfc_unregister_fcf(struct lpfc_hba *phba) |
| 5131 | { |
| 5132 | int rc; |
| 5133 | |
| 5134 | /* Preparation for unregistering fcf */ |
| 5135 | rc = lpfc_unregister_fcf_prep(phba); |
| 5136 | if (rc) { |
| 5137 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 5138 | "2749 Failed to prepare for unregistering " |
| 5139 | "HBA's FCF record: rc=%d\n", rc); |
| 5140 | return; |
| 5141 | } |
| 5142 | |
| 5143 | /* Now, unregister FCF record and reset HBA FCF state */ |
| 5144 | rc = lpfc_sli4_unregister_fcf(phba); |
| 5145 | if (rc) |
| 5146 | return; |
| 5147 | /* Set proper HBA FCF states after successful unregister FCF */ |
| 5148 | spin_lock_irq(&phba->hbalock); |
| 5149 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 5150 | spin_unlock_irq(&phba->hbalock); |
| 5151 | } |
| 5152 | |
| 5153 | /** |
| 5154 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 5155 | * @phba: Pointer to hba context object. |
| 5156 | * |
| 5157 | * This function check if there are any connected remote port for the FCF and |
| 5158 | * if all the devices are disconnected, this function unregister FCFI. |
| 5159 | * This function also tries to use another FCF for discovery. |
| 5160 | */ |
| 5161 | void |
| 5162 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 5163 | { |
| 5164 | /* |
| 5165 | * If HBA is not running in FIP mode or if HBA does not support |
| 5166 | * FCoE or if FCF is not registered, do nothing. |
| 5167 | */ |
| 5168 | spin_lock_irq(&phba->hbalock); |
| 5169 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT) || |
| 5170 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
| 5171 | !(phba->hba_flag & HBA_FIP_SUPPORT)) { |
| 5172 | spin_unlock_irq(&phba->hbalock); |
| 5173 | return; |
| 5174 | } |
| 5175 | spin_unlock_irq(&phba->hbalock); |
| 5176 | |
| 5177 | if (lpfc_fcf_inuse(phba)) |
| 5178 | return; |
| 5179 | |
| 5180 | lpfc_unregister_fcf_rescan(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 5185 | * @phba: Pointer to hba context object. |
| 5186 | * @buff: Buffer containing the FCF connection table as in the config |
| 5187 | * region. |
| 5188 | * This function create driver data structure for the FCF connection |
| 5189 | * record table read from config region 23. |
| 5190 | */ |
| 5191 | static void |
| 5192 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 5193 | uint8_t *buff) |
| 5194 | { |
| 5195 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5196 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 5197 | struct lpfc_fcf_conn_rec *conn_rec; |
| 5198 | uint32_t record_count; |
| 5199 | int i; |
| 5200 | |
| 5201 | /* Free the current connect table */ |
| 5202 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5203 | &phba->fcf_conn_rec_list, list) { |
| 5204 | list_del_init(&conn_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5205 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5206 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5207 | |
| 5208 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 5209 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 5210 | sizeof(struct lpfc_fcf_conn_rec); |
| 5211 | |
| 5212 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 5213 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 5214 | |
| 5215 | for (i = 0; i < record_count; i++) { |
| 5216 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 5217 | continue; |
| 5218 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 5219 | GFP_KERNEL); |
| 5220 | if (!conn_entry) { |
| 5221 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5222 | "2566 Failed to allocate connection" |
| 5223 | " table entry\n"); |
| 5224 | return; |
| 5225 | } |
| 5226 | |
| 5227 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 5228 | sizeof(struct lpfc_fcf_conn_rec)); |
| 5229 | conn_entry->conn_rec.vlan_tag = |
| 5230 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 5231 | conn_entry->conn_rec.flags = |
| 5232 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 5233 | list_add_tail(&conn_entry->list, |
| 5234 | &phba->fcf_conn_rec_list); |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 5240 | * @phba: Pointer to hba context object. |
| 5241 | * @buff: Buffer containing the FCoE parameter data structure. |
| 5242 | * |
| 5243 | * This function update driver data structure with config |
| 5244 | * parameters read from config region 23. |
| 5245 | */ |
| 5246 | static void |
| 5247 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 5248 | uint8_t *buff) |
| 5249 | { |
| 5250 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 5251 | struct lpfc_fcoe_params *fcoe_param; |
| 5252 | |
| 5253 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 5254 | buff; |
| 5255 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5256 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5257 | |
| 5258 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 5259 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 5260 | return; |
| 5261 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5262 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 5263 | phba->valid_vlan = 1; |
| 5264 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 5265 | 0xFFF; |
| 5266 | } |
| 5267 | |
| 5268 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 5269 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 5270 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 5271 | return; |
| 5272 | } |
| 5273 | |
| 5274 | /** |
| 5275 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 5276 | * @buff: Buffer containing config region 23 data. |
| 5277 | * @size: Size of the data buffer. |
| 5278 | * @rec_type: Record type to be searched. |
| 5279 | * |
| 5280 | * This function searches config region data to find the begining |
| 5281 | * of the record specified by record_type. If record found, this |
| 5282 | * function return pointer to the record else return NULL. |
| 5283 | */ |
| 5284 | static uint8_t * |
| 5285 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 5286 | { |
| 5287 | uint32_t offset = 0, rec_length; |
| 5288 | |
| 5289 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 5290 | (size < sizeof(uint32_t))) |
| 5291 | return NULL; |
| 5292 | |
| 5293 | rec_length = buff[offset + 1]; |
| 5294 | |
| 5295 | /* |
| 5296 | * One TLV record has one word header and number of data words |
| 5297 | * specified in the rec_length field of the record header. |
| 5298 | */ |
| 5299 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 5300 | <= size) { |
| 5301 | if (buff[offset] == rec_type) |
| 5302 | return &buff[offset]; |
| 5303 | |
| 5304 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 5305 | return NULL; |
| 5306 | |
| 5307 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 5308 | rec_length = buff[offset + 1]; |
| 5309 | } |
| 5310 | return NULL; |
| 5311 | } |
| 5312 | |
| 5313 | /** |
| 5314 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 5315 | * @phba: Pointer to lpfc_hba data structure. |
| 5316 | * @buff: Buffer containing config region 23 data. |
| 5317 | * @size: Size of the data buffer. |
| 5318 | * |
| 5319 | * This fuction parse the FCoE config parameters in config region 23 and |
| 5320 | * populate driver data structure with the parameters. |
| 5321 | */ |
| 5322 | void |
| 5323 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 5324 | uint8_t *buff, |
| 5325 | uint32_t size) |
| 5326 | { |
| 5327 | uint32_t offset = 0, rec_length; |
| 5328 | uint8_t *rec_ptr; |
| 5329 | |
| 5330 | /* |
| 5331 | * If data size is less than 2 words signature and version cannot be |
| 5332 | * verified. |
| 5333 | */ |
| 5334 | if (size < 2*sizeof(uint32_t)) |
| 5335 | return; |
| 5336 | |
| 5337 | /* Check the region signature first */ |
| 5338 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 5339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5340 | "2567 Config region 23 has bad signature\n"); |
| 5341 | return; |
| 5342 | } |
| 5343 | |
| 5344 | offset += 4; |
| 5345 | |
| 5346 | /* Check the data structure version */ |
| 5347 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 5348 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5349 | "2568 Config region 23 has bad version\n"); |
| 5350 | return; |
| 5351 | } |
| 5352 | offset += 4; |
| 5353 | |
| 5354 | rec_length = buff[offset + 1]; |
| 5355 | |
| 5356 | /* Read FCoE param record */ |
| 5357 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5358 | size - offset, FCOE_PARAM_TYPE); |
| 5359 | if (rec_ptr) |
| 5360 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 5361 | |
| 5362 | /* Read FCF connection table */ |
| 5363 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 5364 | size - offset, FCOE_CONN_TBL_TYPE); |
| 5365 | if (rec_ptr) |
| 5366 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 5367 | |
| 5368 | } |