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