| 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 64 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 65 | void |
| 66 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 67 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 68 | struct lpfc_rport_data *rdata; |
| 69 | struct lpfc_nodelist * ndlp; |
| 70 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 71 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 72 | rdata = rport->dd_data; |
| 73 | ndlp = rdata->pnode; |
| 74 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 75 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 76 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 77 | printk(KERN_ERR "Cannot find remote node" |
| 78 | " to terminate I/O Data x%x\n", |
| 79 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 83 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 84 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 85 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 86 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 87 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 88 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 89 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 90 | lpfc_sli_abort_iocb(ndlp->vport, |
| 91 | &phba->sli.ring[phba->sli.fcp_ring], |
| 92 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 93 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * This function will be called when dev_loss_tmo fire. |
| 98 | */ |
| 99 | void |
| 100 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 101 | { |
| 102 | struct lpfc_rport_data *rdata; |
| 103 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 104 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 105 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 106 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 107 | int put_node; |
| 108 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 109 | |
| 110 | rdata = rport->dd_data; |
| 111 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 112 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 113 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 114 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 115 | vport = ndlp->vport; |
| 116 | phba = vport->phba; |
| 117 | |
| 118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 119 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 120 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 121 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 122 | /* Don't defer this if we are in the process of deleting the vport |
| 123 | * or unloading the driver. The unload will cleanup the node |
| 124 | * appropriately we just need to cleanup the ndlp rport info here. |
| 125 | */ |
| 126 | if (vport->load_flag & FC_UNLOADING) { |
| 127 | put_node = rdata->pnode != NULL; |
| 128 | put_rport = ndlp->rport != NULL; |
| 129 | rdata->pnode = NULL; |
| 130 | ndlp->rport = NULL; |
| 131 | if (put_node) |
| 132 | lpfc_nlp_put(ndlp); |
| 133 | if (put_rport) |
| 134 | put_device(&rport->dev); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 139 | return; |
| 140 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 141 | evtp = &ndlp->dev_loss_evt; |
| 142 | |
| 143 | if (!list_empty(&evtp->evt_listp)) |
| 144 | return; |
| 145 | |
| 146 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 147 | /* We need to hold the node by incrementing the reference |
| 148 | * count until this queued work is done |
| 149 | */ |
| 150 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 151 | if (evtp->evt_arg1) { |
| 152 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 153 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 154 | lpfc_worker_wake_up(phba); |
| 155 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 156 | spin_unlock_irq(&phba->hbalock); |
| 157 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * This function is called from the worker thread when dev_loss_tmo |
| 163 | * expire. |
| 164 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 165 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 166 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 167 | { |
| 168 | struct lpfc_rport_data *rdata; |
| 169 | struct fc_rport *rport; |
| 170 | struct lpfc_vport *vport; |
| 171 | struct lpfc_hba *phba; |
| 172 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 173 | int put_node; |
| 174 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 175 | int warn_on = 0; |
| 176 | |
| 177 | rport = ndlp->rport; |
| 178 | |
| 179 | if (!rport) |
| 180 | return; |
| 181 | |
| 182 | rdata = rport->dd_data; |
| 183 | name = (uint8_t *) &ndlp->nlp_portname; |
| 184 | vport = ndlp->vport; |
| 185 | phba = vport->phba; |
| 186 | |
| 187 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 188 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 189 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 190 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 191 | /* Don't defer this if we are in the process of deleting the vport |
| 192 | * or unloading the driver. The unload will cleanup the node |
| 193 | * appropriately we just need to cleanup the ndlp rport info here. |
| 194 | */ |
| 195 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 196 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 197 | /* flush the target */ |
| 198 | lpfc_sli_abort_iocb(vport, |
| 199 | &phba->sli.ring[phba->sli.fcp_ring], |
| 200 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 201 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 202 | put_node = rdata->pnode != NULL; |
| 203 | put_rport = ndlp->rport != NULL; |
| 204 | rdata->pnode = NULL; |
| 205 | ndlp->rport = NULL; |
| 206 | if (put_node) |
| 207 | lpfc_nlp_put(ndlp); |
| 208 | if (put_rport) |
| 209 | put_device(&rport->dev); |
| 210 | return; |
| 211 | } |
| 212 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 213 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 214 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 215 | "0284 Devloss timeout Ignored on " |
| 216 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 217 | "NPort x%x\n", |
| 218 | *name, *(name+1), *(name+2), *(name+3), |
| 219 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 220 | ndlp->nlp_DID); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 221 | return; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 222 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 223 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 224 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 225 | /* We will clean up these Nodes in linkup */ |
| 226 | put_node = rdata->pnode != NULL; |
| 227 | put_rport = ndlp->rport != NULL; |
| 228 | rdata->pnode = NULL; |
| 229 | ndlp->rport = NULL; |
| 230 | if (put_node) |
| 231 | lpfc_nlp_put(ndlp); |
| 232 | if (put_rport) |
| 233 | put_device(&rport->dev); |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 234 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 235 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 238 | warn_on = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | /* flush the target */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 240 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 241 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 243 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 244 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 245 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 246 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 247 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 248 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 249 | *name, *(name+1), *(name+2), *(name+3), |
| 250 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 251 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 252 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 253 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 254 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 255 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 256 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 257 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 258 | *name, *(name+1), *(name+2), *(name+3), |
| 259 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 260 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 261 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 262 | } |
| 263 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 264 | put_node = rdata->pnode != NULL; |
| 265 | put_rport = ndlp->rport != NULL; |
| 266 | rdata->pnode = NULL; |
| 267 | ndlp->rport = NULL; |
| 268 | if (put_node) |
| 269 | lpfc_nlp_put(ndlp); |
| 270 | if (put_rport) |
| 271 | put_device(&rport->dev); |
| 272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 273 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 274 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 275 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 276 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 277 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 278 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 279 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 280 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 281 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 282 | * @phba: Pointer to hba context object. |
| 283 | * |
| 284 | * This function is called from the functions which need to post |
| 285 | * events from interrupt context. This function allocates data |
| 286 | * structure required for posting event. It also keeps track of |
| 287 | * number of events pending and prevent event storm when there are |
| 288 | * too many events. |
| 289 | **/ |
| 290 | struct lpfc_fast_path_event * |
| 291 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 292 | struct lpfc_fast_path_event *ret; |
| 293 | |
| 294 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 295 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 296 | return NULL; |
| 297 | |
| 298 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 299 | GFP_ATOMIC); |
| 300 | if (ret) |
| 301 | atomic_inc(&phba->fast_event_count); |
| 302 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 303 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 308 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 309 | * @phba: Pointer to hba context object. |
| 310 | * @evt: Event object which need to be freed. |
| 311 | * |
| 312 | * This function frees the data structure required for posting |
| 313 | * events. |
| 314 | **/ |
| 315 | void |
| 316 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 317 | struct lpfc_fast_path_event *evt) { |
| 318 | |
| 319 | atomic_dec(&phba->fast_event_count); |
| 320 | kfree(evt); |
| 321 | } |
| 322 | |
| 323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 324 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 325 | * @phba: Pointer to hba context object. |
| 326 | * @evtp: Event data structure. |
| 327 | * |
| 328 | * This function is called from worker thread, when the interrupt |
| 329 | * context need to post an event. This function posts the event |
| 330 | * to fc transport netlink interface. |
| 331 | **/ |
| 332 | static void |
| 333 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 334 | struct lpfc_work_evt *evtp) |
| 335 | { |
| 336 | unsigned long evt_category, evt_sub_category; |
| 337 | struct lpfc_fast_path_event *fast_evt_data; |
| 338 | char *evt_data; |
| 339 | uint32_t evt_data_size; |
| 340 | struct Scsi_Host *shost; |
| 341 | |
| 342 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 343 | work_evt); |
| 344 | |
| 345 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 346 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 347 | fabric_evt.subcategory; |
| 348 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 349 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 350 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 351 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 352 | evt_data_size = sizeof(fast_evt_data->un. |
| 353 | read_check_error); |
| 354 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 355 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 356 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 357 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 358 | } else { |
| 359 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 360 | return; |
| 361 | } |
| 362 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 363 | switch (evt_sub_category) { |
| 364 | case LPFC_EVENT_QFULL: |
| 365 | case LPFC_EVENT_DEVBSY: |
| 366 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 367 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 368 | break; |
| 369 | case LPFC_EVENT_CHECK_COND: |
| 370 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 371 | evt_data_size = sizeof(fast_evt_data->un. |
| 372 | check_cond_evt); |
| 373 | break; |
| 374 | case LPFC_EVENT_VARQUEDEPTH: |
| 375 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 376 | evt_data_size = sizeof(fast_evt_data->un. |
| 377 | queue_depth_evt); |
| 378 | break; |
| 379 | default: |
| 380 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 381 | return; |
| 382 | } |
| 383 | } else { |
| 384 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | fc_host_post_vendor_event(shost, |
| 389 | fc_get_event_number(), |
| 390 | evt_data_size, |
| 391 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 392 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 393 | |
| 394 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 395 | return; |
| 396 | } |
| 397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 398 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 399 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 400 | { |
| 401 | struct lpfc_work_evt *evtp = NULL; |
| 402 | struct lpfc_nodelist *ndlp; |
| 403 | int free_evt; |
| 404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 405 | spin_lock_irq(&phba->hbalock); |
| 406 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 408 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 411 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 415 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 416 | /* decrement the node reference count held |
| 417 | * for this queued work |
| 418 | */ |
| 419 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 421 | case LPFC_EVT_DEV_LOSS: |
| 422 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 423 | lpfc_dev_loss_tmo_handler(ndlp); |
| 424 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 425 | /* decrement the node reference count held for |
| 426 | * this queued work |
| 427 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 428 | lpfc_nlp_put(ndlp); |
| 429 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 430 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 431 | if (phba->link_state < LPFC_LINK_DOWN) |
| 432 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 433 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | complete((struct completion *)(evtp->evt_arg2)); |
| 436 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 437 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 439 | lpfc_offline_prep(phba); |
| 440 | *(int *)(evtp->evt_arg1) = 0; |
| 441 | complete((struct completion *)(evtp->evt_arg2)); |
| 442 | break; |
| 443 | case LPFC_EVT_OFFLINE: |
| 444 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 445 | lpfc_sli_brdrestart(phba); |
| 446 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 447 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 448 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 449 | complete((struct completion *)(evtp->evt_arg2)); |
| 450 | break; |
| 451 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 452 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 453 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 454 | lpfc_sli_brdreset(phba); |
| 455 | lpfc_hba_down_post(phba); |
| 456 | *(int *)(evtp->evt_arg1) = |
| 457 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 458 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 459 | complete((struct completion *)(evtp->evt_arg2)); |
| 460 | break; |
| 461 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 462 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 463 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 464 | = (phba->pport->stopped) |
| 465 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 466 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | complete((struct completion *)(evtp->evt_arg2)); |
| 468 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 469 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 470 | lpfc_send_fastpath_evt(phba, evtp); |
| 471 | free_evt = 0; |
| 472 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | } |
| 474 | if (free_evt) |
| 475 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 476 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 477 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | |
| 480 | } |
| 481 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 482 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 483 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 484 | { |
| 485 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 486 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 487 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 488 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 489 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 491 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 492 | ha_copy = phba->work_ha; |
| 493 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 494 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 495 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 496 | /* First, try to post the next mailbox command to SLI4 device */ |
| 497 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 498 | lpfc_sli4_post_async_mbox(phba); |
| 499 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 500 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 501 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | lpfc_handle_eratt(phba); |
| 503 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 504 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | lpfc_sli_handle_mb_event(phba); |
| 506 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 507 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 509 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 510 | /* Process SLI4 events */ |
| 511 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
| 512 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 513 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 514 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 515 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 516 | if (phba->hba_flag & ASYNC_EVENT) |
| 517 | lpfc_sli4_async_event_proc(phba); |
| 518 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 519 | spin_lock_irq(&phba->hbalock); |
| 520 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 521 | spin_unlock_irq(&phba->hbalock); |
| 522 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 523 | } |
| 524 | if (phba->hba_flag & HBA_RECEIVE_BUFFER) |
| 525 | lpfc_sli4_handle_received_buffer(phba); |
| 526 | } |
| 527 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 528 | vports = lpfc_create_vport_work_array(phba); |
| 529 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 530 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 531 | /* |
| 532 | * We could have no vports in array if unloading, so if |
| 533 | * this happens then just use the pport |
| 534 | */ |
| 535 | if (vports[i] == NULL && i == 0) |
| 536 | vport = phba->pport; |
| 537 | else |
| 538 | vport = vports[i]; |
| 539 | if (vport == NULL) |
| 540 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 541 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 542 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 543 | vport->work_port_events &= ~work_port_events; |
| 544 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 545 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 546 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 547 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 548 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 549 | if (work_port_events & WORKER_HB_TMO) |
| 550 | lpfc_hb_timeout_handler(phba); |
| 551 | if (work_port_events & WORKER_MBOX_TMO) |
| 552 | lpfc_mbox_timeout_handler(phba); |
| 553 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 554 | lpfc_unblock_fabric_iocbs(phba); |
| 555 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 556 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 557 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 558 | lpfc_ramp_down_queue_handler(phba); |
| 559 | if (work_port_events & WORKER_RAMP_UP_QUEUE) |
| 560 | lpfc_ramp_up_queue_handler(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 561 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 562 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 563 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 564 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 565 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 566 | status >>= (4*LPFC_ELS_RING); |
| 567 | if ((status & HA_RXMASK) |
| 568 | || (pring->flag & LPFC_DEFERRED_RING_EVENT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 569 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 570 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 571 | /* Set the lpfc data pending flag */ |
| 572 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 573 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 574 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 575 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 576 | (status & |
| 577 | HA_RXMASK)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 578 | } |
| 579 | /* |
| 580 | * Turn on Ring interrupts |
| 581 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 582 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 583 | spin_lock_irq(&phba->hbalock); |
| 584 | control = readl(phba->HCregaddr); |
| 585 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 586 | lpfc_debugfs_slow_ring_trc(phba, |
| 587 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 588 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 589 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 590 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 591 | writel(control, phba->HCregaddr); |
| 592 | readl(phba->HCregaddr); /* flush */ |
| 593 | } else { |
| 594 | lpfc_debugfs_slow_ring_trc(phba, |
| 595 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 596 | control, ha_copy, 0); |
| 597 | } |
| 598 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | } |
| 600 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | } |
| 603 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 604 | int |
| 605 | lpfc_do_work(void *p) |
| 606 | { |
| 607 | struct lpfc_hba *phba = p; |
| 608 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | |
| 610 | set_user_nice(current, -20); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 611 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 613 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 614 | /* wait and check worker queue activities */ |
| 615 | rc = wait_event_interruptible(phba->work_waitq, |
| 616 | (test_and_clear_bit(LPFC_DATA_READY, |
| 617 | &phba->data_flags) |
| 618 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 619 | /* Signal wakeup shall terminate the worker thread */ |
| 620 | if (rc) { |
| 621 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 622 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 624 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 626 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 629 | phba->worker_thread = NULL; |
| 630 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 631 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * This is only called to handle FC worker events. Since this a rare |
| 637 | * occurance, we allocate a struct lpfc_work_evt structure here instead of |
| 638 | * embedding it in the IOCB. |
| 639 | */ |
| 640 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 641 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | uint32_t evt) |
| 643 | { |
| 644 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 645 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 649 | * be queued to worker thread for processing |
| 650 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 651 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | if (!evtp) |
| 653 | return 0; |
| 654 | |
| 655 | evtp->evt_arg1 = arg1; |
| 656 | evtp->evt_arg2 = arg2; |
| 657 | evtp->evt = evt; |
| 658 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 659 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 660 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 661 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 663 | lpfc_worker_wake_up(phba); |
| 664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | return 1; |
| 666 | } |
| 667 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 668 | void |
| 669 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 670 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 671 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 672 | struct lpfc_hba *phba = vport->phba; |
| 673 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 674 | int rc; |
| 675 | |
| 676 | 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] | 677 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 678 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 679 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 680 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 681 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 682 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 683 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 684 | lpfc_unreg_rpi(vport, ndlp); |
| 685 | |
| 686 | /* Leave Fabric nodes alone on link down */ |
| 687 | if (!remove && ndlp->nlp_type & NLP_FABRIC) |
| 688 | continue; |
| 689 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 690 | remove |
| 691 | ? NLP_EVT_DEVICE_RM |
| 692 | : NLP_EVT_DEVICE_RECOVERY); |
| 693 | } |
| 694 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
| 695 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 696 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 697 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 698 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 702 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 703 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 704 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 705 | /* Cleanup any outstanding RSCN activity */ |
| 706 | lpfc_els_flush_rscn(vport); |
| 707 | |
| 708 | /* Cleanup any outstanding ELS commands */ |
| 709 | lpfc_els_flush_cmd(vport); |
| 710 | |
| 711 | lpfc_cleanup_rpis(vport, 0); |
| 712 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 713 | /* Turn off discovery timer if its running */ |
| 714 | lpfc_can_disctmo(vport); |
| 715 | } |
| 716 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 717 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 718 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 719 | { |
| 720 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 721 | |
| 722 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 723 | |
| 724 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 725 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 726 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 727 | |
| 728 | lpfc_port_link_failure(vport); |
| 729 | |
| 730 | } |
| 731 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 733 | lpfc_linkdown(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | struct lpfc_vport *vport = phba->pport; |
| 736 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 737 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 738 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 739 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 741 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 742 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 743 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 744 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 745 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 746 | phba->pport->fc_flag &= ~FC_LBIT; |
| 747 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 748 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 749 | vports = lpfc_create_vport_work_array(phba); |
| 750 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 751 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 752 | /* Issue a LINK DOWN event to all nodes */ |
| 753 | lpfc_linkdown_port(vports[i]); |
| 754 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 755 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 757 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 758 | if (mb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 759 | lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 760 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 761 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 762 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 764 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 769 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 770 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 771 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 772 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 774 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 775 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 776 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 778 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | } |
| 780 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 781 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 782 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 785 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 786 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | } |
| 788 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 789 | static void |
| 790 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 792 | struct lpfc_nodelist *ndlp; |
| 793 | |
| 794 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 795 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 796 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 798 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 799 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 800 | /* On Linkup its safe to clean up the ndlp |
| 801 | * from Fabric connections. |
| 802 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | if (ndlp->nlp_DID != Fabric_DID) |
| 804 | lpfc_unreg_rpi(vport, ndlp); |
| 805 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 806 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 807 | /* Fail outstanding IO now since device is |
| 808 | * marked for PLOGI. |
| 809 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 810 | lpfc_unreg_rpi(vport, ndlp); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | static void |
| 816 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 817 | { |
| 818 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | struct lpfc_hba *phba = vport->phba; |
| 820 | |
| 821 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 822 | return; |
| 823 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 825 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 826 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 827 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 828 | /* If NPIV is not enabled, only bring the physical port up */ |
| 829 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 830 | (vport != phba->pport)) |
| 831 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | 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] | 834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 835 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 836 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 837 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 838 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 839 | vport->fc_ns_retry = 0; |
| 840 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 842 | if (vport->fc_flag & FC_LBIT) |
| 843 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static int |
| 848 | lpfc_linkup(struct lpfc_hba *phba) |
| 849 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 850 | struct lpfc_vport **vports; |
| 851 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 852 | |
| 853 | phba->link_state = LPFC_LINK_UP; |
| 854 | |
| 855 | /* Unblock fabric iocbs if they are blocked */ |
| 856 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 857 | del_timer_sync(&phba->fabric_block_timer); |
| 858 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 859 | vports = lpfc_create_vport_work_array(phba); |
| 860 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 861 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 862 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 863 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 864 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 865 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | /* |
| 871 | * This routine handles processing a CLEAR_LA mailbox |
| 872 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 873 | * as the completion routine when the command is |
| 874 | * handed off to the SLI layer. |
| 875 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 876 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 877 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 879 | struct lpfc_vport *vport = pmb->vport; |
| 880 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 881 | struct lpfc_sli *psli = &phba->sli; |
| 882 | MAILBOX_t *mb = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | uint32_t control; |
| 884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 886 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 888 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 889 | |
| 890 | /* Check for error */ |
| 891 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 892 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 893 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 894 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 895 | "state x%x\n", |
| 896 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 897 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | goto out; |
| 899 | } |
| 900 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 901 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 902 | phba->link_state = LPFC_HBA_READY; |
| 903 | |
| 904 | spin_lock_irq(&phba->hbalock); |
| 905 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 906 | control = readl(phba->HCregaddr); |
| 907 | control |= HC_LAINT_ENA; |
| 908 | writel(control, phba->HCregaddr); |
| 909 | readl(phba->HCregaddr); /* flush */ |
| 910 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 911 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 912 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | out: |
| 915 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 916 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 917 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 921 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 922 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 924 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | |
| 926 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | |
| 928 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 930 | control = readl(phba->HCregaddr); |
| 931 | control |= HC_LAINT_ENA; |
| 932 | writel(control, phba->HCregaddr); |
| 933 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 934 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | |
| 936 | return; |
| 937 | } |
| 938 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 941 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 943 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 945 | if (pmb->mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 948 | mempool_free(pmb, phba->mbox_mem_pool); |
| 949 | |
| 950 | if (phba->fc_topology == TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 951 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 952 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 953 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 954 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 955 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 956 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 957 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 958 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 959 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 961 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 962 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 963 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | lpfc_initial_flogi(vport); |
| 966 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 967 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | |
| 969 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 970 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 971 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 972 | "HBA state x%x\n", |
| 973 | pmb->mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 974 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 975 | |
| 976 | lpfc_linkdown(phba); |
| 977 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 978 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 979 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 980 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 982 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | return; |
| 984 | } |
| 985 | |
| 986 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 987 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | MAILBOX_t *mb = &pmb->mb; |
| 990 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 991 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | |
| 993 | |
| 994 | /* Check for error */ |
| 995 | if (mb->mbxStatus) { |
| 996 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 997 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 998 | "0319 READ_SPARAM mbxStatus error x%x " |
| 999 | "hba state x%x>\n", |
| 1000 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | goto out; |
| 1003 | } |
| 1004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1005 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 | sizeof (struct serv_parm)); |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1007 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1008 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 1009 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1010 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1011 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 1012 | vport->fc_sparam.portName.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1013 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 1014 | sizeof(vport->fc_nodename)); |
| 1015 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 1016 | sizeof(vport->fc_portname)); |
| 1017 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 1018 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 1019 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 1020 | } |
| 1021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1022 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1023 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1024 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | return; |
| 1026 | |
| 1027 | out: |
| 1028 | pmb->context1 = NULL; |
| 1029 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1030 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1031 | lpfc_issue_clear_la(phba, vport); |
| 1032 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | return; |
| 1034 | } |
| 1035 | |
| 1036 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1037 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1039 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1042 | struct lpfc_dmabuf *mp; |
| 1043 | int rc; |
| 1044 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1046 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1047 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1048 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1049 | switch (la->UlnkSpeed) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1050 | case LA_1GHZ_LINK: |
| 1051 | phba->fc_linkspeed = LA_1GHZ_LINK; |
| 1052 | break; |
| 1053 | case LA_2GHZ_LINK: |
| 1054 | phba->fc_linkspeed = LA_2GHZ_LINK; |
| 1055 | break; |
| 1056 | case LA_4GHZ_LINK: |
| 1057 | phba->fc_linkspeed = LA_4GHZ_LINK; |
| 1058 | break; |
| 1059 | case LA_8GHZ_LINK: |
| 1060 | phba->fc_linkspeed = LA_8GHZ_LINK; |
| 1061 | break; |
| 1062 | default: |
| 1063 | phba->fc_linkspeed = LA_UNKNW_LINK; |
| 1064 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | phba->fc_topology = la->topology; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1068 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | |
| 1070 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1071 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1073 | if (phba->cfg_enable_npiv) |
| 1074 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1075 | "1309 Link Up Event npiv not supported in loop " |
| 1076 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1077 | /* Get Loop Map information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | if (la->il) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1079 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1081 | vport->fc_myDID = la->granted_AL_PA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | i = la->un.lilpBde64.tus.f.bdeSize; |
| 1083 | |
| 1084 | if (i == 0) { |
| 1085 | phba->alpa_map[0] = 0; |
| 1086 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1087 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | int numalpa, j, k; |
| 1089 | union { |
| 1090 | uint8_t pamap[16]; |
| 1091 | struct { |
| 1092 | uint32_t wd1; |
| 1093 | uint32_t wd2; |
| 1094 | uint32_t wd3; |
| 1095 | uint32_t wd4; |
| 1096 | } pa; |
| 1097 | } un; |
| 1098 | numalpa = phba->alpa_map[0]; |
| 1099 | j = 0; |
| 1100 | while (j < numalpa) { |
| 1101 | memset(un.pamap, 0, 16); |
| 1102 | for (k = 1; j < numalpa; k++) { |
| 1103 | un.pamap[k - 1] = |
| 1104 | phba->alpa_map[j + 1]; |
| 1105 | j++; |
| 1106 | if (k == 16) |
| 1107 | break; |
| 1108 | } |
| 1109 | /* Link Up Event ALPA map */ |
| 1110 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1111 | KERN_WARNING, |
| 1112 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1113 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1114 | "ALPA map Data: x%x " |
| 1115 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1116 | un.pa.wd1, un.pa.wd2, |
| 1117 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1122 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1123 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1124 | (phba->sli_rev == 3)) |
| 1125 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 1126 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | vport->fc_myDID = phba->fc_pref_DID; |
| 1128 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1129 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1130 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1131 | |
| 1132 | lpfc_linkup(phba); |
| 1133 | if (sparam_mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1134 | lpfc_read_sparam(phba, sparam_mbox, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | sparam_mbox->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1137 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1138 | if (rc == MBX_NOT_FINISHED) { |
| 1139 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 1140 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1141 | kfree(mp); |
| 1142 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
| 1143 | if (cfglink_mbox) |
| 1144 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1145 | goto out; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1146 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (cfglink_mbox) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1150 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1152 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1153 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1154 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1155 | if (rc != MBX_NOT_FINISHED) |
| 1156 | return; |
| 1157 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1159 | out: |
| 1160 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1161 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1162 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 1163 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1164 | lpfc_issue_clear_la(phba, vport); |
| 1165 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1169 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1170 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | uint32_t control; |
| 1172 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1173 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1175 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 1176 | control = readl(phba->HCregaddr); |
| 1177 | control |= HC_LAINT_ENA; |
| 1178 | writel(control, phba->HCregaddr); |
| 1179 | readl(phba->HCregaddr); /* flush */ |
| 1180 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1181 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | } |
| 1183 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1184 | static void |
| 1185 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 1186 | { |
| 1187 | lpfc_linkdown(phba); |
| 1188 | lpfc_enable_la(phba); |
| 1189 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 1190 | } |
| 1191 | |
| 1192 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | /* |
| 1194 | * This routine handles processing a READ_LA mailbox |
| 1195 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1196 | * as the completion routine when the command is |
| 1197 | * handed off to the SLI layer. |
| 1198 | */ |
| 1199 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1200 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1202 | struct lpfc_vport *vport = pmb->vport; |
| 1203 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | READ_LA_VAR *la; |
| 1205 | MAILBOX_t *mb = &pmb->mb; |
| 1206 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 1207 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1208 | /* Unblock ELS traffic */ |
| 1209 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1210 | /* Check for error */ |
| 1211 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1212 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1213 | "1307 READ_LA mbox error x%x state x%x\n", |
| 1214 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 1218 | } |
| 1219 | |
| 1220 | la = (READ_LA_VAR *) & pmb->mb.un.varReadLA; |
| 1221 | |
| 1222 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 1223 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1225 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1227 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 1229 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | if (((phba->fc_eventTag + 1) < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1232 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1234 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | if (phba->fc_eventTag != 0) |
| 1236 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1237 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | |
| 1239 | phba->fc_eventTag = la->eventTag; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1240 | if (la->mm) |
| 1241 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 1242 | else |
| 1243 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1245 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1247 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1248 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1249 | "1306 Link Up Event in loop back mode " |
| 1250 | "x%x received Data: x%x x%x x%x x%x\n", |
| 1251 | la->eventTag, phba->fc_eventTag, |
| 1252 | la->granted_AL_PA, la->UlnkSpeed, |
| 1253 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 1254 | } else { |
| 1255 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1256 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1257 | "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] | 1258 | la->eventTag, phba->fc_eventTag, |
| 1259 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1260 | phba->alpa_map[0], |
| 1261 | la->mm, la->fa, |
| 1262 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 1263 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1264 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1265 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1267 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 1268 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1269 | "1308 Link Down Event in loop back mode " |
| 1270 | "x%x received " |
| 1271 | "Data: x%x x%x x%x\n", |
| 1272 | la->eventTag, phba->fc_eventTag, |
| 1273 | phba->pport->port_state, vport->fc_flag); |
| 1274 | } |
| 1275 | else { |
| 1276 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1277 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1278 | "Data: x%x x%x x%x x%x x%x\n", |
| 1279 | la->eventTag, phba->fc_eventTag, |
| 1280 | phba->pport->port_state, vport->fc_flag, |
| 1281 | la->mm, la->fa); |
| 1282 | } |
| 1283 | lpfc_mbx_issue_link_down(phba); |
| 1284 | } |
| 1285 | if (la->mm && la->attType == AT_LINK_UP) { |
| 1286 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 1287 | phba->fc_stat.LinkDown++; |
| 1288 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1289 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1291 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1292 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1293 | lpfc_mbx_issue_link_down(phba); |
| 1294 | } else |
| 1295 | lpfc_enable_la(phba); |
| 1296 | |
| 1297 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1298 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 1299 | "Data: x%x x%x x%x\n", |
| 1300 | la->eventTag, phba->fc_eventTag, |
| 1301 | phba->pport->port_state, vport->fc_flag); |
| 1302 | /* |
| 1303 | * The cmnd that triggered this will be waiting for this |
| 1304 | * signal. |
| 1305 | */ |
| 1306 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 1307 | if (phba->wait_4_mlo_maint_flg) { |
| 1308 | phba->wait_4_mlo_maint_flg = 0; |
| 1309 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1310 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | if (la->fa) { |
| 1314 | if (la->mm) |
| 1315 | lpfc_issue_clear_la(phba, vport); |
| 1316 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1317 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 1321 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1322 | kfree(mp); |
| 1323 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1324 | return; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | * This routine handles processing a REG_LOGIN mailbox |
| 1329 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1330 | * as the completion routine when the command is |
| 1331 | * handed off to the SLI layer. |
| 1332 | */ |
| 1333 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1336 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1337 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1338 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | pmb->context1 = NULL; |
| 1341 | |
| 1342 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1345 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1347 | /* decrement the node reference count held for this callback |
| 1348 | * function. |
| 1349 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1350 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | |
| 1352 | return; |
| 1353 | } |
| 1354 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1355 | static void |
| 1356 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1357 | { |
| 1358 | MAILBOX_t *mb = &pmb->mb; |
| 1359 | struct lpfc_vport *vport = pmb->vport; |
| 1360 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1361 | |
| 1362 | switch (mb->mbxStatus) { |
| 1363 | case 0x0011: |
| 1364 | case 0x0020: |
| 1365 | case 0x9700: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1366 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1367 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 1368 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1369 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1370 | } |
| 1371 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 1372 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1373 | /* |
| 1374 | * This shost reference might have been taken at the beginning of |
| 1375 | * lpfc_vport_delete() |
| 1376 | */ |
| 1377 | if (vport->load_flag & FC_UNLOADING) |
| 1378 | scsi_host_put(shost); |
| 1379 | } |
| 1380 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1381 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1382 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 1383 | { |
| 1384 | struct lpfc_hba *phba = vport->phba; |
| 1385 | LPFC_MBOXQ_t *mbox; |
| 1386 | int rc; |
| 1387 | |
| 1388 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1389 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1390 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1391 | |
| 1392 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 1393 | mbox->vport = vport; |
| 1394 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1395 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1396 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1397 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 1398 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1399 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1400 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1401 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1402 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1403 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | static void |
| 1407 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1408 | { |
| 1409 | struct lpfc_vport *vport = pmb->vport; |
| 1410 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1411 | MAILBOX_t *mb = &pmb->mb; |
| 1412 | |
| 1413 | switch (mb->mbxStatus) { |
| 1414 | case 0x0011: |
| 1415 | case 0x9601: |
| 1416 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1417 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1418 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 1419 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1420 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 1421 | spin_lock_irq(shost->host_lock); |
| 1422 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1423 | spin_unlock_irq(shost->host_lock); |
| 1424 | vport->fc_myDID = 0; |
| 1425 | goto out; |
| 1426 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1427 | |
| 1428 | vport->num_disc_nodes = 0; |
| 1429 | /* go thru NPR list and issue ELS PLOGIs */ |
| 1430 | if (vport->fc_npr_cnt) |
| 1431 | lpfc_els_disc_plogi(vport); |
| 1432 | |
| 1433 | if (!vport->num_disc_nodes) { |
| 1434 | spin_lock_irq(shost->host_lock); |
| 1435 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1436 | spin_unlock_irq(shost->host_lock); |
| 1437 | lpfc_can_disctmo(vport); |
| 1438 | } |
| 1439 | vport->port_state = LPFC_VPORT_READY; |
| 1440 | |
| 1441 | out: |
| 1442 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1443 | return; |
| 1444 | } |
| 1445 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | /* |
| 1447 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 1448 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1449 | * as the completion routine when the command is |
| 1450 | * handed off to the SLI layer. |
| 1451 | */ |
| 1452 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1453 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1455 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1456 | MAILBOX_t *mb = &pmb->mb; |
| 1457 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1458 | struct lpfc_nodelist *ndlp; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1459 | struct lpfc_vport **vports; |
| 1460 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1462 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1463 | pmb->context1 = NULL; |
| 1464 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | if (mb->mbxStatus) { |
| 1466 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1467 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1468 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1470 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1471 | /* FLOGI failed, use loop map to make discovery list */ |
| 1472 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1474 | /* Start discovery */ |
| 1475 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1476 | /* Decrement the reference count to ndlp after the |
| 1477 | * reference to the ndlp are done. |
| 1478 | */ |
| 1479 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1484 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1485 | "0258 Register Fabric login error: 0x%x\n", |
| 1486 | mb->mbxStatus); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1487 | /* Decrement the reference count to ndlp after the reference |
| 1488 | * to the ndlp are done. |
| 1489 | */ |
| 1490 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | return; |
| 1492 | } |
| 1493 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1496 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1499 | vports = lpfc_create_vport_work_array(phba); |
| 1500 | if (vports != NULL) |
| 1501 | for(i = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1502 | i <= phba->max_vpi && vports[i] != NULL; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1503 | i++) { |
| 1504 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 1505 | continue; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1506 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1507 | lpfc_vport_set_state(vports[i], |
| 1508 | FC_VPORT_LINKDOWN); |
| 1509 | continue; |
| 1510 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1511 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 1512 | lpfc_initial_fdisc(vports[i]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1513 | else { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1514 | lpfc_vport_set_state(vports[i], |
| 1515 | FC_VPORT_NO_FABRIC_SUPP); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1516 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1517 | LOG_ELS, |
| 1518 | "0259 No NPIV " |
| 1519 | "Fabric support\n"); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1520 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1521 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1522 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1523 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1527 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1528 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1529 | |
| 1530 | /* Drop the reference count from the mbox at the end after |
| 1531 | * all the current reference to the ndlp have been done. |
| 1532 | */ |
| 1533 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | return; |
| 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 1539 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1540 | * as the completion routine when the command is |
| 1541 | * handed off to the SLI layer. |
| 1542 | */ |
| 1543 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | MAILBOX_t *mb = &pmb->mb; |
| 1547 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 1548 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 1549 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | |
| 1551 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1552 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1553 | /* decrement the node reference count held for this |
| 1554 | * callback function. |
| 1555 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1556 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1558 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1559 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1560 | |
| 1561 | /* If no other thread is using the ndlp, free it */ |
| 1562 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1564 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1565 | /* |
| 1566 | * RegLogin failed, use loop map to make discovery |
| 1567 | * list |
| 1568 | */ |
| 1569 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1570 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1571 | /* Start discovery */ |
| 1572 | lpfc_disc_start(vport); |
| 1573 | return; |
| 1574 | } |
| 1575 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1576 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1577 | "0260 Register NameServer error: 0x%x\n", |
| 1578 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | return; |
| 1580 | } |
| 1581 | |
| 1582 | pmb->context1 = NULL; |
| 1583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1586 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1588 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1589 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1590 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 1591 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 1592 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 1593 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 1594 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 1595 | |
| 1596 | /* Issue SCR just before NameServer GID_FT Query */ |
| 1597 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | } |
| 1599 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1600 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1602 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1604 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | } |
| 1606 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1607 | /* decrement the node reference count held for this |
| 1608 | * callback function. |
| 1609 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1610 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1612 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1613 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | |
| 1615 | return; |
| 1616 | } |
| 1617 | |
| 1618 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1621 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1622 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | struct lpfc_rport_data *rdata; |
| 1624 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | |
| 1627 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1628 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 1629 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1630 | rport_ids.port_id = ndlp->nlp_DID; |
| 1631 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1632 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1633 | /* |
| 1634 | * We leave our node pointer in rport->dd_data when we unregister a |
| 1635 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 1636 | * rport->dd_data points. So, if we're reusing a previously |
| 1637 | * registered port, drop the reference that we took the last time we |
| 1638 | * registered the port. |
| 1639 | */ |
| 1640 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1641 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1642 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1643 | |
| 1644 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 1645 | "rport add: did:x%x flg:x%x type x%x", |
| 1646 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 1647 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1649 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 1651 | "Warning: fc_remote_port_add failed\n"); |
| 1652 | return; |
| 1653 | } |
| 1654 | |
| 1655 | /* initialize static port data */ |
| 1656 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 1657 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1659 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 1660 | |
| 1661 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 1662 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 1663 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 1664 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1665 | |
| 1666 | |
| 1667 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 1668 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 1669 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 1670 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1671 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 1672 | ndlp->nlp_sid = rport->scsi_target_id; |
| 1673 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1674 | return; |
| 1675 | } |
| 1676 | |
| 1677 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1679 | { |
| 1680 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1681 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1682 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 1683 | "rport delete: did:x%x flg:x%x type x%x", |
| 1684 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 1685 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1686 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | |
| 1688 | return; |
| 1689 | } |
| 1690 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1691 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1693 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1694 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1695 | |
| 1696 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1697 | switch (state) { |
| 1698 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1699 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1700 | break; |
| 1701 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1702 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1703 | break; |
| 1704 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1705 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1706 | break; |
| 1707 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1709 | break; |
| 1710 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1712 | break; |
| 1713 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1714 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1715 | break; |
| 1716 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1717 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1718 | break; |
| 1719 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1720 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1721 | break; |
| 1722 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1724 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 1725 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1726 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1727 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1728 | int old_state, int new_state) |
| 1729 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1731 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1732 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
| 1733 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 1734 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 1735 | ndlp->nlp_type |= NLP_FC_NODE; |
| 1736 | } |
| 1737 | if (new_state == NLP_STE_MAPPED_NODE) |
| 1738 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 1739 | if (new_state == NLP_STE_NPR_NODE) |
| 1740 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1742 | /* Transport interface */ |
| 1743 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 1744 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | vport->phba->nport_event_cnt++; |
| 1746 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1747 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1749 | if (new_state == NLP_STE_MAPPED_NODE || |
| 1750 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1752 | /* |
| 1753 | * Tell the fc transport about the port, if we haven't |
| 1754 | * already. If we have, and it's a scsi entity, be |
| 1755 | * sure to unblock any attached scsi devices |
| 1756 | */ |
| 1757 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1758 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1759 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 1760 | (vport->stat_data_enabled)) { |
| 1761 | /* |
| 1762 | * A new target is discovered, if there is no buffer for |
| 1763 | * statistical data collection allocate buffer. |
| 1764 | */ |
| 1765 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 1766 | sizeof(struct lpfc_scsicmd_bkt), |
| 1767 | GFP_KERNEL); |
| 1768 | |
| 1769 | if (!ndlp->lat_data) |
| 1770 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 1771 | "0286 lpfc_nlp_state_cleanup failed to " |
| 1772 | "allocate statistical data buffer DID " |
| 1773 | "0x%x\n", ndlp->nlp_DID); |
| 1774 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1775 | /* |
| 1776 | * if we added to Mapped list, but the remote port |
| 1777 | * registration failed or assigned a target id outside |
| 1778 | * our presentable range - move the node to the |
| 1779 | * Unmapped List |
| 1780 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1781 | if (new_state == NLP_STE_MAPPED_NODE && |
| 1782 | (!ndlp->rport || |
| 1783 | ndlp->rport->scsi_target_id == -1 || |
| 1784 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1785 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1786 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1787 | spin_unlock_irq(shost->host_lock); |
| 1788 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1792 | static char * |
| 1793 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 1794 | { |
| 1795 | static char *states[] = { |
| 1796 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 1797 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 1798 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 1799 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 1800 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 1801 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 1802 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 1803 | [NLP_STE_NPR_NODE] = "NPR", |
| 1804 | }; |
| 1805 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1806 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1807 | strlcpy(buffer, states[state], size); |
| 1808 | else |
| 1809 | snprintf(buffer, size, "unknown (%d)", state); |
| 1810 | return buffer; |
| 1811 | } |
| 1812 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1813 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 1815 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1816 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1818 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1819 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1820 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1821 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1822 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 1823 | ndlp->nlp_DID, |
| 1824 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 1825 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1826 | |
| 1827 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 1828 | "node statechg did:x%x old:%d ste:%d", |
| 1829 | ndlp->nlp_DID, old_state, state); |
| 1830 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1831 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1832 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1834 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 1835 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 1836 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 1837 | } |
| 1838 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1839 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | spin_lock_irq(shost->host_lock); |
| 1841 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 1842 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1843 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1844 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1845 | |
| 1846 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1847 | lpfc_nlp_counters(vport, state, 1); |
| 1848 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1852 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 1853 | { |
| 1854 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1855 | |
| 1856 | if (list_empty(&ndlp->nlp_listp)) { |
| 1857 | spin_lock_irq(shost->host_lock); |
| 1858 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 1859 | spin_unlock_irq(shost->host_lock); |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1865 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1867 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1868 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1869 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1870 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 1871 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1872 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1873 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1874 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1875 | NLP_STE_UNUSED_NODE); |
| 1876 | } |
| 1877 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 1878 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1879 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 1880 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1881 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1882 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 1883 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 1884 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 1885 | NLP_STE_UNUSED_NODE); |
| 1886 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1888 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1889 | * @vport: Pointer to Virtual Port object. |
| 1890 | * @ndlp: Pointer to FC node object. |
| 1891 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1892 | * |
| 1893 | * This function is always called when node object need to be initialized. |
| 1894 | * It initializes all the fields of the node object. Although the reference |
| 1895 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 1896 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 1897 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 1898 | * the final release of ndlp is determined by its reference count. And, the |
| 1899 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1900 | **/ |
| 1901 | static inline void |
| 1902 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 1903 | uint32_t did) |
| 1904 | { |
| 1905 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 1906 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 1907 | init_timer(&ndlp->nlp_delayfunc); |
| 1908 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 1909 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 1910 | ndlp->nlp_DID = did; |
| 1911 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1912 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1913 | ndlp->nlp_sid = NLP_NO_SID; |
| 1914 | kref_init(&ndlp->kref); |
| 1915 | NLP_INT_NODE_ACT(ndlp); |
| 1916 | atomic_set(&ndlp->cmd_pending, 0); |
| 1917 | ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; |
| 1918 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1919 | |
| 1920 | struct lpfc_nodelist * |
| 1921 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 1922 | int state) |
| 1923 | { |
| 1924 | struct lpfc_hba *phba = vport->phba; |
| 1925 | uint32_t did; |
| 1926 | unsigned long flags; |
| 1927 | |
| 1928 | if (!ndlp) |
| 1929 | return NULL; |
| 1930 | |
| 1931 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 1932 | /* The ndlp should not be in memory free mode */ |
| 1933 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 1934 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1935 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 1936 | "0277 lpfc_enable_node: ndlp:x%p " |
| 1937 | "usgmap:x%x refcnt:%d\n", |
| 1938 | (void *)ndlp, ndlp->nlp_usg_map, |
| 1939 | atomic_read(&ndlp->kref.refcount)); |
| 1940 | return NULL; |
| 1941 | } |
| 1942 | /* The ndlp should not already be in active mode */ |
| 1943 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 1944 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1945 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 1946 | "0278 lpfc_enable_node: ndlp:x%p " |
| 1947 | "usgmap:x%x refcnt:%d\n", |
| 1948 | (void *)ndlp, ndlp->nlp_usg_map, |
| 1949 | atomic_read(&ndlp->kref.refcount)); |
| 1950 | return NULL; |
| 1951 | } |
| 1952 | |
| 1953 | /* Keep the original DID */ |
| 1954 | did = ndlp->nlp_DID; |
| 1955 | |
| 1956 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 1957 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 1958 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1959 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1960 | |
| 1961 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1962 | |
| 1963 | if (state != NLP_STE_UNUSED_NODE) |
| 1964 | lpfc_nlp_set_state(vport, ndlp, state); |
| 1965 | |
| 1966 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 1967 | "node enable: did:x%x", |
| 1968 | ndlp->nlp_DID, 0, 0); |
| 1969 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1973 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1974 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1975 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1976 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1977 | * 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] | 1978 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 1979 | * until ALL other outstanding threads have completed. We check |
| 1980 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1981 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1982 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1983 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1984 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1985 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1986 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | /* |
| 1990 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 1991 | */ |
| 1992 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1995 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1996 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | uint32_t tmo; |
| 1998 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1999 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2000 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2001 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 2002 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2003 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2004 | * FC spec states we need 3 * ratov for CT requests |
| 2005 | */ |
| 2006 | tmo = ((phba->fc_ratov * 3) + 3); |
| 2007 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2009 | |
| 2010 | if (!timer_pending(&vport->fc_disctmo)) { |
| 2011 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2012 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 2013 | tmo, vport->port_state, vport->fc_flag); |
| 2014 | } |
| 2015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2016 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 2017 | spin_lock_irq(shost->host_lock); |
| 2018 | vport->fc_flag |= FC_DISC_TMO; |
| 2019 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | |
| 2021 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2022 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2023 | "0247 Start Discovery Timer state x%x " |
| 2024 | "Data: x%x x%lx x%x x%x\n", |
| 2025 | vport->port_state, tmo, |
| 2026 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 2027 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | |
| 2029 | return; |
| 2030 | } |
| 2031 | |
| 2032 | /* |
| 2033 | * Cancel rescue timer for Discovery / RSCN handling |
| 2034 | */ |
| 2035 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2036 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2039 | unsigned long iflags; |
| 2040 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2041 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2042 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 2043 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 2044 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | if (vport->fc_flag & FC_DISC_TMO) { |
| 2047 | spin_lock_irqsave(shost->host_lock, iflags); |
| 2048 | vport->fc_flag &= ~FC_DISC_TMO; |
| 2049 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 2050 | del_timer_sync(&vport->fc_disctmo); |
| 2051 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 2052 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 2053 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2057 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2058 | "0248 Cancel Discovery Timer state x%x " |
| 2059 | "Data: x%x x%x x%x\n", |
| 2060 | vport->port_state, vport->fc_flag, |
| 2061 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2062 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | /* |
| 2066 | * Check specified ring for outstanding IOCB on the SLI queue |
| 2067 | * Return true if iocb matches the specified nport |
| 2068 | */ |
| 2069 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2070 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 2071 | struct lpfc_sli_ring *pring, |
| 2072 | struct lpfc_iocbq *iocb, |
| 2073 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | struct lpfc_sli *psli = &phba->sli; |
| 2076 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2077 | struct lpfc_vport *vport = ndlp->vport; |
| 2078 | |
| 2079 | if (iocb->vport != vport) |
| 2080 | return 0; |
| 2081 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | if (pring->ringno == LPFC_ELS_RING) { |
| 2083 | switch (icmd->ulpCommand) { |
| 2084 | case CMD_GEN_REQUEST64_CR: |
| 2085 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2086 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 2088 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 2089 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | case CMD_XMIT_ELS_RSP64_CX: |
| 2091 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2092 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2094 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
| 2096 | } else if (pring->ringno == psli->fcp_ring) { |
| 2097 | /* Skip match check if waiting to relogin to FCP target */ |
| 2098 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2099 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2100 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | } |
| 2102 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2103 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | } |
| 2105 | } else if (pring->ringno == psli->next_ring) { |
| 2106 | |
| 2107 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2108 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /* |
| 2112 | * Free resources / clean up outstanding I/Os |
| 2113 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 2114 | */ |
| 2115 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2116 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2118 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | struct lpfc_sli *psli; |
| 2120 | struct lpfc_sli_ring *pring; |
| 2121 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | uint32_t rpi, i; |
| 2123 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2124 | lpfc_fabric_abort_nport(ndlp); |
| 2125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | /* |
| 2127 | * Everything that matches on txcmplq will be returned |
| 2128 | * by firmware with a no rpi error. |
| 2129 | */ |
| 2130 | psli = &phba->sli; |
| 2131 | rpi = ndlp->nlp_rpi; |
| 2132 | if (rpi) { |
| 2133 | /* Now process each ring */ |
| 2134 | for (i = 0; i < psli->num_rings; i++) { |
| 2135 | pring = &psli->ring[i]; |
| 2136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2137 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2139 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | /* |
| 2141 | * Check to see if iocb matches the nport we are |
| 2142 | * looking for |
| 2143 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2144 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 2145 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | /* It matches, so deque and call compl |
| 2147 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2148 | list_move_tail(&iocb->list, |
| 2149 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | } |
| 2152 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2153 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | } |
| 2155 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2156 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2157 | /* Cancel all the IOCBs from the completions list */ |
| 2158 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 2159 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2160 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2161 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | /* |
| 2165 | * Free rpi associated with LPFC_NODELIST entry. |
| 2166 | * This routine is called from lpfc_freenode(), when we are removing |
| 2167 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 2168 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 2169 | * to the remote NPort. In addition, it is called after we receive |
| 2170 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 2171 | * we are waiting to PLOGI back to the remote NPort. |
| 2172 | */ |
| 2173 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | struct lpfc_hba *phba = vport->phba; |
| 2177 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | int rc; |
| 2179 | |
| 2180 | if (ndlp->nlp_rpi) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2181 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2182 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2183 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2184 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2185 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2186 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | lpfc_no_rpi(phba, ndlp); |
| 2191 | ndlp->nlp_rpi = 0; |
| 2192 | return 1; |
| 2193 | } |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | void |
| 2198 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 2199 | { |
| 2200 | struct lpfc_hba *phba = vport->phba; |
| 2201 | LPFC_MBOXQ_t *mbox; |
| 2202 | int rc; |
| 2203 | |
| 2204 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2205 | if (mbox) { |
| 2206 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 2207 | mbox->vport = vport; |
| 2208 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2209 | mbox->context1 = NULL; |
| 2210 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2211 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2213 | |
| 2214 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 2215 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2216 | "1836 Could not issue " |
| 2217 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | void |
| 2222 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 2223 | { |
| 2224 | struct lpfc_hba *phba = vport->phba; |
| 2225 | LPFC_MBOXQ_t *mbox; |
| 2226 | int rc; |
| 2227 | |
| 2228 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2229 | if (mbox) { |
| 2230 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 2231 | mbox->vport = vport; |
| 2232 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2233 | mbox->context1 = NULL; |
| 2234 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2235 | if (rc != MBX_TIMEOUT) |
| 2236 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2237 | |
| 2238 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2239 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2240 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2241 | "unreg_did (default rpis) status %d\n", |
| 2242 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | /* |
| 2247 | * Free resources associated with LPFC_NODELIST entry |
| 2248 | * so it can be freed. |
| 2249 | */ |
| 2250 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2254 | struct lpfc_hba *phba = vport->phba; |
| 2255 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | |
| 2258 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2259 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2260 | "0900 Cleanup node for NPort x%x " |
| 2261 | "Data: x%x x%x x%x\n", |
| 2262 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 2263 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2264 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2265 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2266 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 2267 | "usgmap:x%x refcnt:%d\n", |
| 2268 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2269 | atomic_read(&ndlp->kref.refcount)); |
| 2270 | lpfc_dequeue_node(vport, ndlp); |
| 2271 | } else { |
| 2272 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2273 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 2274 | "usgmap:x%x refcnt:%d\n", |
| 2275 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2276 | atomic_read(&ndlp->kref.refcount)); |
| 2277 | lpfc_disable_node(vport, ndlp); |
| 2278 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 2281 | if ((mb = phba->sli.mbox_active)) { |
| 2282 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && |
| 2283 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 2284 | mb->context2 = NULL; |
| 2285 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2286 | } |
| 2287 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2288 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2289 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 2291 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 2294 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2295 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | kfree(mp); |
| 2297 | } |
| 2298 | list_del(&mb->list); |
| 2299 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2300 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 2301 | * the ndlp reference count as we are in the process |
| 2302 | * of lpfc_nlp_release. |
| 2303 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | } |
| 2305 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2308 | lpfc_els_abort(phba, ndlp); |
| 2309 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2311 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2312 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2314 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 2316 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2317 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 2318 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2322 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | /* |
| 2326 | * Check to see if we can free the nlp back to the freelist. |
| 2327 | * If we are in the middle of using the nlp in the discovery state |
| 2328 | * machine, defer the free till we reach the end of the state machine. |
| 2329 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2330 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2331 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2333 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2334 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2335 | LPFC_MBOXQ_t *mbox; |
| 2336 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2338 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2339 | if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) { |
| 2340 | /* For this case we need to cleanup the default rpi |
| 2341 | * allocated by the firmware. |
| 2342 | */ |
| 2343 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 2344 | != NULL) { |
| 2345 | rc = lpfc_reg_login(phba, vport->vpi, ndlp->nlp_DID, |
| 2346 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 2347 | if (rc) { |
| 2348 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2349 | } |
| 2350 | else { |
| 2351 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 2352 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 2353 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2354 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2355 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 2356 | if (rc == MBX_NOT_FINISHED) { |
| 2357 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2363 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2365 | * We can get here with a non-NULL ndlp->rport because when we |
| 2366 | * unregister a rport we don't break the rport/node linkage. So if we |
| 2367 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2369 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2370 | rdata = ndlp->rport->dd_data; |
| 2371 | rdata->pnode = NULL; |
| 2372 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2378 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | |
| 2382 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2383 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | /* First check for Direct match */ |
| 2386 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2387 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | |
| 2389 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2390 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2392 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | matchdid.un.word = did; |
| 2396 | ndlpdid.un.word = ndlp->nlp_DID; |
| 2397 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 2398 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 2399 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 2400 | if ((ndlpdid.un.b.domain == 0) && |
| 2401 | (ndlpdid.un.b.area == 0)) { |
| 2402 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2403 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2405 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | matchdid.un.word = ndlp->nlp_DID; |
| 2409 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 2410 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 2411 | if ((matchdid.un.b.domain == 0) && |
| 2412 | (matchdid.un.b.area == 0)) { |
| 2413 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2414 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2418 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
| 2420 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2421 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2422 | static struct lpfc_nodelist * |
| 2423 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 2425 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | uint32_t data1; |
| 2427 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2428 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 2429 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2430 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 2431 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 2432 | ((uint32_t) ndlp->nlp_type << 8) | |
| 2433 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2434 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2435 | "0929 FIND node DID " |
| 2436 | "Data: x%p x%x x%x x%x\n", |
| 2437 | ndlp, ndlp->nlp_DID, |
| 2438 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2439 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | } |
| 2441 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 2442 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2444 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2445 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | return NULL; |
| 2447 | } |
| 2448 | |
| 2449 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2450 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2452 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2455 | spin_lock_irq(shost->host_lock); |
| 2456 | ndlp = __lpfc_findnode_did(vport, did); |
| 2457 | spin_unlock_irq(shost->host_lock); |
| 2458 | return ndlp; |
| 2459 | } |
| 2460 | |
| 2461 | struct lpfc_nodelist * |
| 2462 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 2463 | { |
| 2464 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2465 | struct lpfc_nodelist *ndlp; |
| 2466 | |
| 2467 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2468 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2469 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 2470 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | return NULL; |
| 2472 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | if (!ndlp) |
| 2475 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2476 | lpfc_nlp_init(vport, ndlp, did); |
| 2477 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2478 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2480 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2482 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2483 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 2484 | if (!ndlp) |
| 2485 | return NULL; |
| 2486 | spin_lock_irq(shost->host_lock); |
| 2487 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2488 | spin_unlock_irq(shost->host_lock); |
| 2489 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2491 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2492 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 2493 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2495 | /* If we've already recieved a PLOGI from this NPort |
| 2496 | * we don't need to try to discover it again. |
| 2497 | */ |
| 2498 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 2499 | return NULL; |
| 2500 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2501 | /* Since this node is marked for discovery, |
| 2502 | * delay timeout is not needed. |
| 2503 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2504 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2505 | spin_lock_irq(shost->host_lock); |
| 2506 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2507 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 2508 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2510 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2511 | /* If we've already recieved a PLOGI from this NPort, |
| 2512 | * or we are already in the process of discovery on it, |
| 2513 | * we don't need to try to discover it again. |
| 2514 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2515 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2516 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 2517 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2519 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2520 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2522 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2523 | } |
| 2524 | return ndlp; |
| 2525 | } |
| 2526 | |
| 2527 | /* Build a list of nodes to discover based on the loopmap */ |
| 2528 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2529 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2531 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | int j; |
| 2533 | uint32_t alpa, index; |
| 2534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2535 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2536 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | |
| 2538 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | |
| 2541 | /* Check for loop map present or not */ |
| 2542 | if (phba->alpa_map[0]) { |
| 2543 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 2544 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2545 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2547 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | } |
| 2549 | } else { |
| 2550 | /* No alpamap, so try all alpa's */ |
| 2551 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 2552 | /* If cfg_scan_down is set, start from highest |
| 2553 | * ALPA (0xef) to lowest (0x1). |
| 2554 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2555 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | index = j; |
| 2557 | else |
| 2558 | index = FC_MAXLOOP - j - 1; |
| 2559 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2560 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2562 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | return; |
| 2566 | } |
| 2567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2568 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2569 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2572 | struct lpfc_sli *psli = &phba->sli; |
| 2573 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 2574 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 2575 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 2576 | int rc; |
| 2577 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2578 | /* |
| 2579 | * if it's not a physical port or if we already send |
| 2580 | * clear_la then don't send it. |
| 2581 | */ |
| 2582 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 2583 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 2584 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | return; |
| 2586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | /* Link up discovery */ |
| 2588 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 2589 | phba->link_state = LPFC_CLEAR_LA; |
| 2590 | lpfc_clear_la(phba, mbox); |
| 2591 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 2592 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2593 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2594 | if (rc == MBX_NOT_FINISHED) { |
| 2595 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2596 | lpfc_disc_flush_list(vport); |
| 2597 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 2598 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 2599 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2600 | phba->link_state = LPFC_HBA_ERROR; |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 2606 | void |
| 2607 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 2608 | { |
| 2609 | LPFC_MBOXQ_t *regvpimbox; |
| 2610 | |
| 2611 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2612 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 2613 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2614 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 2615 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2616 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2617 | == MBX_NOT_FINISHED) { |
| 2618 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 2624 | void |
| 2625 | lpfc_disc_start(struct lpfc_vport *vport) |
| 2626 | { |
| 2627 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2628 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2629 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2631 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | |
| 2636 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | clear_la_pending = 1; |
| 2638 | else |
| 2639 | clear_la_pending = 0; |
| 2640 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2641 | if (vport->port_state < LPFC_VPORT_READY) |
| 2642 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | lpfc_set_disctmo(vport); |
| 2645 | |
| 2646 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2650 | |
| 2651 | vport->fc_prevDID = vport->fc_myDID; |
| 2652 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | |
| 2654 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2655 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2656 | "0202 Start Discovery hba state x%x " |
| 2657 | "Data: x%x x%x x%x\n", |
| 2658 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 2659 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | |
| 2661 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2662 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | |
| 2664 | if (num_sent) |
| 2665 | return; |
| 2666 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2667 | /* |
| 2668 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 2669 | * continue discovery. |
| 2670 | */ |
| 2671 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2672 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 2673 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2674 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2675 | lpfc_issue_reg_vpi(phba, vport); |
| 2676 | return; |
| 2677 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2678 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2679 | /* |
| 2680 | * For SLI2, we need to set port_state to READY and continue |
| 2681 | * discovery. |
| 2682 | */ |
| 2683 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 2684 | /* If we get here, there is nothing to ADISC */ |
| 2685 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 2686 | lpfc_issue_clear_la(phba, vport); |
| 2687 | |
| 2688 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2689 | vport->num_disc_nodes = 0; |
| 2690 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2691 | if (vport->fc_npr_cnt) |
| 2692 | lpfc_els_disc_plogi(vport); |
| 2693 | |
| 2694 | if (!vport->num_disc_nodes) { |
| 2695 | spin_lock_irq(shost->host_lock); |
| 2696 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2697 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2698 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | } |
| 2700 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2701 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | } else { |
| 2703 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2705 | |
| 2706 | if (num_sent) |
| 2707 | return; |
| 2708 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | /* Check to see if more RSCNs came in while we |
| 2711 | * were processing this one. |
| 2712 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2713 | if ((vport->fc_rscn_id_cnt == 0) && |
| 2714 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 2715 | spin_lock_irq(shost->host_lock); |
| 2716 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 2717 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2718 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2719 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2720 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | return; |
| 2724 | } |
| 2725 | |
| 2726 | /* |
| 2727 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 2728 | * ring the match the sppecified nodelist. |
| 2729 | */ |
| 2730 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2733 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | struct lpfc_sli *psli; |
| 2735 | IOCB_t *icmd; |
| 2736 | struct lpfc_iocbq *iocb, *next_iocb; |
| 2737 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2738 | |
| 2739 | psli = &phba->sli; |
| 2740 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2741 | |
| 2742 | /* Error matching iocb on txq or txcmplq |
| 2743 | * First check the txq. |
| 2744 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2745 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 2747 | if (iocb->context1 != ndlp) { |
| 2748 | continue; |
| 2749 | } |
| 2750 | icmd = &iocb->iocb; |
| 2751 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 2752 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 2753 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2754 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /* Next check the txcmplq */ |
| 2760 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 2761 | if (iocb->context1 != ndlp) { |
| 2762 | continue; |
| 2763 | } |
| 2764 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 2766 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2767 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | } |
| 2769 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2770 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2771 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2772 | /* Cancel all the IOCBs from the completions list */ |
| 2773 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 2774 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | } |
| 2776 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2777 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2778 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | { |
| 2780 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2781 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2782 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2783 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 2784 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2785 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2786 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2787 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2788 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 2789 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 2790 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2791 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | } |
| 2793 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2794 | } |
| 2795 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2796 | void |
| 2797 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 2798 | { |
| 2799 | lpfc_els_flush_rscn(vport); |
| 2800 | lpfc_els_flush_cmd(vport); |
| 2801 | lpfc_disc_flush_list(vport); |
| 2802 | } |
| 2803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | /*****************************************************************************/ |
| 2805 | /* |
| 2806 | * NAME: lpfc_disc_timeout |
| 2807 | * |
| 2808 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 2809 | * |
| 2810 | * EXECUTION ENVIRONMENT: interrupt only |
| 2811 | * |
| 2812 | * CALLED FROM: |
| 2813 | * Timer function |
| 2814 | * |
| 2815 | * RETURNS: |
| 2816 | * none |
| 2817 | */ |
| 2818 | /*****************************************************************************/ |
| 2819 | void |
| 2820 | lpfc_disc_timeout(unsigned long ptr) |
| 2821 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2822 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 2823 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2824 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | unsigned long flags = 0; |
| 2826 | |
| 2827 | if (unlikely(!phba)) |
| 2828 | return; |
| 2829 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2830 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 2831 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 2832 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2833 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2834 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2836 | if (!tmo_posted) |
| 2837 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | return; |
| 2839 | } |
| 2840 | |
| 2841 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2842 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2843 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2844 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2845 | struct lpfc_hba *phba = vport->phba; |
| 2846 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2847 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2848 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | int rc, clrlaerr = 0; |
| 2850 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2851 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2852 | return; |
| 2853 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2854 | spin_lock_irq(shost->host_lock); |
| 2855 | vport->fc_flag &= ~FC_DISC_TMO; |
| 2856 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2858 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2859 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 2860 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 2861 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2862 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | |
| 2864 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2865 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 2866 | * FAN |
| 2867 | */ |
| 2868 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2869 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 2870 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2871 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2872 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2873 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2874 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2875 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2876 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 2877 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2878 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2879 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2880 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2881 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2882 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2883 | /* Fail outstanding IO now since device |
| 2884 | * is marked for PLOGI. |
| 2885 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2887 | } |
| 2888 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2889 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2890 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2891 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2892 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | break; |
| 2894 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2895 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2897 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2899 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2900 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2901 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | |
| 2903 | /* Assume no Fabric and go on with discovery. |
| 2904 | * Check for outstanding ELS FLOGI to abort. |
| 2905 | */ |
| 2906 | |
| 2907 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2908 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2909 | |
| 2910 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2911 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | break; |
| 2913 | |
| 2914 | case LPFC_FABRIC_CFG_LINK: |
| 2915 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 2916 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2917 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2918 | "0223 Timeout while waiting for " |
| 2919 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2920 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2922 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2923 | lpfc_els_abort(phba, ndlp); |
| 2924 | |
| 2925 | /* ReStart discovery */ |
| 2926 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2927 | |
| 2928 | case LPFC_NS_QRY: |
| 2929 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2930 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2931 | "0224 NameServer Query timeout " |
| 2932 | "Data: x%x x%x\n", |
| 2933 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2935 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 2936 | /* Try it one more time */ |
| 2937 | vport->fc_ns_retry++; |
| 2938 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 2939 | vport->fc_ns_retry, 0); |
| 2940 | if (rc == 0) |
| 2941 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2943 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2945 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2946 | /* |
| 2947 | * Discovery is over. |
| 2948 | * set port_state to PORT_READY if SLI2. |
| 2949 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 2950 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2951 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 2952 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2953 | lpfc_issue_reg_vpi(phba, vport); |
| 2954 | else { /* NPIV Not enabled */ |
| 2955 | lpfc_issue_clear_la(phba, vport); |
| 2956 | vport->port_state = LPFC_VPORT_READY; |
| 2957 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 2961 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2962 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2963 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2964 | "0206 Device Discovery " |
| 2965 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2966 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | break; |
| 2968 | } |
| 2969 | |
| 2970 | lpfc_linkdown(phba); |
| 2971 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 2972 | phba->cfg_link_speed); |
| 2973 | initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2974 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2975 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2976 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2977 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | if (rc == MBX_NOT_FINISHED) |
| 2979 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 2980 | |
| 2981 | break; |
| 2982 | |
| 2983 | case LPFC_DISC_AUTH: |
| 2984 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2985 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2986 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2987 | lpfc_disc_flush_list(vport); |
| 2988 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2989 | /* |
| 2990 | * set port_state to PORT_READY if SLI2. |
| 2991 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 2992 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2993 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 2994 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2995 | lpfc_issue_reg_vpi(phba, vport); |
| 2996 | else { /* NPIV Not enabled */ |
| 2997 | lpfc_issue_clear_la(phba, vport); |
| 2998 | vport->port_state = LPFC_VPORT_READY; |
| 2999 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | } |
| 3001 | break; |
| 3002 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3003 | case LPFC_VPORT_READY: |
| 3004 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3005 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3006 | "0231 RSCN timeout Data: x%x " |
| 3007 | "x%x\n", |
| 3008 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | |
| 3010 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3011 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | lpfc_els_flush_rscn(vport); |
| 3014 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | } |
| 3016 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3017 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3019 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3020 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3021 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | break; |
| 3023 | } |
| 3024 | |
| 3025 | switch (phba->link_state) { |
| 3026 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3027 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3028 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3029 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3030 | clrlaerr = 1; |
| 3031 | break; |
| 3032 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3033 | case LPFC_LINK_UP: |
| 3034 | lpfc_issue_clear_la(phba, vport); |
| 3035 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3036 | case LPFC_LINK_UNKNOWN: |
| 3037 | case LPFC_WARM_START: |
| 3038 | case LPFC_INIT_START: |
| 3039 | case LPFC_INIT_MBX_CMDS: |
| 3040 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3041 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3042 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3043 | "0230 Unexpected timeout, hba link " |
| 3044 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3045 | clrlaerr = 1; |
| 3046 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3047 | |
| 3048 | case LPFC_HBA_READY: |
| 3049 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3053 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3054 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3056 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3057 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | return; |
| 3061 | } |
| 3062 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | /* |
| 3064 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3065 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3066 | * as the completion routine when the command is |
| 3067 | * handed off to the SLI layer. |
| 3068 | */ |
| 3069 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3070 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3072 | MAILBOX_t *mb = &pmb->mb; |
| 3073 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3074 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3075 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | |
| 3077 | pmb->context1 = NULL; |
| 3078 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3083 | /* |
| 3084 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 3085 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 3086 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3088 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3089 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3090 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 3091 | else |
| 3092 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3094 | /* decrement the node reference count held for this callback |
| 3095 | * function. |
| 3096 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3097 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3099 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3100 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | |
| 3102 | return; |
| 3103 | } |
| 3104 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3105 | static int |
| 3106 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 3107 | { |
| 3108 | uint16_t *rpi = param; |
| 3109 | |
| 3110 | return ndlp->nlp_rpi == *rpi; |
| 3111 | } |
| 3112 | |
| 3113 | static int |
| 3114 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 3115 | { |
| 3116 | return memcmp(&ndlp->nlp_portname, param, |
| 3117 | sizeof(ndlp->nlp_portname)) == 0; |
| 3118 | } |
| 3119 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3120 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 3123 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3125 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3126 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3127 | return ndlp; |
| 3128 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 3129 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | } |
| 3131 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3132 | /* |
| 3133 | * 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] | 3134 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3135 | */ |
| 3136 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3137 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3138 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3139 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3140 | } |
| 3141 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3142 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3143 | * 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] | 3144 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3145 | */ |
| 3146 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3147 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3149 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3150 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3152 | spin_lock_irq(shost->host_lock); |
| 3153 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 3154 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3155 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3156 | } |
| 3157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3159 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3160 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3161 | { |
| 3162 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3163 | |
| 3164 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3165 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3166 | |
| 3167 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 3168 | "node init: did:x%x", |
| 3169 | ndlp->nlp_DID, 0, 0); |
| 3170 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | return; |
| 3172 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3173 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3174 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 3175 | * and mempool_free's the nodelist. |
| 3176 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 3177 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3178 | lpfc_nlp_release(struct kref *kref) |
| 3179 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3180 | struct lpfc_hba *phba; |
| 3181 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3182 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 3183 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3184 | |
| 3185 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3186 | "node release: did:x%x flg:x%x type:x%x", |
| 3187 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3188 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3189 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3190 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 3191 | "usgmap:x%x refcnt:%d\n", |
| 3192 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3193 | atomic_read(&ndlp->kref.refcount)); |
| 3194 | |
| 3195 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3196 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3197 | |
| 3198 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3199 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3200 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3201 | NLP_CLR_NODE_ACT(ndlp); |
| 3202 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3203 | |
| 3204 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3205 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3206 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3207 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3208 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3209 | } |
| 3210 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3211 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 3212 | * that one discovery thread won't free a ndlp while another discovery thread |
| 3213 | * is using it. |
| 3214 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3215 | struct lpfc_nodelist * |
| 3216 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 3217 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3218 | struct lpfc_hba *phba; |
| 3219 | unsigned long flags; |
| 3220 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3221 | if (ndlp) { |
| 3222 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3223 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 3224 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3225 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3226 | /* The check of ndlp usage to prevent incrementing the |
| 3227 | * ndlp reference count that is in the process of being |
| 3228 | * released. |
| 3229 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3230 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3231 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3232 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 3233 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3234 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3235 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 3236 | "usgmap:x%x refcnt:%d\n", |
| 3237 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3238 | atomic_read(&ndlp->kref.refcount)); |
| 3239 | return NULL; |
| 3240 | } else |
| 3241 | kref_get(&ndlp->kref); |
| 3242 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3243 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3244 | return ndlp; |
| 3245 | } |
| 3246 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3247 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3248 | * count goes to 0, this indicates the the associated nodelist should be |
| 3249 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 3250 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 3251 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3252 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3253 | int |
| 3254 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 3255 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3256 | struct lpfc_hba *phba; |
| 3257 | unsigned long flags; |
| 3258 | |
| 3259 | if (!ndlp) |
| 3260 | return 1; |
| 3261 | |
| 3262 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3263 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 3264 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3265 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3266 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3267 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3268 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 3269 | * possible race condition that kref_put got invoked again |
| 3270 | * after previous one has done ndlp memory free. |
| 3271 | */ |
| 3272 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 3273 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3274 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3275 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 3276 | "usgmap:x%x refcnt:%d\n", |
| 3277 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3278 | atomic_read(&ndlp->kref.refcount)); |
| 3279 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3280 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3281 | /* Check the ndlp inactivate log flag to avoid the possible |
| 3282 | * race condition that kref_put got invoked again after ndlp |
| 3283 | * is already in inactivating state. |
| 3284 | */ |
| 3285 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 3286 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3287 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3288 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 3289 | "usgmap:x%x refcnt:%d\n", |
| 3290 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3291 | atomic_read(&ndlp->kref.refcount)); |
| 3292 | return 1; |
| 3293 | } |
| 3294 | /* For last put, mark the ndlp usage flags to make sure no |
| 3295 | * other kref_get and kref_put on the same ndlp shall get |
| 3296 | * in between the process when the final kref_put has been |
| 3297 | * invoked on this ndlp. |
| 3298 | */ |
| 3299 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 3300 | /* Indicate ndlp is put to inactive state. */ |
| 3301 | NLP_SET_IACT_REQ(ndlp); |
| 3302 | /* Acknowledge ndlp memory free has been seen. */ |
| 3303 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 3304 | NLP_SET_FREE_ACK(ndlp); |
| 3305 | } |
| 3306 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3307 | /* Note, the kref_put returns 1 when decrementing a reference |
| 3308 | * count that was 1, it invokes the release callback function, |
| 3309 | * but it still left the reference count as 1 (not actually |
| 3310 | * performs the last decrementation). Otherwise, it actually |
| 3311 | * decrements the reference count and returns 0. |
| 3312 | */ |
| 3313 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3314 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3315 | |
| 3316 | /* 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] | 3317 | * by any other discovery thread. This routine returns 1 if the |
| 3318 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 3319 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3320 | */ |
| 3321 | int |
| 3322 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 3323 | { |
| 3324 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3325 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 3326 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3327 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3328 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 3329 | if (lpfc_nlp_put(ndlp)) |
| 3330 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3331 | return 0; |
| 3332 | } |