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