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