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