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