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