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