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