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