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