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