| 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 | } |
| 92 | |
| 93 | /* |
| 94 | * This function will be called when dev_loss_tmo fire. |
| 95 | */ |
| 96 | void |
| 97 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 98 | { |
| 99 | struct lpfc_rport_data *rdata; |
| 100 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 101 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 102 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 103 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 104 | int put_node; |
| 105 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 106 | |
| 107 | rdata = rport->dd_data; |
| 108 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 109 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 110 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 111 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 112 | vport = ndlp->vport; |
| 113 | phba = vport->phba; |
| 114 | |
| 115 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 116 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 117 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 118 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 119 | /* Don't defer this if we are in the process of deleting the vport |
| 120 | * or unloading the driver. The unload will cleanup the node |
| 121 | * appropriately we just need to cleanup the ndlp rport info here. |
| 122 | */ |
| 123 | if (vport->load_flag & FC_UNLOADING) { |
| 124 | put_node = rdata->pnode != NULL; |
| 125 | put_rport = ndlp->rport != NULL; |
| 126 | rdata->pnode = NULL; |
| 127 | ndlp->rport = NULL; |
| 128 | if (put_node) |
| 129 | lpfc_nlp_put(ndlp); |
| 130 | if (put_rport) |
| 131 | put_device(&rport->dev); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 136 | return; |
| 137 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 138 | evtp = &ndlp->dev_loss_evt; |
| 139 | |
| 140 | if (!list_empty(&evtp->evt_listp)) |
| 141 | return; |
| 142 | |
| 143 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 144 | /* We need to hold the node by incrementing the reference |
| 145 | * count until this queued work is done |
| 146 | */ |
| 147 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 148 | if (evtp->evt_arg1) { |
| 149 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 150 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 151 | lpfc_worker_wake_up(phba); |
| 152 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 153 | spin_unlock_irq(&phba->hbalock); |
| 154 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * This function is called from the worker thread when dev_loss_tmo |
| 160 | * expire. |
| 161 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 162 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 163 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 164 | { |
| 165 | struct lpfc_rport_data *rdata; |
| 166 | struct fc_rport *rport; |
| 167 | struct lpfc_vport *vport; |
| 168 | struct lpfc_hba *phba; |
| 169 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 170 | int put_node; |
| 171 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 172 | int warn_on = 0; |
| 173 | |
| 174 | rport = ndlp->rport; |
| 175 | |
| 176 | if (!rport) |
| 177 | return; |
| 178 | |
| 179 | rdata = rport->dd_data; |
| 180 | name = (uint8_t *) &ndlp->nlp_portname; |
| 181 | vport = ndlp->vport; |
| 182 | phba = vport->phba; |
| 183 | |
| 184 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 185 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 186 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 187 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 188 | /* Don't defer this if we are in the process of deleting the vport |
| 189 | * or unloading the driver. The unload will cleanup the node |
| 190 | * appropriately we just need to cleanup the ndlp rport info here. |
| 191 | */ |
| 192 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 193 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 194 | /* flush the target */ |
| 195 | lpfc_sli_abort_iocb(vport, |
| 196 | &phba->sli.ring[phba->sli.fcp_ring], |
| 197 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 198 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 199 | put_node = rdata->pnode != NULL; |
| 200 | put_rport = ndlp->rport != NULL; |
| 201 | rdata->pnode = NULL; |
| 202 | ndlp->rport = NULL; |
| 203 | if (put_node) |
| 204 | lpfc_nlp_put(ndlp); |
| 205 | if (put_rport) |
| 206 | put_device(&rport->dev); |
| 207 | return; |
| 208 | } |
| 209 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 210 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 211 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 212 | "0284 Devloss timeout Ignored on " |
| 213 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 214 | "NPort x%x\n", |
| 215 | *name, *(name+1), *(name+2), *(name+3), |
| 216 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 217 | ndlp->nlp_DID); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 218 | return; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 219 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 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 | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 240 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 241 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 242 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 243 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 244 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 245 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 246 | *name, *(name+1), *(name+2), *(name+3), |
| 247 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 248 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 249 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 250 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 251 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 252 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 253 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 254 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 255 | *name, *(name+1), *(name+2), *(name+3), |
| 256 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 257 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 258 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 259 | } |
| 260 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 261 | put_node = rdata->pnode != NULL; |
| 262 | put_rport = ndlp->rport != NULL; |
| 263 | rdata->pnode = NULL; |
| 264 | ndlp->rport = NULL; |
| 265 | if (put_node) |
| 266 | lpfc_nlp_put(ndlp); |
| 267 | if (put_rport) |
| 268 | put_device(&rport->dev); |
| 269 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 270 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 271 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 272 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 273 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 274 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 275 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 277 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 278 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 279 | { |
| 280 | struct lpfc_work_evt *evtp = NULL; |
| 281 | struct lpfc_nodelist *ndlp; |
| 282 | int free_evt; |
| 283 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 284 | spin_lock_irq(&phba->hbalock); |
| 285 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 287 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 288 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 290 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 292 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 293 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 294 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 295 | /* decrement the node reference count held |
| 296 | * for this queued work |
| 297 | */ |
| 298 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 299 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 300 | case LPFC_EVT_DEV_LOSS: |
| 301 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 302 | lpfc_dev_loss_tmo_handler(ndlp); |
| 303 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 304 | /* decrement the node reference count held for |
| 305 | * this queued work |
| 306 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 307 | lpfc_nlp_put(ndlp); |
| 308 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 309 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 310 | if (phba->link_state < LPFC_LINK_DOWN) |
| 311 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 312 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 313 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 314 | complete((struct completion *)(evtp->evt_arg2)); |
| 315 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 316 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 317 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 318 | lpfc_offline_prep(phba); |
| 319 | *(int *)(evtp->evt_arg1) = 0; |
| 320 | complete((struct completion *)(evtp->evt_arg2)); |
| 321 | break; |
| 322 | case LPFC_EVT_OFFLINE: |
| 323 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 324 | lpfc_sli_brdrestart(phba); |
| 325 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 326 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 327 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 328 | complete((struct completion *)(evtp->evt_arg2)); |
| 329 | break; |
| 330 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 331 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 332 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 333 | lpfc_sli_brdreset(phba); |
| 334 | lpfc_hba_down_post(phba); |
| 335 | *(int *)(evtp->evt_arg1) = |
| 336 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 337 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 338 | complete((struct completion *)(evtp->evt_arg2)); |
| 339 | break; |
| 340 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 341 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 342 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 343 | = (phba->pport->stopped) |
| 344 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 345 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 346 | complete((struct completion *)(evtp->evt_arg2)); |
| 347 | break; |
| 348 | } |
| 349 | if (free_evt) |
| 350 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 351 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 353 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | |
| 355 | } |
| 356 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 357 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 358 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 359 | { |
| 360 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 361 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 362 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 363 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 364 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 365 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 366 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 367 | ha_copy = phba->work_ha; |
| 368 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 369 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 371 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 372 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | lpfc_handle_eratt(phba); |
| 374 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 375 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 376 | lpfc_sli_handle_mb_event(phba); |
| 377 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 378 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 379 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 380 | |
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 | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1016 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1017 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | uint32_t control; |
| 1019 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1020 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1021 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1022 | control = readl(phba->HCregaddr); |
| 1023 | control |= HC_LAINT_ENA; |
| 1024 | writel(control, phba->HCregaddr); |
| 1025 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1027 | } |
| 1028 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1029 | static void |
| 1030 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 1031 | { |
| 1032 | lpfc_linkdown(phba); |
| 1033 | lpfc_enable_la(phba); |
| 1034 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 1035 | } |
| 1036 | |
| 1037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | /* |
| 1039 | * This routine handles processing a READ_LA mailbox |
| 1040 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1041 | * as the completion routine when the command is |
| 1042 | * handed off to the SLI layer. |
| 1043 | */ |
| 1044 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1045 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | struct lpfc_vport *vport = pmb->vport; |
| 1048 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | READ_LA_VAR *la; |
| 1050 | MAILBOX_t *mb = &pmb->mb; |
| 1051 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 1052 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1053 | /* Unblock ELS traffic */ |
| 1054 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | /* Check for error */ |
| 1056 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1057 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1058 | "1307 READ_LA mbox error x%x state x%x\n", |
| 1059 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1061 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 1063 | } |
| 1064 | |
| 1065 | la = (READ_LA_VAR *) & pmb->mb.un.varReadLA; |
| 1066 | |
| 1067 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 1068 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1069 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1070 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1071 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1072 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1073 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 1074 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | if (((phba->fc_eventTag + 1) < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1077 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1079 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | if (phba->fc_eventTag != 0) |
| 1081 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1083 | |
| 1084 | phba->fc_eventTag = la->eventTag; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1085 | if (la->mm) |
| 1086 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 1087 | else |
| 1088 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1090 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1091 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1092 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1093 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1094 | "1306 Link Up Event in loop back mode " |
| 1095 | "x%x received Data: x%x x%x x%x x%x\n", |
| 1096 | la->eventTag, phba->fc_eventTag, |
| 1097 | la->granted_AL_PA, la->UlnkSpeed, |
| 1098 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 1099 | } else { |
| 1100 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1101 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1102 | "Data: x%x x%x x%x x%x x%x x%x %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1103 | la->eventTag, phba->fc_eventTag, |
| 1104 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1105 | phba->alpa_map[0], |
| 1106 | la->mm, la->fa, |
| 1107 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 1108 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1109 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1110 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1112 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 1113 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1114 | "1308 Link Down Event in loop back mode " |
| 1115 | "x%x received " |
| 1116 | "Data: x%x x%x x%x\n", |
| 1117 | la->eventTag, phba->fc_eventTag, |
| 1118 | phba->pport->port_state, vport->fc_flag); |
| 1119 | } |
| 1120 | else { |
| 1121 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1122 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1123 | "Data: x%x x%x x%x x%x x%x\n", |
| 1124 | la->eventTag, phba->fc_eventTag, |
| 1125 | phba->pport->port_state, vport->fc_flag, |
| 1126 | la->mm, la->fa); |
| 1127 | } |
| 1128 | lpfc_mbx_issue_link_down(phba); |
| 1129 | } |
| 1130 | if (la->mm && la->attType == AT_LINK_UP) { |
| 1131 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 1132 | phba->fc_stat.LinkDown++; |
| 1133 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1134 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1135 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1136 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1137 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1138 | lpfc_mbx_issue_link_down(phba); |
| 1139 | } else |
| 1140 | lpfc_enable_la(phba); |
| 1141 | |
| 1142 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1143 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 1144 | "Data: x%x x%x x%x\n", |
| 1145 | la->eventTag, phba->fc_eventTag, |
| 1146 | phba->pport->port_state, vport->fc_flag); |
| 1147 | /* |
| 1148 | * The cmnd that triggered this will be waiting for this |
| 1149 | * signal. |
| 1150 | */ |
| 1151 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 1152 | if (phba->wait_4_mlo_maint_flg) { |
| 1153 | phba->wait_4_mlo_maint_flg = 0; |
| 1154 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1155 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | if (la->fa) { |
| 1159 | if (la->mm) |
| 1160 | lpfc_issue_clear_la(phba, vport); |
| 1161 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1162 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 1166 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1167 | kfree(mp); |
| 1168 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1169 | return; |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | * This routine handles processing a REG_LOGIN mailbox |
| 1174 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1175 | * as the completion routine when the command is |
| 1176 | * handed off to the SLI layer. |
| 1177 | */ |
| 1178 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1179 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1180 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1181 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1182 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1183 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1185 | pmb->context1 = NULL; |
| 1186 | |
| 1187 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1188 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1190 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1191 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1192 | /* decrement the node reference count held for this callback |
| 1193 | * function. |
| 1194 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1195 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | |
| 1197 | return; |
| 1198 | } |
| 1199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1200 | static void |
| 1201 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1202 | { |
| 1203 | MAILBOX_t *mb = &pmb->mb; |
| 1204 | struct lpfc_vport *vport = pmb->vport; |
| 1205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1206 | |
| 1207 | switch (mb->mbxStatus) { |
| 1208 | case 0x0011: |
| 1209 | case 0x0020: |
| 1210 | case 0x9700: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1211 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1212 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 1213 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1214 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1215 | } |
| 1216 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 1217 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1218 | /* |
| 1219 | * This shost reference might have been taken at the beginning of |
| 1220 | * lpfc_vport_delete() |
| 1221 | */ |
| 1222 | if (vport->load_flag & FC_UNLOADING) |
| 1223 | scsi_host_put(shost); |
| 1224 | } |
| 1225 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1226 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1227 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 1228 | { |
| 1229 | struct lpfc_hba *phba = vport->phba; |
| 1230 | LPFC_MBOXQ_t *mbox; |
| 1231 | int rc; |
| 1232 | |
| 1233 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1234 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1235 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1236 | |
| 1237 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 1238 | mbox->vport = vport; |
| 1239 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1240 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1241 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1242 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 1243 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1244 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1245 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1246 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1247 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1248 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void |
| 1252 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1253 | { |
| 1254 | struct lpfc_vport *vport = pmb->vport; |
| 1255 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1256 | MAILBOX_t *mb = &pmb->mb; |
| 1257 | |
| 1258 | switch (mb->mbxStatus) { |
| 1259 | case 0x0011: |
| 1260 | case 0x9601: |
| 1261 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1262 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1263 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 1264 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1265 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 1266 | spin_lock_irq(shost->host_lock); |
| 1267 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 1268 | spin_unlock_irq(shost->host_lock); |
| 1269 | vport->fc_myDID = 0; |
| 1270 | goto out; |
| 1271 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1272 | |
| 1273 | vport->num_disc_nodes = 0; |
| 1274 | /* go thru NPR list and issue ELS PLOGIs */ |
| 1275 | if (vport->fc_npr_cnt) |
| 1276 | lpfc_els_disc_plogi(vport); |
| 1277 | |
| 1278 | if (!vport->num_disc_nodes) { |
| 1279 | spin_lock_irq(shost->host_lock); |
| 1280 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1281 | spin_unlock_irq(shost->host_lock); |
| 1282 | lpfc_can_disctmo(vport); |
| 1283 | } |
| 1284 | vport->port_state = LPFC_VPORT_READY; |
| 1285 | |
| 1286 | out: |
| 1287 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1288 | return; |
| 1289 | } |
| 1290 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | /* |
| 1292 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 1293 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1294 | * as the completion routine when the command is |
| 1295 | * handed off to the SLI layer. |
| 1296 | */ |
| 1297 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1298 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | MAILBOX_t *mb = &pmb->mb; |
| 1302 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1303 | struct lpfc_nodelist *ndlp; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1304 | struct lpfc_vport **vports; |
| 1305 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1307 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1308 | pmb->context1 = NULL; |
| 1309 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | if (mb->mbxStatus) { |
| 1311 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1312 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1313 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1315 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1316 | /* FLOGI failed, use loop map to make discovery list */ |
| 1317 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1319 | /* Start discovery */ |
| 1320 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1321 | /* Decrement the reference count to ndlp after the |
| 1322 | * reference to the ndlp are done. |
| 1323 | */ |
| 1324 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1325 | return; |
| 1326 | } |
| 1327 | |
| 1328 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1330 | "0258 Register Fabric login error: 0x%x\n", |
| 1331 | mb->mbxStatus); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1332 | /* Decrement the reference count to ndlp after the reference |
| 1333 | * to the ndlp are done. |
| 1334 | */ |
| 1335 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1336 | return; |
| 1337 | } |
| 1338 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1344 | vports = lpfc_create_vport_work_array(phba); |
| 1345 | if (vports != NULL) |
| 1346 | for(i = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1347 | i <= phba->max_vpi && vports[i] != NULL; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1348 | i++) { |
| 1349 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 1350 | continue; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1351 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1352 | lpfc_vport_set_state(vports[i], |
| 1353 | FC_VPORT_LINKDOWN); |
| 1354 | continue; |
| 1355 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1356 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 1357 | lpfc_initial_fdisc(vports[i]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1358 | else { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1359 | lpfc_vport_set_state(vports[i], |
| 1360 | FC_VPORT_NO_FABRIC_SUPP); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1361 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1362 | LOG_ELS, |
| 1363 | "0259 No NPIV " |
| 1364 | "Fabric support\n"); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1365 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1366 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1367 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1368 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1372 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1373 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1374 | |
| 1375 | /* Drop the reference count from the mbox at the end after |
| 1376 | * all the current reference to the ndlp have been done. |
| 1377 | */ |
| 1378 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | return; |
| 1380 | } |
| 1381 | |
| 1382 | /* |
| 1383 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 1384 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1385 | * as the completion routine when the command is |
| 1386 | * handed off to the SLI layer. |
| 1387 | */ |
| 1388 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1389 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1391 | MAILBOX_t *mb = &pmb->mb; |
| 1392 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 1393 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 1394 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | |
| 1396 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1397 | out: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1398 | /* decrement the node reference count held for this |
| 1399 | * callback function. |
| 1400 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1401 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1403 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1404 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1405 | |
| 1406 | /* If no other thread is using the ndlp, free it */ |
| 1407 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1409 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1410 | /* |
| 1411 | * RegLogin failed, use loop map to make discovery |
| 1412 | * list |
| 1413 | */ |
| 1414 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1415 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1416 | /* Start discovery */ |
| 1417 | lpfc_disc_start(vport); |
| 1418 | return; |
| 1419 | } |
| 1420 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1421 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1422 | "0260 Register NameServer error: 0x%x\n", |
| 1423 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | return; |
| 1425 | } |
| 1426 | |
| 1427 | pmb->context1 = NULL; |
| 1428 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1434 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1435 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 1436 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 1437 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 1438 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 1439 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 1440 | |
| 1441 | /* Issue SCR just before NameServer GID_FT Query */ |
| 1442 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | } |
| 1444 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1445 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1447 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1449 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | } |
| 1451 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1452 | /* decrement the node reference count held for this |
| 1453 | * callback function. |
| 1454 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1455 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1457 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1458 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1464 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1466 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1467 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | struct lpfc_rport_data *rdata; |
| 1469 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | |
| 1472 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1473 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 1474 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | rport_ids.port_id = ndlp->nlp_DID; |
| 1476 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1478 | /* |
| 1479 | * We leave our node pointer in rport->dd_data when we unregister a |
| 1480 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 1481 | * rport->dd_data points. So, if we're reusing a previously |
| 1482 | * registered port, drop the reference that we took the last time we |
| 1483 | * registered the port. |
| 1484 | */ |
| 1485 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1486 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1487 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1488 | |
| 1489 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 1490 | "rport add: did:x%x flg:x%x type x%x", |
| 1491 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 1492 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1493 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1494 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 1496 | "Warning: fc_remote_port_add failed\n"); |
| 1497 | return; |
| 1498 | } |
| 1499 | |
| 1500 | /* initialize static port data */ |
| 1501 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 1502 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1503 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1504 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 1505 | |
| 1506 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 1507 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 1508 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 1509 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1510 | |
| 1511 | |
| 1512 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 1513 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 1514 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 1515 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1516 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 1517 | ndlp->nlp_sid = rport->scsi_target_id; |
| 1518 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1523 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1524 | { |
| 1525 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1526 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1527 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 1528 | "rport delete: did:x%x flg:x%x type x%x", |
| 1529 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 1530 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1531 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1532 | |
| 1533 | return; |
| 1534 | } |
| 1535 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1536 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1540 | |
| 1541 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1542 | switch (state) { |
| 1543 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1545 | break; |
| 1546 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1547 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1548 | break; |
| 1549 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1551 | break; |
| 1552 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1554 | break; |
| 1555 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1557 | break; |
| 1558 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1560 | break; |
| 1561 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1562 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1563 | break; |
| 1564 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1565 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1566 | break; |
| 1567 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1569 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 1570 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1571 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1573 | int old_state, int new_state) |
| 1574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1575 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1576 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1577 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
| 1578 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 1579 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 1580 | ndlp->nlp_type |= NLP_FC_NODE; |
| 1581 | } |
| 1582 | if (new_state == NLP_STE_MAPPED_NODE) |
| 1583 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 1584 | if (new_state == NLP_STE_NPR_NODE) |
| 1585 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1587 | /* Transport interface */ |
| 1588 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 1589 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1590 | vport->phba->nport_event_cnt++; |
| 1591 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1594 | if (new_state == NLP_STE_MAPPED_NODE || |
| 1595 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1596 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1597 | /* |
| 1598 | * Tell the fc transport about the port, if we haven't |
| 1599 | * already. If we have, and it's a scsi entity, be |
| 1600 | * sure to unblock any attached scsi devices |
| 1601 | */ |
| 1602 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1603 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1604 | /* |
| 1605 | * if we added to Mapped list, but the remote port |
| 1606 | * registration failed or assigned a target id outside |
| 1607 | * our presentable range - move the node to the |
| 1608 | * Unmapped List |
| 1609 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1610 | if (new_state == NLP_STE_MAPPED_NODE && |
| 1611 | (!ndlp->rport || |
| 1612 | ndlp->rport->scsi_target_id == -1 || |
| 1613 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1614 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1615 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1616 | spin_unlock_irq(shost->host_lock); |
| 1617 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1619 | } |
| 1620 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1621 | static char * |
| 1622 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 1623 | { |
| 1624 | static char *states[] = { |
| 1625 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 1626 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 1627 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 1628 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 1629 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 1630 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 1631 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 1632 | [NLP_STE_NPR_NODE] = "NPR", |
| 1633 | }; |
| 1634 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1635 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1636 | strlcpy(buffer, states[state], size); |
| 1637 | else |
| 1638 | snprintf(buffer, size, "unknown (%d)", state); |
| 1639 | return buffer; |
| 1640 | } |
| 1641 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1642 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1643 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 1644 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1645 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1647 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1648 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1649 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1650 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 1651 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 1652 | ndlp->nlp_DID, |
| 1653 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 1654 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1655 | |
| 1656 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 1657 | "node statechg did:x%x old:%d ste:%d", |
| 1658 | ndlp->nlp_DID, old_state, state); |
| 1659 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1660 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1661 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1662 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1663 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 1664 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 1665 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 1666 | } |
| 1667 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1668 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1669 | spin_lock_irq(shost->host_lock); |
| 1670 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 1671 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1672 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1674 | |
| 1675 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | lpfc_nlp_counters(vport, state, 1); |
| 1677 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1681 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 1682 | { |
| 1683 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1684 | |
| 1685 | if (list_empty(&ndlp->nlp_listp)) { |
| 1686 | spin_lock_irq(shost->host_lock); |
| 1687 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 1688 | spin_unlock_irq(shost->host_lock); |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1694 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1696 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1697 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1698 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1699 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 1700 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1701 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1702 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1703 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1704 | NLP_STE_UNUSED_NODE); |
| 1705 | } |
| 1706 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 1707 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1708 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 1709 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1710 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1711 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 1712 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 1713 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 1714 | NLP_STE_UNUSED_NODE); |
| 1715 | } |
| 1716 | |
| 1717 | struct lpfc_nodelist * |
| 1718 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 1719 | int state) |
| 1720 | { |
| 1721 | struct lpfc_hba *phba = vport->phba; |
| 1722 | uint32_t did; |
| 1723 | unsigned long flags; |
| 1724 | |
| 1725 | if (!ndlp) |
| 1726 | return NULL; |
| 1727 | |
| 1728 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 1729 | /* The ndlp should not be in memory free mode */ |
| 1730 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 1731 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1732 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 1733 | "0277 lpfc_enable_node: ndlp:x%p " |
| 1734 | "usgmap:x%x refcnt:%d\n", |
| 1735 | (void *)ndlp, ndlp->nlp_usg_map, |
| 1736 | atomic_read(&ndlp->kref.refcount)); |
| 1737 | return NULL; |
| 1738 | } |
| 1739 | /* The ndlp should not already be in active mode */ |
| 1740 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 1741 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1742 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 1743 | "0278 lpfc_enable_node: ndlp:x%p " |
| 1744 | "usgmap:x%x refcnt:%d\n", |
| 1745 | (void *)ndlp, ndlp->nlp_usg_map, |
| 1746 | atomic_read(&ndlp->kref.refcount)); |
| 1747 | return NULL; |
| 1748 | } |
| 1749 | |
| 1750 | /* Keep the original DID */ |
| 1751 | did = ndlp->nlp_DID; |
| 1752 | |
| 1753 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 1754 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 1755 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
| 1756 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 1757 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 1758 | init_timer(&ndlp->nlp_delayfunc); |
| 1759 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 1760 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 1761 | ndlp->nlp_DID = did; |
| 1762 | ndlp->vport = vport; |
| 1763 | ndlp->nlp_sid = NLP_NO_SID; |
| 1764 | /* ndlp management re-initialize */ |
| 1765 | kref_init(&ndlp->kref); |
| 1766 | NLP_INT_NODE_ACT(ndlp); |
| 1767 | |
| 1768 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 1769 | |
| 1770 | if (state != NLP_STE_UNUSED_NODE) |
| 1771 | lpfc_nlp_set_state(vport, ndlp, state); |
| 1772 | |
| 1773 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 1774 | "node enable: did:x%x", |
| 1775 | ndlp->nlp_DID, 0, 0); |
| 1776 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1781 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1782 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1783 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1784 | * 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] | 1785 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 1786 | * until ALL other outstanding threads have completed. We check |
| 1787 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1788 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1789 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1790 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1791 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1792 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1793 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | /* |
| 1797 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 1798 | */ |
| 1799 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1800 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1802 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1803 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | uint32_t tmo; |
| 1805 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1806 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1807 | /* For FAN, timeout should be greater then edtov */ |
| 1808 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 1809 | } else { |
| 1810 | /* Normal discovery timeout should be > then ELS/CT timeout |
| 1811 | * FC spec states we need 3 * ratov for CT requests |
| 1812 | */ |
| 1813 | tmo = ((phba->fc_ratov * 3) + 3); |
| 1814 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1816 | |
| 1817 | if (!timer_pending(&vport->fc_disctmo)) { |
| 1818 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1819 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 1820 | tmo, vport->port_state, vport->fc_flag); |
| 1821 | } |
| 1822 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1823 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 1824 | spin_lock_irq(shost->host_lock); |
| 1825 | vport->fc_flag |= FC_DISC_TMO; |
| 1826 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | |
| 1828 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1829 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1830 | "0247 Start Discovery Timer state x%x " |
| 1831 | "Data: x%x x%lx x%x x%x\n", |
| 1832 | vport->port_state, tmo, |
| 1833 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 1834 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | |
| 1836 | return; |
| 1837 | } |
| 1838 | |
| 1839 | /* |
| 1840 | * Cancel rescue timer for Discovery / RSCN handling |
| 1841 | */ |
| 1842 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | unsigned long iflags; |
| 1847 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1848 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1849 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 1850 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 1851 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1852 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1853 | if (vport->fc_flag & FC_DISC_TMO) { |
| 1854 | spin_lock_irqsave(shost->host_lock, iflags); |
| 1855 | vport->fc_flag &= ~FC_DISC_TMO; |
| 1856 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 1857 | del_timer_sync(&vport->fc_disctmo); |
| 1858 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 1859 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 1860 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1864 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1865 | "0248 Cancel Discovery Timer state x%x " |
| 1866 | "Data: x%x x%x x%x\n", |
| 1867 | vport->port_state, vport->fc_flag, |
| 1868 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1869 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | /* |
| 1873 | * Check specified ring for outstanding IOCB on the SLI queue |
| 1874 | * Return true if iocb matches the specified nport |
| 1875 | */ |
| 1876 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 1878 | struct lpfc_sli_ring *pring, |
| 1879 | struct lpfc_iocbq *iocb, |
| 1880 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1882 | struct lpfc_sli *psli = &phba->sli; |
| 1883 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1884 | struct lpfc_vport *vport = ndlp->vport; |
| 1885 | |
| 1886 | if (iocb->vport != vport) |
| 1887 | return 0; |
| 1888 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | if (pring->ringno == LPFC_ELS_RING) { |
| 1890 | switch (icmd->ulpCommand) { |
| 1891 | case CMD_GEN_REQUEST64_CR: |
| 1892 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1893 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 1895 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 1896 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | case CMD_XMIT_ELS_RSP64_CX: |
| 1898 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1899 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1901 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | |
| 1903 | } else if (pring->ringno == psli->fcp_ring) { |
| 1904 | /* Skip match check if waiting to relogin to FCP target */ |
| 1905 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1906 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1907 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | } |
| 1909 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1910 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | } |
| 1912 | } else if (pring->ringno == psli->next_ring) { |
| 1913 | |
| 1914 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1915 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /* |
| 1919 | * Free resources / clean up outstanding I/Os |
| 1920 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 1921 | */ |
| 1922 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1923 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1925 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | struct lpfc_sli *psli; |
| 1927 | struct lpfc_sli_ring *pring; |
| 1928 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1929 | IOCB_t *icmd; |
| 1930 | uint32_t rpi, i; |
| 1931 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | lpfc_fabric_abort_nport(ndlp); |
| 1933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | /* |
| 1935 | * Everything that matches on txcmplq will be returned |
| 1936 | * by firmware with a no rpi error. |
| 1937 | */ |
| 1938 | psli = &phba->sli; |
| 1939 | rpi = ndlp->nlp_rpi; |
| 1940 | if (rpi) { |
| 1941 | /* Now process each ring */ |
| 1942 | for (i = 0; i < psli->num_rings; i++) { |
| 1943 | pring = &psli->ring[i]; |
| 1944 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1946 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1947 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | /* |
| 1949 | * Check to see if iocb matches the nport we are |
| 1950 | * looking for |
| 1951 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1952 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 1953 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | /* It matches, so deque and call compl |
| 1955 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1956 | list_move_tail(&iocb->list, |
| 1957 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | } |
| 1960 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | } |
| 1963 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1964 | |
| 1965 | while (!list_empty(&completions)) { |
| 1966 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1967 | list_del_init(&iocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1968 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | if (!iocb->iocb_cmpl) |
| 1970 | lpfc_sli_release_iocbq(phba, iocb); |
| 1971 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1972 | icmd = &iocb->iocb; |
| 1973 | icmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 1974 | icmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | (iocb->iocb_cmpl)(phba, iocb, iocb); |
| 1976 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1979 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | /* |
| 1983 | * Free rpi associated with LPFC_NODELIST entry. |
| 1984 | * This routine is called from lpfc_freenode(), when we are removing |
| 1985 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 1986 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 1987 | * to the remote NPort. In addition, it is called after we receive |
| 1988 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 1989 | * we are waiting to PLOGI back to the remote NPort. |
| 1990 | */ |
| 1991 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1992 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1994 | struct lpfc_hba *phba = vport->phba; |
| 1995 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | int rc; |
| 1997 | |
| 1998 | if (ndlp->nlp_rpi) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1999 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2000 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2001 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2002 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2004 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2005 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2006 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | lpfc_no_rpi(phba, ndlp); |
| 2009 | ndlp->nlp_rpi = 0; |
| 2010 | return 1; |
| 2011 | } |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2015 | void |
| 2016 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 2017 | { |
| 2018 | struct lpfc_hba *phba = vport->phba; |
| 2019 | LPFC_MBOXQ_t *mbox; |
| 2020 | int rc; |
| 2021 | |
| 2022 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2023 | if (mbox) { |
| 2024 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 2025 | mbox->vport = vport; |
| 2026 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2027 | mbox->context1 = NULL; |
| 2028 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2029 | if (rc == MBX_NOT_FINISHED) { |
| 2030 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2031 | } |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | void |
| 2036 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 2037 | { |
| 2038 | struct lpfc_hba *phba = vport->phba; |
| 2039 | LPFC_MBOXQ_t *mbox; |
| 2040 | int rc; |
| 2041 | |
| 2042 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2043 | if (mbox) { |
| 2044 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 2045 | mbox->vport = vport; |
| 2046 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2047 | mbox->context1 = NULL; |
| 2048 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2049 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2050 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2051 | "1815 Could not issue " |
| 2052 | "unreg_did (default rpis)\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2053 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | /* |
| 2059 | * Free resources associated with LPFC_NODELIST entry |
| 2060 | * so it can be freed. |
| 2061 | */ |
| 2062 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2063 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2066 | struct lpfc_hba *phba = vport->phba; |
| 2067 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | |
| 2070 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2071 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2072 | "0900 Cleanup node for NPort x%x " |
| 2073 | "Data: x%x x%x x%x\n", |
| 2074 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 2075 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2076 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2077 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2078 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 2079 | "usgmap:x%x refcnt:%d\n", |
| 2080 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2081 | atomic_read(&ndlp->kref.refcount)); |
| 2082 | lpfc_dequeue_node(vport, ndlp); |
| 2083 | } else { |
| 2084 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2085 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 2086 | "usgmap:x%x refcnt:%d\n", |
| 2087 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2088 | atomic_read(&ndlp->kref.refcount)); |
| 2089 | lpfc_disable_node(vport, ndlp); |
| 2090 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 2093 | if ((mb = phba->sli.mbox_active)) { |
| 2094 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && |
| 2095 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 2096 | mb->context2 = NULL; |
| 2097 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2098 | } |
| 2099 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2100 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2101 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 2103 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2104 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 2106 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | kfree(mp); |
| 2109 | } |
| 2110 | list_del(&mb->list); |
| 2111 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2112 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 2113 | * the ndlp reference count as we are in the process |
| 2114 | * of lpfc_nlp_release. |
| 2115 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | } |
| 2117 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2120 | lpfc_els_abort(phba, ndlp); |
| 2121 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2123 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2124 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2126 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 2128 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2129 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 2130 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2134 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | /* |
| 2138 | * Check to see if we can free the nlp back to the freelist. |
| 2139 | * If we are in the middle of using the nlp in the discovery state |
| 2140 | * machine, defer the free till we reach the end of the state machine. |
| 2141 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2142 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2145 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2146 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2147 | LPFC_MBOXQ_t *mbox; |
| 2148 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2150 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2151 | if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) { |
| 2152 | /* For this case we need to cleanup the default rpi |
| 2153 | * allocated by the firmware. |
| 2154 | */ |
| 2155 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 2156 | != NULL) { |
| 2157 | rc = lpfc_reg_login(phba, vport->vpi, ndlp->nlp_DID, |
| 2158 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 2159 | if (rc) { |
| 2160 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2161 | } |
| 2162 | else { |
| 2163 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 2164 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 2165 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2166 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2167 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 2168 | if (rc == MBX_NOT_FINISHED) { |
| 2169 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2175 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2177 | * We can get here with a non-NULL ndlp->rport because when we |
| 2178 | * unregister a rport we don't break the rport/node linkage. So if we |
| 2179 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2181 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2182 | rdata = ndlp->rport->dd_data; |
| 2183 | rdata->pnode = NULL; |
| 2184 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2189 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2190 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2192 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | |
| 2194 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2195 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | /* First check for Direct match */ |
| 2198 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2199 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | |
| 2201 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2202 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2204 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | matchdid.un.word = did; |
| 2208 | ndlpdid.un.word = ndlp->nlp_DID; |
| 2209 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 2210 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 2211 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 2212 | if ((ndlpdid.un.b.domain == 0) && |
| 2213 | (ndlpdid.un.b.area == 0)) { |
| 2214 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2215 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2217 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | matchdid.un.word = ndlp->nlp_DID; |
| 2221 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 2222 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 2223 | if ((matchdid.un.b.domain == 0) && |
| 2224 | (matchdid.un.b.area == 0)) { |
| 2225 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2226 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2230 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } |
| 2232 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2233 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | static struct lpfc_nodelist * |
| 2235 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 2237 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | uint32_t data1; |
| 2239 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2240 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 2241 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2242 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 2243 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 2244 | ((uint32_t) ndlp->nlp_type << 8) | |
| 2245 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2246 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2247 | "0929 FIND node DID " |
| 2248 | "Data: x%p x%x x%x x%x\n", |
| 2249 | ndlp, ndlp->nlp_DID, |
| 2250 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2251 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | } |
| 2253 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 2254 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2255 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2256 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2257 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | return NULL; |
| 2259 | } |
| 2260 | |
| 2261 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2262 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2263 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | spin_lock_irq(shost->host_lock); |
| 2268 | ndlp = __lpfc_findnode_did(vport, did); |
| 2269 | spin_unlock_irq(shost->host_lock); |
| 2270 | return ndlp; |
| 2271 | } |
| 2272 | |
| 2273 | struct lpfc_nodelist * |
| 2274 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 2275 | { |
| 2276 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2277 | struct lpfc_nodelist *ndlp; |
| 2278 | |
| 2279 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2280 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2281 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 2282 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | return NULL; |
| 2284 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2285 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | if (!ndlp) |
| 2287 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2288 | lpfc_nlp_init(vport, ndlp, did); |
| 2289 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2290 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2292 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2294 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2295 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 2296 | if (!ndlp) |
| 2297 | return NULL; |
| 2298 | spin_lock_irq(shost->host_lock); |
| 2299 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 2300 | spin_unlock_irq(shost->host_lock); |
| 2301 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2303 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2304 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 2305 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2307 | /* If we've already recieved a PLOGI from this NPort |
| 2308 | * we don't need to try to discover it again. |
| 2309 | */ |
| 2310 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 2311 | return NULL; |
| 2312 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2313 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2315 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2316 | |
| 2317 | /* Since this node is marked for discovery, |
| 2318 | * delay timeout is not needed. |
| 2319 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2320 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 2321 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2323 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2324 | /* If we've already recieved a PLOGI from this NPort, |
| 2325 | * or we are already in the process of discovery on it, |
| 2326 | * we don't need to try to discover it again. |
| 2327 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2328 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2329 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 2330 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2332 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2333 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2335 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | } |
| 2337 | return ndlp; |
| 2338 | } |
| 2339 | |
| 2340 | /* Build a list of nodes to discover based on the loopmap */ |
| 2341 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | int j; |
| 2346 | uint32_t alpa, index; |
| 2347 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2348 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2350 | |
| 2351 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | |
| 2354 | /* Check for loop map present or not */ |
| 2355 | if (phba->alpa_map[0]) { |
| 2356 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 2357 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2358 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | } |
| 2362 | } else { |
| 2363 | /* No alpamap, so try all alpa's */ |
| 2364 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 2365 | /* If cfg_scan_down is set, start from highest |
| 2366 | * ALPA (0xef) to lowest (0x1). |
| 2367 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2368 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | index = j; |
| 2370 | else |
| 2371 | index = FC_MAXLOOP - j - 1; |
| 2372 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2375 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | return; |
| 2379 | } |
| 2380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2385 | struct lpfc_sli *psli = &phba->sli; |
| 2386 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 2387 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 2388 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 2389 | int rc; |
| 2390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2391 | /* |
| 2392 | * if it's not a physical port or if we already send |
| 2393 | * clear_la then don't send it. |
| 2394 | */ |
| 2395 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
| 2396 | (vport->port_type != LPFC_PHYSICAL_PORT)) |
| 2397 | return; |
| 2398 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2399 | /* Link up discovery */ |
| 2400 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 2401 | phba->link_state = LPFC_CLEAR_LA; |
| 2402 | lpfc_clear_la(phba, mbox); |
| 2403 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 2404 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2405 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | if (rc == MBX_NOT_FINISHED) { |
| 2407 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2408 | lpfc_disc_flush_list(vport); |
| 2409 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 2410 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 2411 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2412 | phba->link_state = LPFC_HBA_ERROR; |
| 2413 | } |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 2418 | void |
| 2419 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 2420 | { |
| 2421 | LPFC_MBOXQ_t *regvpimbox; |
| 2422 | |
| 2423 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2424 | if (regvpimbox) { |
| 2425 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox); |
| 2426 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 2427 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2428 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | == MBX_NOT_FINISHED) { |
| 2430 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 2436 | void |
| 2437 | lpfc_disc_start(struct lpfc_vport *vport) |
| 2438 | { |
| 2439 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2440 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2441 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2443 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | |
| 2448 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | clear_la_pending = 1; |
| 2450 | else |
| 2451 | clear_la_pending = 0; |
| 2452 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2453 | if (vport->port_state < LPFC_VPORT_READY) |
| 2454 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | lpfc_set_disctmo(vport); |
| 2457 | |
| 2458 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2462 | |
| 2463 | vport->fc_prevDID = vport->fc_myDID; |
| 2464 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | |
| 2466 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2467 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2468 | "0202 Start Discovery hba state x%x " |
| 2469 | "Data: x%x x%x x%x\n", |
| 2470 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 2471 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | |
| 2473 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2474 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | |
| 2476 | if (num_sent) |
| 2477 | return; |
| 2478 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2479 | /* |
| 2480 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 2481 | * continue discovery. |
| 2482 | */ |
| 2483 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2484 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2485 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 2486 | lpfc_issue_reg_vpi(phba, vport); |
| 2487 | return; |
| 2488 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2490 | /* |
| 2491 | * For SLI2, we need to set port_state to READY and continue |
| 2492 | * discovery. |
| 2493 | */ |
| 2494 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 2495 | /* If we get here, there is nothing to ADISC */ |
| 2496 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 2497 | lpfc_issue_clear_la(phba, vport); |
| 2498 | |
| 2499 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | vport->num_disc_nodes = 0; |
| 2501 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2502 | if (vport->fc_npr_cnt) |
| 2503 | lpfc_els_disc_plogi(vport); |
| 2504 | |
| 2505 | if (!vport->num_disc_nodes) { |
| 2506 | spin_lock_irq(shost->host_lock); |
| 2507 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2508 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2509 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | } |
| 2511 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | } else { |
| 2514 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2515 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | |
| 2517 | if (num_sent) |
| 2518 | return; |
| 2519 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2520 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | /* Check to see if more RSCNs came in while we |
| 2522 | * were processing this one. |
| 2523 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2524 | if ((vport->fc_rscn_id_cnt == 0) && |
| 2525 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 2526 | spin_lock_irq(shost->host_lock); |
| 2527 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 2528 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2529 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2530 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2531 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | return; |
| 2535 | } |
| 2536 | |
| 2537 | /* |
| 2538 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 2539 | * ring the match the sppecified nodelist. |
| 2540 | */ |
| 2541 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2542 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2544 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | struct lpfc_sli *psli; |
| 2546 | IOCB_t *icmd; |
| 2547 | struct lpfc_iocbq *iocb, *next_iocb; |
| 2548 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2549 | |
| 2550 | psli = &phba->sli; |
| 2551 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2552 | |
| 2553 | /* Error matching iocb on txq or txcmplq |
| 2554 | * First check the txq. |
| 2555 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2556 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2557 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 2558 | if (iocb->context1 != ndlp) { |
| 2559 | continue; |
| 2560 | } |
| 2561 | icmd = &iocb->iocb; |
| 2562 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 2563 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 2564 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2565 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | /* Next check the txcmplq */ |
| 2571 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 2572 | if (iocb->context1 != ndlp) { |
| 2573 | continue; |
| 2574 | } |
| 2575 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2576 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 2577 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2578 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | } |
| 2580 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2581 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2582 | |
| 2583 | while (!list_empty(&completions)) { |
| 2584 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | list_del_init(&iocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | if (!iocb->iocb_cmpl) |
| 2588 | lpfc_sli_release_iocbq(phba, iocb); |
| 2589 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2590 | icmd = &iocb->iocb; |
| 2591 | icmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2592 | icmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 2593 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2594 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2595 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | } |
| 2597 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2598 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2599 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | { |
| 2601 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2602 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 2605 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2606 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2607 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2608 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2609 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 2610 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 2611 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | } |
| 2614 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | } |
| 2616 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2617 | void |
| 2618 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 2619 | { |
| 2620 | lpfc_els_flush_rscn(vport); |
| 2621 | lpfc_els_flush_cmd(vport); |
| 2622 | lpfc_disc_flush_list(vport); |
| 2623 | } |
| 2624 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | /*****************************************************************************/ |
| 2626 | /* |
| 2627 | * NAME: lpfc_disc_timeout |
| 2628 | * |
| 2629 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 2630 | * |
| 2631 | * EXECUTION ENVIRONMENT: interrupt only |
| 2632 | * |
| 2633 | * CALLED FROM: |
| 2634 | * Timer function |
| 2635 | * |
| 2636 | * RETURNS: |
| 2637 | * none |
| 2638 | */ |
| 2639 | /*****************************************************************************/ |
| 2640 | void |
| 2641 | lpfc_disc_timeout(unsigned long ptr) |
| 2642 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2643 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 2644 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2645 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | unsigned long flags = 0; |
| 2647 | |
| 2648 | if (unlikely(!phba)) |
| 2649 | return; |
| 2650 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2651 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 2652 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 2653 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2654 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2655 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2657 | if (!tmo_posted) |
| 2658 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | return; |
| 2660 | } |
| 2661 | |
| 2662 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2666 | struct lpfc_hba *phba = vport->phba; |
| 2667 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2668 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2669 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | int rc, clrlaerr = 0; |
| 2671 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2672 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | return; |
| 2674 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2675 | spin_lock_irq(shost->host_lock); |
| 2676 | vport->fc_flag &= ~FC_DISC_TMO; |
| 2677 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2679 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2680 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 2681 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 2682 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2683 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | |
| 2685 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 2687 | * FAN |
| 2688 | */ |
| 2689 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2690 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 2691 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2692 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2693 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2694 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2695 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2696 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2697 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 2698 | continue; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2699 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2700 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2701 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2702 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2703 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2704 | /* Fail outstanding IO now since device |
| 2705 | * is marked for PLOGI. |
| 2706 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2708 | } |
| 2709 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2710 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2711 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2712 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2713 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | break; |
| 2715 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2716 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2718 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2720 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2721 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2722 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | |
| 2724 | /* Assume no Fabric and go on with discovery. |
| 2725 | * Check for outstanding ELS FLOGI to abort. |
| 2726 | */ |
| 2727 | |
| 2728 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | |
| 2731 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | break; |
| 2734 | |
| 2735 | case LPFC_FABRIC_CFG_LINK: |
| 2736 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 2737 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2738 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2739 | "0223 Timeout while waiting for " |
| 2740 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2743 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2744 | lpfc_els_abort(phba, ndlp); |
| 2745 | |
| 2746 | /* ReStart discovery */ |
| 2747 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | |
| 2749 | case LPFC_NS_QRY: |
| 2750 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2752 | "0224 NameServer Query timeout " |
| 2753 | "Data: x%x x%x\n", |
| 2754 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2756 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 2757 | /* Try it one more time */ |
| 2758 | vport->fc_ns_retry++; |
| 2759 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 2760 | vport->fc_ns_retry, 0); |
| 2761 | if (rc == 0) |
| 2762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2764 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2766 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2767 | /* |
| 2768 | * Discovery is over. |
| 2769 | * set port_state to PORT_READY if SLI2. |
| 2770 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 2771 | */ |
| 2772 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2773 | lpfc_issue_reg_vpi(phba, vport); |
| 2774 | else { /* NPIV Not enabled */ |
| 2775 | lpfc_issue_clear_la(phba, vport); |
| 2776 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 2780 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2781 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2782 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2783 | "0206 Device Discovery " |
| 2784 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2785 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | break; |
| 2787 | } |
| 2788 | |
| 2789 | lpfc_linkdown(phba); |
| 2790 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 2791 | phba->cfg_link_speed); |
| 2792 | initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2793 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2794 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2795 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2796 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2797 | if (rc == MBX_NOT_FINISHED) |
| 2798 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 2799 | |
| 2800 | break; |
| 2801 | |
| 2802 | case LPFC_DISC_AUTH: |
| 2803 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2804 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2805 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 | lpfc_disc_flush_list(vport); |
| 2807 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2808 | /* |
| 2809 | * set port_state to PORT_READY if SLI2. |
| 2810 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 2811 | */ |
| 2812 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2813 | lpfc_issue_reg_vpi(phba, vport); |
| 2814 | else { /* NPIV Not enabled */ |
| 2815 | lpfc_issue_clear_la(phba, vport); |
| 2816 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | } |
| 2818 | break; |
| 2819 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2820 | case LPFC_VPORT_READY: |
| 2821 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2822 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2823 | "0231 RSCN timeout Data: x%x " |
| 2824 | "x%x\n", |
| 2825 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | |
| 2827 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2828 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2830 | lpfc_els_flush_rscn(vport); |
| 2831 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | } |
| 2833 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2834 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2835 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2836 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2837 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2838 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2839 | break; |
| 2840 | } |
| 2841 | |
| 2842 | switch (phba->link_state) { |
| 2843 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2844 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2845 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2846 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2847 | clrlaerr = 1; |
| 2848 | break; |
| 2849 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2850 | case LPFC_LINK_UP: |
| 2851 | lpfc_issue_clear_la(phba, vport); |
| 2852 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2853 | case LPFC_LINK_UNKNOWN: |
| 2854 | case LPFC_WARM_START: |
| 2855 | case LPFC_INIT_START: |
| 2856 | case LPFC_INIT_MBX_CMDS: |
| 2857 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2859 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2860 | "0230 Unexpected timeout, hba link " |
| 2861 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2862 | clrlaerr = 1; |
| 2863 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2864 | |
| 2865 | case LPFC_HBA_READY: |
| 2866 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2870 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2871 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 2873 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2874 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | return; |
| 2878 | } |
| 2879 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | /* |
| 2881 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 2882 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2883 | * as the completion routine when the command is |
| 2884 | * handed off to the SLI layer. |
| 2885 | */ |
| 2886 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2887 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2889 | MAILBOX_t *mb = &pmb->mb; |
| 2890 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2891 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2892 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | |
| 2894 | pmb->context1 = NULL; |
| 2895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | ndlp->nlp_rpi = mb->un.varWords[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2897 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | /* |
| 2901 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 2902 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 2903 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2905 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2906 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2907 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 2908 | else |
| 2909 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2911 | /* decrement the node reference count held for this callback |
| 2912 | * function. |
| 2913 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2914 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2915 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2916 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2917 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | |
| 2919 | return; |
| 2920 | } |
| 2921 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2922 | static int |
| 2923 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 2924 | { |
| 2925 | uint16_t *rpi = param; |
| 2926 | |
| 2927 | return ndlp->nlp_rpi == *rpi; |
| 2928 | } |
| 2929 | |
| 2930 | static int |
| 2931 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 2932 | { |
| 2933 | return memcmp(&ndlp->nlp_portname, param, |
| 2934 | sizeof(ndlp->nlp_portname)) == 0; |
| 2935 | } |
| 2936 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2937 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2938 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2939 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 2940 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2942 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2943 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2944 | return ndlp; |
| 2945 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 2946 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | } |
| 2948 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2949 | /* |
| 2950 | * 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] | 2951 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2952 | */ |
| 2953 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2954 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2955 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2956 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2957 | } |
| 2958 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2959 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2960 | * 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] | 2961 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2962 | */ |
| 2963 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2964 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2965 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2966 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2967 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2968 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | spin_lock_irq(shost->host_lock); |
| 2970 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 2971 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2972 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2973 | } |
| 2974 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2977 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | { |
| 2979 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2981 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | init_timer(&ndlp->nlp_delayfunc); |
| 2983 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 2984 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 2985 | ndlp->nlp_DID = did; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2986 | ndlp->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2987 | ndlp->nlp_sid = NLP_NO_SID; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2988 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2989 | kref_init(&ndlp->kref); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2990 | NLP_INT_NODE_ACT(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2991 | |
| 2992 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 2993 | "node init: did:x%x", |
| 2994 | ndlp->nlp_DID, 0, 0); |
| 2995 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2996 | return; |
| 2997 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2998 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2999 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 3000 | * and mempool_free's the nodelist. |
| 3001 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 3002 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3003 | lpfc_nlp_release(struct kref *kref) |
| 3004 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3005 | struct lpfc_hba *phba; |
| 3006 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3007 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 3008 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3009 | |
| 3010 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3011 | "node release: did:x%x flg:x%x type:x%x", |
| 3012 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 3013 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3014 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3015 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 3016 | "usgmap:x%x refcnt:%d\n", |
| 3017 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3018 | atomic_read(&ndlp->kref.refcount)); |
| 3019 | |
| 3020 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3021 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3022 | |
| 3023 | /* clear the ndlp active flag for all release cases */ |
| 3024 | phba = ndlp->vport->phba; |
| 3025 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3026 | NLP_CLR_NODE_ACT(ndlp); |
| 3027 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3028 | |
| 3029 | /* free ndlp memory for final ndlp release */ |
| 3030 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 3031 | mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3032 | } |
| 3033 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3034 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 3035 | * that one discovery thread won't free a ndlp while another discovery thread |
| 3036 | * is using it. |
| 3037 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3038 | struct lpfc_nodelist * |
| 3039 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 3040 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3041 | struct lpfc_hba *phba; |
| 3042 | unsigned long flags; |
| 3043 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3044 | if (ndlp) { |
| 3045 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3046 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 3047 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3048 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3049 | /* The check of ndlp usage to prevent incrementing the |
| 3050 | * ndlp reference count that is in the process of being |
| 3051 | * released. |
| 3052 | */ |
| 3053 | phba = ndlp->vport->phba; |
| 3054 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3055 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 3056 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3057 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3058 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 3059 | "usgmap:x%x refcnt:%d\n", |
| 3060 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3061 | atomic_read(&ndlp->kref.refcount)); |
| 3062 | return NULL; |
| 3063 | } else |
| 3064 | kref_get(&ndlp->kref); |
| 3065 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3066 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3067 | return ndlp; |
| 3068 | } |
| 3069 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3070 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3071 | * count goes to 0, this indicates the the associated nodelist should be |
| 3072 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 3073 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 3074 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3075 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3076 | int |
| 3077 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 3078 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3079 | struct lpfc_hba *phba; |
| 3080 | unsigned long flags; |
| 3081 | |
| 3082 | if (!ndlp) |
| 3083 | return 1; |
| 3084 | |
| 3085 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3086 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 3087 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3088 | atomic_read(&ndlp->kref.refcount)); |
| 3089 | phba = ndlp->vport->phba; |
| 3090 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3091 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 3092 | * possible race condition that kref_put got invoked again |
| 3093 | * after previous one has done ndlp memory free. |
| 3094 | */ |
| 3095 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 3096 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3097 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3098 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 3099 | "usgmap:x%x refcnt:%d\n", |
| 3100 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3101 | atomic_read(&ndlp->kref.refcount)); |
| 3102 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3103 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3104 | /* Check the ndlp inactivate log flag to avoid the possible |
| 3105 | * race condition that kref_put got invoked again after ndlp |
| 3106 | * is already in inactivating state. |
| 3107 | */ |
| 3108 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 3109 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3110 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 3111 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 3112 | "usgmap:x%x refcnt:%d\n", |
| 3113 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3114 | atomic_read(&ndlp->kref.refcount)); |
| 3115 | return 1; |
| 3116 | } |
| 3117 | /* For last put, mark the ndlp usage flags to make sure no |
| 3118 | * other kref_get and kref_put on the same ndlp shall get |
| 3119 | * in between the process when the final kref_put has been |
| 3120 | * invoked on this ndlp. |
| 3121 | */ |
| 3122 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 3123 | /* Indicate ndlp is put to inactive state. */ |
| 3124 | NLP_SET_IACT_REQ(ndlp); |
| 3125 | /* Acknowledge ndlp memory free has been seen. */ |
| 3126 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 3127 | NLP_SET_FREE_ACK(ndlp); |
| 3128 | } |
| 3129 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3130 | /* Note, the kref_put returns 1 when decrementing a reference |
| 3131 | * count that was 1, it invokes the release callback function, |
| 3132 | * but it still left the reference count as 1 (not actually |
| 3133 | * performs the last decrementation). Otherwise, it actually |
| 3134 | * decrements the reference count and returns 0. |
| 3135 | */ |
| 3136 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3137 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3138 | |
| 3139 | /* 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] | 3140 | * by any other discovery thread. This routine returns 1 if the |
| 3141 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 3142 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3143 | */ |
| 3144 | int |
| 3145 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 3146 | { |
| 3147 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 3148 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 3149 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3150 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3151 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 3152 | if (lpfc_nlp_put(ndlp)) |
| 3153 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3154 | return 0; |
| 3155 | } |