| 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 | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 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 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 34 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include "lpfc_disc.h" |
| 36 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include "lpfc_sli4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | |
| 45 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ |
| 46 | static uint8_t lpfcAlpaArray[] = { |
| 47 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, |
| 48 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, |
| 49 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, |
| 50 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, |
| 51 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, |
| 52 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, |
| 53 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, |
| 54 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, |
| 55 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, |
| 56 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, |
| 57 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, |
| 58 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, |
| 59 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 |
| 60 | }; |
| 61 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 62 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 63 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 64 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 66 | void |
| 67 | lpfc_terminate_rport_io(struct fc_rport *rport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 69 | struct lpfc_rport_data *rdata; |
| 70 | struct lpfc_nodelist * ndlp; |
| 71 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 72 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 73 | rdata = rport->dd_data; |
| 74 | ndlp = rdata->pnode; |
| 75 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 76 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 77 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
| 78 | printk(KERN_ERR "Cannot find remote node" |
| 79 | " to terminate I/O Data x%x\n", |
| 80 | rport->port_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 84 | phba = ndlp->phba; |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 85 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 86 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 87 | "rport terminate: sid:x%x did:x%x flg:x%x", |
| 88 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 89 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 90 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 91 | lpfc_sli_abort_iocb(ndlp->vport, |
| 92 | &phba->sli.ring[phba->sli.fcp_ring], |
| 93 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 94 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * This function will be called when dev_loss_tmo fire. |
| 99 | */ |
| 100 | void |
| 101 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) |
| 102 | { |
| 103 | struct lpfc_rport_data *rdata; |
| 104 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 105 | struct lpfc_vport *vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 106 | struct lpfc_hba *phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 107 | struct lpfc_work_evt *evtp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 108 | int put_node; |
| 109 | int put_rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 110 | |
| 111 | rdata = rport->dd_data; |
| 112 | ndlp = rdata->pnode; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 113 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 114 | return; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 115 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 116 | vport = ndlp->vport; |
| 117 | phba = vport->phba; |
| 118 | |
| 119 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 120 | "rport devlosscb: sid:x%x did:x%x flg:x%x", |
| 121 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); |
| 122 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 123 | /* Don't defer this if we are in the process of deleting the vport |
| 124 | * or unloading the driver. The unload will cleanup the node |
| 125 | * appropriately we just need to cleanup the ndlp rport info here. |
| 126 | */ |
| 127 | if (vport->load_flag & FC_UNLOADING) { |
| 128 | put_node = rdata->pnode != NULL; |
| 129 | put_rport = ndlp->rport != NULL; |
| 130 | rdata->pnode = NULL; |
| 131 | ndlp->rport = NULL; |
| 132 | if (put_node) |
| 133 | lpfc_nlp_put(ndlp); |
| 134 | if (put_rport) |
| 135 | put_device(&rport->dev); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) |
| 140 | return; |
| 141 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 142 | evtp = &ndlp->dev_loss_evt; |
| 143 | |
| 144 | if (!list_empty(&evtp->evt_listp)) |
| 145 | return; |
| 146 | |
| 147 | spin_lock_irq(&phba->hbalock); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 148 | /* We need to hold the node by incrementing the reference |
| 149 | * count until this queued work is done |
| 150 | */ |
| 151 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 152 | if (evtp->evt_arg1) { |
| 153 | evtp->evt = LPFC_EVT_DEV_LOSS; |
| 154 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 155 | lpfc_worker_wake_up(phba); |
| 156 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 157 | spin_unlock_irq(&phba->hbalock); |
| 158 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * This function is called from the worker thread when dev_loss_tmo |
| 164 | * expire. |
| 165 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 166 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 167 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
| 168 | { |
| 169 | struct lpfc_rport_data *rdata; |
| 170 | struct fc_rport *rport; |
| 171 | struct lpfc_vport *vport; |
| 172 | struct lpfc_hba *phba; |
| 173 | uint8_t *name; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 174 | int put_node; |
| 175 | int put_rport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 176 | int warn_on = 0; |
| 177 | |
| 178 | rport = ndlp->rport; |
| 179 | |
| 180 | if (!rport) |
| 181 | return; |
| 182 | |
| 183 | rdata = rport->dd_data; |
| 184 | name = (uint8_t *) &ndlp->nlp_portname; |
| 185 | vport = ndlp->vport; |
| 186 | phba = vport->phba; |
| 187 | |
| 188 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 189 | "rport devlosstmo:did:x%x type:x%x id:x%x", |
| 190 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); |
| 191 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 192 | /* Don't defer this if we are in the process of deleting the vport |
| 193 | * or unloading the driver. The unload will cleanup the node |
| 194 | * appropriately we just need to cleanup the ndlp rport info here. |
| 195 | */ |
| 196 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 197 | if (ndlp->nlp_sid != NLP_NO_SID) { |
| 198 | /* flush the target */ |
| 199 | lpfc_sli_abort_iocb(vport, |
| 200 | &phba->sli.ring[phba->sli.fcp_ring], |
| 201 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| 202 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 203 | put_node = rdata->pnode != NULL; |
| 204 | put_rport = ndlp->rport != NULL; |
| 205 | rdata->pnode = NULL; |
| 206 | ndlp->rport = NULL; |
| 207 | if (put_node) |
| 208 | lpfc_nlp_put(ndlp); |
| 209 | if (put_rport) |
| 210 | put_device(&rport->dev); |
| 211 | return; |
| 212 | } |
| 213 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 214 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 215 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 216 | "0284 Devloss timeout Ignored on " |
| 217 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
| 218 | "NPort x%x\n", |
| 219 | *name, *(name+1), *(name+2), *(name+3), |
| 220 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 221 | ndlp->nlp_DID); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 222 | return; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 223 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 225 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 226 | /* We will clean up these Nodes in linkup */ |
| 227 | put_node = rdata->pnode != NULL; |
| 228 | put_rport = ndlp->rport != NULL; |
| 229 | rdata->pnode = NULL; |
| 230 | ndlp->rport = NULL; |
| 231 | if (put_node) |
| 232 | lpfc_nlp_put(ndlp); |
| 233 | if (put_rport) |
| 234 | put_device(&rport->dev); |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 235 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 236 | } |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | if (ndlp->nlp_sid != NLP_NO_SID) { |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 239 | warn_on = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | /* flush the target */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 241 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 242 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 244 | |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 245 | if (warn_on) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 246 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 247 | "0203 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 248 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 249 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 250 | *name, *(name+1), *(name+2), *(name+3), |
| 251 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 252 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 253 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 254 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 255 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 256 | "0204 Devloss timeout on " |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 257 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
| 258 | "NPort x%06x Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 259 | *name, *(name+1), *(name+2), *(name+3), |
| 260 | *(name+4), *(name+5), *(name+6), *(name+7), |
| 261 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 262 | ndlp->nlp_state, ndlp->nlp_rpi); |
James.Smart@Emulex.Com | 6e8215e | 2005-06-25 10:34:04 -0400 | [diff] [blame] | 263 | } |
| 264 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 265 | put_node = rdata->pnode != NULL; |
| 266 | put_rport = ndlp->rport != NULL; |
| 267 | rdata->pnode = NULL; |
| 268 | ndlp->rport = NULL; |
| 269 | if (put_node) |
| 270 | lpfc_nlp_put(ndlp); |
| 271 | if (put_rport) |
| 272 | put_device(&rport->dev); |
| 273 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 274 | if (!(vport->load_flag & FC_UNLOADING) && |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 275 | !(ndlp->nlp_flag & NLP_DELAY_TMO) && |
James Smart | 8208571 | 2007-04-25 09:52:41 -0400 | [diff] [blame] | 276 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 277 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 278 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 279 | |
| 280 | lpfc_unregister_unused_fcf(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 281 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 282 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 283 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 284 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 285 | * @phba: Pointer to hba context object. |
| 286 | * |
| 287 | * This function is called from the functions which need to post |
| 288 | * events from interrupt context. This function allocates data |
| 289 | * structure required for posting event. It also keeps track of |
| 290 | * number of events pending and prevent event storm when there are |
| 291 | * too many events. |
| 292 | **/ |
| 293 | struct lpfc_fast_path_event * |
| 294 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { |
| 295 | struct lpfc_fast_path_event *ret; |
| 296 | |
| 297 | /* If there are lot of fast event do not exhaust memory due to this */ |
| 298 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) |
| 299 | return NULL; |
| 300 | |
| 301 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), |
| 302 | GFP_ATOMIC); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 303 | if (ret) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 304 | atomic_inc(&phba->fast_event_count); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 305 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
| 306 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 307 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 312 | * lpfc_free_fast_evt - Frees event data structure |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 313 | * @phba: Pointer to hba context object. |
| 314 | * @evt: Event object which need to be freed. |
| 315 | * |
| 316 | * This function frees the data structure required for posting |
| 317 | * events. |
| 318 | **/ |
| 319 | void |
| 320 | lpfc_free_fast_evt(struct lpfc_hba *phba, |
| 321 | struct lpfc_fast_path_event *evt) { |
| 322 | |
| 323 | atomic_dec(&phba->fast_event_count); |
| 324 | kfree(evt); |
| 325 | } |
| 326 | |
| 327 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 328 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 329 | * @phba: Pointer to hba context object. |
| 330 | * @evtp: Event data structure. |
| 331 | * |
| 332 | * This function is called from worker thread, when the interrupt |
| 333 | * context need to post an event. This function posts the event |
| 334 | * to fc transport netlink interface. |
| 335 | **/ |
| 336 | static void |
| 337 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, |
| 338 | struct lpfc_work_evt *evtp) |
| 339 | { |
| 340 | unsigned long evt_category, evt_sub_category; |
| 341 | struct lpfc_fast_path_event *fast_evt_data; |
| 342 | char *evt_data; |
| 343 | uint32_t evt_data_size; |
| 344 | struct Scsi_Host *shost; |
| 345 | |
| 346 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, |
| 347 | work_evt); |
| 348 | |
| 349 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; |
| 350 | evt_sub_category = (unsigned long) fast_evt_data->un. |
| 351 | fabric_evt.subcategory; |
| 352 | shost = lpfc_shost_from_vport(fast_evt_data->vport); |
| 353 | if (evt_category == FC_REG_FABRIC_EVENT) { |
| 354 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { |
| 355 | evt_data = (char *) &fast_evt_data->un.read_check_error; |
| 356 | evt_data_size = sizeof(fast_evt_data->un. |
| 357 | read_check_error); |
| 358 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 359 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 360 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
| 361 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); |
| 362 | } else { |
| 363 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 364 | return; |
| 365 | } |
| 366 | } else if (evt_category == FC_REG_SCSI_EVENT) { |
| 367 | switch (evt_sub_category) { |
| 368 | case LPFC_EVENT_QFULL: |
| 369 | case LPFC_EVENT_DEVBSY: |
| 370 | evt_data = (char *) &fast_evt_data->un.scsi_evt; |
| 371 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); |
| 372 | break; |
| 373 | case LPFC_EVENT_CHECK_COND: |
| 374 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; |
| 375 | evt_data_size = sizeof(fast_evt_data->un. |
| 376 | check_cond_evt); |
| 377 | break; |
| 378 | case LPFC_EVENT_VARQUEDEPTH: |
| 379 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; |
| 380 | evt_data_size = sizeof(fast_evt_data->un. |
| 381 | queue_depth_evt); |
| 382 | break; |
| 383 | default: |
| 384 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 385 | return; |
| 386 | } |
| 387 | } else { |
| 388 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | fc_host_post_vendor_event(shost, |
| 393 | fc_get_event_number(), |
| 394 | evt_data_size, |
| 395 | evt_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 396 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 397 | |
| 398 | lpfc_free_fast_evt(phba, fast_evt_data); |
| 399 | return; |
| 400 | } |
| 401 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 402 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 403 | lpfc_work_list_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | { |
| 405 | struct lpfc_work_evt *evtp = NULL; |
| 406 | struct lpfc_nodelist *ndlp; |
| 407 | int free_evt; |
| 408 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | spin_lock_irq(&phba->hbalock); |
| 410 | while (!list_empty(&phba->work_list)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
| 412 | evt_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | free_evt = 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 415 | switch (evtp->evt) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | case LPFC_EVT_ELS_RETRY: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 418 | lpfc_els_retry_delay_handler(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 419 | free_evt = 0; /* evt is part of ndlp */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 420 | /* decrement the node reference count held |
| 421 | * for this queued work |
| 422 | */ |
| 423 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 425 | case LPFC_EVT_DEV_LOSS: |
| 426 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 427 | lpfc_dev_loss_tmo_handler(ndlp); |
| 428 | free_evt = 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 429 | /* decrement the node reference count held for |
| 430 | * this queued work |
| 431 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 432 | lpfc_nlp_put(ndlp); |
| 433 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | case LPFC_EVT_ONLINE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 435 | if (phba->link_state < LPFC_LINK_DOWN) |
| 436 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 437 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | *(int *) (evtp->evt_arg1) = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | complete((struct completion *)(evtp->evt_arg2)); |
| 440 | break; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 441 | case LPFC_EVT_OFFLINE_PREP: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 442 | if (phba->link_state >= LPFC_LINK_DOWN) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 443 | lpfc_offline_prep(phba); |
| 444 | *(int *)(evtp->evt_arg1) = 0; |
| 445 | complete((struct completion *)(evtp->evt_arg2)); |
| 446 | break; |
| 447 | case LPFC_EVT_OFFLINE: |
| 448 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 449 | lpfc_sli_brdrestart(phba); |
| 450 | *(int *)(evtp->evt_arg1) = |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 451 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
| 452 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 453 | complete((struct completion *)(evtp->evt_arg2)); |
| 454 | break; |
| 455 | case LPFC_EVT_WARM_START: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 456 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 457 | lpfc_reset_barrier(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 458 | lpfc_sli_brdreset(phba); |
| 459 | lpfc_hba_down_post(phba); |
| 460 | *(int *)(evtp->evt_arg1) = |
| 461 | lpfc_sli_brdready(phba, HS_MBRDY); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 462 | lpfc_unblock_mgmt_io(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 463 | complete((struct completion *)(evtp->evt_arg2)); |
| 464 | break; |
| 465 | case LPFC_EVT_KILL: |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 466 | lpfc_offline(phba); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 467 | *(int *)(evtp->evt_arg1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 468 | = (phba->pport->stopped) |
| 469 | ? 0 : lpfc_sli_brdkill(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 470 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 471 | complete((struct completion *)(evtp->evt_arg2)); |
| 472 | break; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 473 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
| 474 | lpfc_send_fastpath_evt(phba, evtp); |
| 475 | free_evt = 0; |
| 476 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 477 | } |
| 478 | if (free_evt) |
| 479 | kfree(evtp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 480 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 481 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 482 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 483 | |
| 484 | } |
| 485 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 486 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 487 | lpfc_work_done(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | { |
| 489 | struct lpfc_sli_ring *pring; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 490 | uint32_t ha_copy, status, control, work_port_events; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 491 | struct lpfc_vport **vports; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 492 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 493 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 494 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 495 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 496 | ha_copy = phba->work_ha; |
| 497 | phba->work_ha = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 498 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 500 | /* First, try to post the next mailbox command to SLI4 device */ |
| 501 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) |
| 502 | lpfc_sli4_post_async_mbox(phba); |
| 503 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 504 | if (ha_copy & HA_ERATT) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 505 | /* Handle the error attention event */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | lpfc_handle_eratt(phba); |
| 507 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 508 | if (ha_copy & HA_MBATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | lpfc_sli_handle_mb_event(phba); |
| 510 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 511 | if (ha_copy & HA_LATT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | lpfc_handle_latt(phba); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 513 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 514 | /* Process SLI4 events */ |
| 515 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
| 516 | if (phba->hba_flag & FCP_XRI_ABORT_EVENT) |
| 517 | lpfc_sli4_fcp_xri_abort_event_proc(phba); |
| 518 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
| 519 | lpfc_sli4_els_xri_abort_event_proc(phba); |
| 520 | if (phba->hba_flag & ASYNC_EVENT) |
| 521 | lpfc_sli4_async_event_proc(phba); |
| 522 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { |
| 523 | spin_lock_irq(&phba->hbalock); |
| 524 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; |
| 525 | spin_unlock_irq(&phba->hbalock); |
| 526 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 527 | } |
| 528 | if (phba->hba_flag & HBA_RECEIVE_BUFFER) |
| 529 | lpfc_sli4_handle_received_buffer(phba); |
| 530 | } |
| 531 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 532 | vports = lpfc_create_vport_work_array(phba); |
| 533 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 534 | for (i = 0; i <= phba->max_vports; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 535 | /* |
| 536 | * We could have no vports in array if unloading, so if |
| 537 | * this happens then just use the pport |
| 538 | */ |
| 539 | if (vports[i] == NULL && i == 0) |
| 540 | vport = phba->pport; |
| 541 | else |
| 542 | vport = vports[i]; |
| 543 | if (vport == NULL) |
| 544 | break; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 545 | spin_lock_irq(&vport->work_port_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 546 | work_port_events = vport->work_port_events; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 547 | vport->work_port_events &= ~work_port_events; |
| 548 | spin_unlock_irq(&vport->work_port_lock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 549 | if (work_port_events & WORKER_DISC_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 550 | lpfc_disc_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 551 | if (work_port_events & WORKER_ELS_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 552 | lpfc_els_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 553 | if (work_port_events & WORKER_HB_TMO) |
| 554 | lpfc_hb_timeout_handler(phba); |
| 555 | if (work_port_events & WORKER_MBOX_TMO) |
| 556 | lpfc_mbox_timeout_handler(phba); |
| 557 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) |
| 558 | lpfc_unblock_fabric_iocbs(phba); |
| 559 | if (work_port_events & WORKER_FDMI_TMO) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 560 | lpfc_fdmi_timeout_handler(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 561 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
| 562 | lpfc_ramp_down_queue_handler(phba); |
| 563 | if (work_port_events & WORKER_RAMP_UP_QUEUE) |
| 564 | lpfc_ramp_up_queue_handler(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 565 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 566 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 567 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 568 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 569 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 570 | status >>= (4*LPFC_ELS_RING); |
| 571 | if ((status & HA_RXMASK) |
| 572 | || (pring->flag & LPFC_DEFERRED_RING_EVENT)) { |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 573 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 574 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 575 | /* Set the lpfc data pending flag */ |
| 576 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 577 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 578 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 579 | lpfc_sli_handle_slow_ring_event(phba, pring, |
| 580 | (status & |
| 581 | HA_RXMASK)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 582 | } |
| 583 | /* |
| 584 | * Turn on Ring interrupts |
| 585 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 586 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 587 | spin_lock_irq(&phba->hbalock); |
| 588 | control = readl(phba->HCregaddr); |
| 589 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { |
| 590 | lpfc_debugfs_slow_ring_trc(phba, |
| 591 | "WRK Enable ring: cntl:x%x hacopy:x%x", |
| 592 | control, ha_copy, 0); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 593 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 594 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); |
| 595 | writel(control, phba->HCregaddr); |
| 596 | readl(phba->HCregaddr); /* flush */ |
| 597 | } else { |
| 598 | lpfc_debugfs_slow_ring_trc(phba, |
| 599 | "WRK Ring ok: cntl:x%x hacopy:x%x", |
| 600 | control, ha_copy, 0); |
| 601 | } |
| 602 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | } |
| 604 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 605 | lpfc_work_list_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | int |
| 609 | lpfc_do_work(void *p) |
| 610 | { |
| 611 | struct lpfc_hba *phba = p; |
| 612 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | |
| 614 | set_user_nice(current, -20); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 615 | phba->data_flags = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 617 | while (!kthread_should_stop()) { |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 618 | /* wait and check worker queue activities */ |
| 619 | rc = wait_event_interruptible(phba->work_waitq, |
| 620 | (test_and_clear_bit(LPFC_DATA_READY, |
| 621 | &phba->data_flags) |
| 622 | || kthread_should_stop())); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 623 | /* Signal wakeup shall terminate the worker thread */ |
| 624 | if (rc) { |
| 625 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 626 | "0433 Wakeup on signal: rc=x%x\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | break; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 628 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 630 | /* Attend pending lpfc data processing */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | lpfc_work_done(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | } |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 633 | phba->worker_thread = NULL; |
| 634 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 635 | "0432 Worker thread stopped.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * This is only called to handle FC worker events. Since this a rare |
| 641 | * occurance, we allocate a struct lpfc_work_evt structure here instead of |
| 642 | * embedding it in the IOCB. |
| 643 | */ |
| 644 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 645 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | uint32_t evt) |
| 647 | { |
| 648 | struct lpfc_work_evt *evtp; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 649 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will |
| 653 | * be queued to worker thread for processing |
| 654 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 655 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | if (!evtp) |
| 657 | return 0; |
| 658 | |
| 659 | evtp->evt_arg1 = arg1; |
| 660 | evtp->evt_arg2 = arg2; |
| 661 | evtp->evt = evt; |
| 662 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 663 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 664 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 665 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 667 | lpfc_worker_wake_up(phba); |
| 668 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | return 1; |
| 670 | } |
| 671 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 672 | void |
| 673 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) |
| 674 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 675 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 676 | struct lpfc_hba *phba = vport->phba; |
| 677 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 678 | int rc; |
| 679 | |
| 680 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 681 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 682 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 683 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 684 | continue; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 685 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
| 686 | ((vport->port_type == LPFC_NPIV_PORT) && |
| 687 | (ndlp->nlp_DID == NameServer_DID))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 688 | lpfc_unreg_rpi(vport, ndlp); |
| 689 | |
| 690 | /* Leave Fabric nodes alone on link down */ |
| 691 | if (!remove && ndlp->nlp_type & NLP_FABRIC) |
| 692 | continue; |
| 693 | rc = lpfc_disc_state_machine(vport, ndlp, NULL, |
| 694 | remove |
| 695 | ? NLP_EVT_DEVICE_RM |
| 696 | : NLP_EVT_DEVICE_RECOVERY); |
| 697 | } |
| 698 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { |
| 699 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 700 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 701 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 702 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 706 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 707 | lpfc_port_link_failure(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 708 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 709 | /* Cleanup any outstanding RSCN activity */ |
| 710 | lpfc_els_flush_rscn(vport); |
| 711 | |
| 712 | /* Cleanup any outstanding ELS commands */ |
| 713 | lpfc_els_flush_cmd(vport); |
| 714 | |
| 715 | lpfc_cleanup_rpis(vport, 0); |
| 716 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 717 | /* Turn off discovery timer if its running */ |
| 718 | lpfc_can_disctmo(vport); |
| 719 | } |
| 720 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 721 | void |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 722 | lpfc_linkdown_port(struct lpfc_vport *vport) |
| 723 | { |
| 724 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 725 | |
| 726 | fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); |
| 727 | |
| 728 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 729 | "Link Down: state:x%x rtry:x%x flg:x%x", |
| 730 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 731 | |
| 732 | lpfc_port_link_failure(vport); |
| 733 | |
| 734 | } |
| 735 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 737 | lpfc_linkdown(struct lpfc_hba *phba) |
| 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 = phba->pport; |
| 740 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 741 | struct lpfc_vport **vports; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 742 | LPFC_MBOXQ_t *mb; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 743 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 744 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 745 | if (phba->link_state == LPFC_LINK_DOWN) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 746 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 747 | spin_lock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 748 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_DISCOVERED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 749 | if (phba->link_state > LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 750 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 751 | phba->pport->fc_flag &= ~FC_LBIT; |
| 752 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 753 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 754 | vports = lpfc_create_vport_work_array(phba); |
| 755 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 756 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 757 | /* Issue a LINK DOWN event to all nodes */ |
| 758 | lpfc_linkdown_port(vports[i]); |
| 759 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 760 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | /* Clean up any firmware default rpi's */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 762 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 763 | if (mb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 764 | lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 765 | mb->vport = vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 766 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 767 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 769 | mempool_free(mb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | /* Setup myDID for link up if we are in pt2pt mode */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 774 | if (phba->pport->fc_flag & FC_PT2PT) { |
| 775 | phba->pport->fc_myDID = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 776 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 777 | if (mb) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | lpfc_config_link(phba, mb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 779 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 780 | mb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 781 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | == MBX_NOT_FINISHED) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | mempool_free(mb, phba->mbox_mem_pool); |
| 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 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 787 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 788 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 791 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | } |
| 793 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | static void |
| 795 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | struct lpfc_nodelist *ndlp; |
| 798 | |
| 799 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 800 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 801 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 802 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 803 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 804 | if (ndlp->nlp_type & NLP_FABRIC) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 805 | /* On Linkup its safe to clean up the ndlp |
| 806 | * from Fabric connections. |
| 807 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 808 | if (ndlp->nlp_DID != Fabric_DID) |
| 809 | lpfc_unreg_rpi(vport, ndlp); |
| 810 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 811 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 812 | /* Fail outstanding IO now since device is |
| 813 | * marked for PLOGI. |
| 814 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 815 | lpfc_unreg_rpi(vport, ndlp); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | static void |
| 821 | lpfc_linkup_port(struct lpfc_vport *vport) |
| 822 | { |
| 823 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | struct lpfc_hba *phba = vport->phba; |
| 825 | |
| 826 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 827 | return; |
| 828 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 829 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 830 | "Link Up: top:x%x speed:x%x flg:x%x", |
| 831 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); |
| 832 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 833 | /* If NPIV is not enabled, only bring the physical port up */ |
| 834 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 835 | (vport != phba->pport)) |
| 836 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 837 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 838 | 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] | 839 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 840 | spin_lock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 841 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
| 842 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); |
| 843 | vport->fc_flag |= FC_NDISC_ACTIVE; |
| 844 | vport->fc_ns_retry = 0; |
| 845 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 847 | if (vport->fc_flag & FC_LBIT) |
| 848 | lpfc_linkup_cleanup_nodes(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static int |
| 853 | lpfc_linkup(struct lpfc_hba *phba) |
| 854 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 855 | struct lpfc_vport **vports; |
| 856 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 857 | |
| 858 | phba->link_state = LPFC_LINK_UP; |
| 859 | |
| 860 | /* Unblock fabric iocbs if they are blocked */ |
| 861 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 862 | del_timer_sync(&phba->fabric_block_timer); |
| 863 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 864 | vports = lpfc_create_vport_work_array(phba); |
| 865 | if (vports != NULL) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 866 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 867 | lpfc_linkup_port(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 868 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 869 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 870 | (phba->sli_rev < LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 871 | lpfc_issue_clear_la(phba, phba->pport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * This routine handles processing a CLEAR_LA mailbox |
| 878 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 879 | * as the completion routine when the command is |
| 880 | * handed off to the SLI layer. |
| 881 | */ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 882 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 885 | struct lpfc_vport *vport = pmb->vport; |
| 886 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 887 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 888 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | uint32_t control; |
| 890 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | /* Since we don't do discovery right now, turn these off here */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 892 | psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 894 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 895 | |
| 896 | /* Check for error */ |
| 897 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 899 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 900 | "0320 CLEAR_LA mbxStatus error x%x hba " |
| 901 | "state x%x\n", |
| 902 | mb->mbxStatus, vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 903 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 904 | goto out; |
| 905 | } |
| 906 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 907 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 908 | phba->link_state = LPFC_HBA_READY; |
| 909 | |
| 910 | spin_lock_irq(&phba->hbalock); |
| 911 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 912 | control = readl(phba->HCregaddr); |
| 913 | control |= HC_LAINT_ENA; |
| 914 | writel(control, phba->HCregaddr); |
| 915 | readl(phba->HCregaddr); /* flush */ |
| 916 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 917 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 918 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | out: |
| 921 | /* Device Discovery completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 922 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 923 | "0225 Device Discovery completes\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 924 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | spin_lock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 927 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 928 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 929 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | |
| 932 | /* turn on Link Attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 933 | |
| 934 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 936 | control = readl(phba->HCregaddr); |
| 937 | control |= HC_LAINT_ENA; |
| 938 | writel(control, phba->HCregaddr); |
| 939 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 940 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | |
| 942 | return; |
| 943 | } |
| 944 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | static void |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 947 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 951 | if (pmb->u.mb.mbxStatus) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 954 | mempool_free(pmb, phba->mbox_mem_pool); |
| 955 | |
| 956 | if (phba->fc_topology == TOPOLOGY_LOOP && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 957 | vport->fc_flag & FC_PUBLIC_LOOP && |
| 958 | !(vport->fc_flag & FC_LBIT)) { |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 959 | /* Need to wait for FAN - use discovery timer |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 960 | * for timeout. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 961 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
| 962 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 963 | lpfc_set_disctmo(vport); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 964 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 967 | /* Start discovery by sending a FLOGI. port_state is identically |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 968 | * LPFC_FLOGI while waiting for FLOGI cmpl |
| 969 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 970 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 971 | lpfc_initial_flogi(vport); |
| 972 | } |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 973 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | |
| 975 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 976 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 977 | "0306 CONFIG_LINK mbxStatus error x%x " |
| 978 | "HBA state x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 979 | pmb->u.mb.mbxStatus, vport->port_state); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 980 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 981 | |
| 982 | lpfc_linkdown(phba); |
| 983 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 984 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 985 | "0200 CONFIG_LINK bad hba state x%x\n", |
| 986 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | return; |
| 990 | } |
| 991 | |
| 992 | static void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 993 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 994 | { |
| 995 | struct lpfc_vport *vport = mboxq->vport; |
| 996 | unsigned long flags; |
| 997 | |
| 998 | if (mboxq->u.mb.mbxStatus) { |
| 999 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1000 | "2017 REG_FCFI mbxStatus error x%x " |
| 1001 | "HBA state x%x\n", |
| 1002 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 1003 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | /* Start FCoE discovery by sending a FLOGI. */ |
| 1008 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); |
| 1009 | /* Set the FCFI registered flag */ |
| 1010 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1011 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
| 1012 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1013 | /* If there is a pending FCoE event, restart FCF table scan. */ |
| 1014 | if (lpfc_check_pending_fcoe_event(phba, 1)) { |
| 1015 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1016 | return; |
| 1017 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1018 | if (vport->port_state != LPFC_FLOGI) { |
| 1019 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1020 | phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1021 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1022 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1023 | lpfc_initial_flogi(vport); |
| 1024 | } |
| 1025 | |
| 1026 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1027 | return; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * lpfc_fab_name_match - Check if the fcf fabric name match. |
| 1032 | * @fab_name: pointer to fabric name. |
| 1033 | * @new_fcf_record: pointer to fcf record. |
| 1034 | * |
| 1035 | * This routine compare the fcf record's fabric name with provided |
| 1036 | * fabric name. If the fabric name are identical this function |
| 1037 | * returns 1 else return 0. |
| 1038 | **/ |
| 1039 | static uint32_t |
| 1040 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) |
| 1041 | { |
| 1042 | if ((fab_name[0] == |
| 1043 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) && |
| 1044 | (fab_name[1] == |
| 1045 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) && |
| 1046 | (fab_name[2] == |
| 1047 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) && |
| 1048 | (fab_name[3] == |
| 1049 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) && |
| 1050 | (fab_name[4] == |
| 1051 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) && |
| 1052 | (fab_name[5] == |
| 1053 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) && |
| 1054 | (fab_name[6] == |
| 1055 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) && |
| 1056 | (fab_name[7] == |
| 1057 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))) |
| 1058 | return 1; |
| 1059 | else |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | /** |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1064 | * lpfc_sw_name_match - Check if the fcf switch name match. |
| 1065 | * @fab_name: pointer to fabric name. |
| 1066 | * @new_fcf_record: pointer to fcf record. |
| 1067 | * |
| 1068 | * This routine compare the fcf record's switch name with provided |
| 1069 | * switch name. If the switch name are identical this function |
| 1070 | * returns 1 else return 0. |
| 1071 | **/ |
| 1072 | static uint32_t |
| 1073 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) |
| 1074 | { |
| 1075 | if ((sw_name[0] == |
| 1076 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) && |
| 1077 | (sw_name[1] == |
| 1078 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) && |
| 1079 | (sw_name[2] == |
| 1080 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) && |
| 1081 | (sw_name[3] == |
| 1082 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) && |
| 1083 | (sw_name[4] == |
| 1084 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) && |
| 1085 | (sw_name[5] == |
| 1086 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) && |
| 1087 | (sw_name[6] == |
| 1088 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) && |
| 1089 | (sw_name[7] == |
| 1090 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))) |
| 1091 | return 1; |
| 1092 | else |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1097 | * lpfc_mac_addr_match - Check if the fcf mac address match. |
| 1098 | * @phba: pointer to lpfc hba data structure. |
| 1099 | * @new_fcf_record: pointer to fcf record. |
| 1100 | * |
| 1101 | * This routine compare the fcf record's mac address with HBA's |
| 1102 | * FCF mac address. If the mac addresses are identical this function |
| 1103 | * returns 1 else return 0. |
| 1104 | **/ |
| 1105 | static uint32_t |
| 1106 | lpfc_mac_addr_match(struct lpfc_hba *phba, struct fcf_record *new_fcf_record) |
| 1107 | { |
| 1108 | if ((phba->fcf.mac_addr[0] == |
| 1109 | bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) && |
| 1110 | (phba->fcf.mac_addr[1] == |
| 1111 | bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) && |
| 1112 | (phba->fcf.mac_addr[2] == |
| 1113 | bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) && |
| 1114 | (phba->fcf.mac_addr[3] == |
| 1115 | bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) && |
| 1116 | (phba->fcf.mac_addr[4] == |
| 1117 | bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) && |
| 1118 | (phba->fcf.mac_addr[5] == |
| 1119 | bf_get(lpfc_fcf_record_mac_5, new_fcf_record))) |
| 1120 | return 1; |
| 1121 | else |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. |
| 1127 | * @phba: pointer to lpfc hba data structure. |
| 1128 | * @new_fcf_record: pointer to fcf record. |
| 1129 | * |
| 1130 | * This routine copies the FCF information from the FCF |
| 1131 | * record to lpfc_hba data structure. |
| 1132 | **/ |
| 1133 | static void |
| 1134 | lpfc_copy_fcf_record(struct lpfc_hba *phba, struct fcf_record *new_fcf_record) |
| 1135 | { |
| 1136 | phba->fcf.fabric_name[0] = |
| 1137 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
| 1138 | phba->fcf.fabric_name[1] = |
| 1139 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
| 1140 | phba->fcf.fabric_name[2] = |
| 1141 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
| 1142 | phba->fcf.fabric_name[3] = |
| 1143 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
| 1144 | phba->fcf.fabric_name[4] = |
| 1145 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
| 1146 | phba->fcf.fabric_name[5] = |
| 1147 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
| 1148 | phba->fcf.fabric_name[6] = |
| 1149 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
| 1150 | phba->fcf.fabric_name[7] = |
| 1151 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
| 1152 | phba->fcf.mac_addr[0] = |
| 1153 | bf_get(lpfc_fcf_record_mac_0, new_fcf_record); |
| 1154 | phba->fcf.mac_addr[1] = |
| 1155 | bf_get(lpfc_fcf_record_mac_1, new_fcf_record); |
| 1156 | phba->fcf.mac_addr[2] = |
| 1157 | bf_get(lpfc_fcf_record_mac_2, new_fcf_record); |
| 1158 | phba->fcf.mac_addr[3] = |
| 1159 | bf_get(lpfc_fcf_record_mac_3, new_fcf_record); |
| 1160 | phba->fcf.mac_addr[4] = |
| 1161 | bf_get(lpfc_fcf_record_mac_4, new_fcf_record); |
| 1162 | phba->fcf.mac_addr[5] = |
| 1163 | bf_get(lpfc_fcf_record_mac_5, new_fcf_record); |
| 1164 | phba->fcf.fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
| 1165 | phba->fcf.priority = new_fcf_record->fip_priority; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1166 | phba->fcf.switch_name[0] = |
| 1167 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
| 1168 | phba->fcf.switch_name[1] = |
| 1169 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
| 1170 | phba->fcf.switch_name[2] = |
| 1171 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
| 1172 | phba->fcf.switch_name[3] = |
| 1173 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
| 1174 | phba->fcf.switch_name[4] = |
| 1175 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
| 1176 | phba->fcf.switch_name[5] = |
| 1177 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
| 1178 | phba->fcf.switch_name[6] = |
| 1179 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
| 1180 | phba->fcf.switch_name[7] = |
| 1181 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * lpfc_register_fcf - Register the FCF with hba. |
| 1186 | * @phba: pointer to lpfc hba data structure. |
| 1187 | * |
| 1188 | * This routine issues a register fcfi mailbox command to register |
| 1189 | * the fcf with HBA. |
| 1190 | **/ |
| 1191 | static void |
| 1192 | lpfc_register_fcf(struct lpfc_hba *phba) |
| 1193 | { |
| 1194 | LPFC_MBOXQ_t *fcf_mbxq; |
| 1195 | int rc; |
| 1196 | unsigned long flags; |
| 1197 | |
| 1198 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1199 | |
| 1200 | /* If the FCF is not availabe do nothing. */ |
| 1201 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
| 1202 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | /* The FCF is already registered, start discovery */ |
| 1207 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { |
| 1208 | phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE); |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1209 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1210 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1211 | if (phba->pport->port_state != LPFC_FLOGI) |
| 1212 | lpfc_initial_flogi(phba->pport); |
| 1213 | return; |
| 1214 | } |
| 1215 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1216 | |
| 1217 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, |
| 1218 | GFP_KERNEL); |
| 1219 | if (!fcf_mbxq) |
| 1220 | return; |
| 1221 | |
| 1222 | lpfc_reg_fcfi(phba, fcf_mbxq); |
| 1223 | fcf_mbxq->vport = phba->pport; |
| 1224 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; |
| 1225 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); |
| 1226 | if (rc == MBX_NOT_FINISHED) |
| 1227 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
| 1228 | |
| 1229 | return; |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. |
| 1234 | * @phba: pointer to lpfc hba data structure. |
| 1235 | * @new_fcf_record: pointer to fcf record. |
| 1236 | * @boot_flag: Indicates if this record used by boot bios. |
| 1237 | * @addr_mode: The address mode to be used by this FCF |
| 1238 | * |
| 1239 | * This routine compare the fcf record with connect list obtained from the |
| 1240 | * config region to decide if this FCF can be used for SAN discovery. It returns |
| 1241 | * 1 if this record can be used for SAN discovery else return zero. If this FCF |
| 1242 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF |
| 1243 | * is used by boot bios and addr_mode will indicate the addressing mode to be |
| 1244 | * used for this FCF when the function returns. |
| 1245 | * If the FCF record need to be used with a particular vlan id, the vlan is |
| 1246 | * set in the vlan_id on return of the function. If not VLAN tagging need to |
| 1247 | * be used with the FCF vlan_id will be set to 0xFFFF; |
| 1248 | **/ |
| 1249 | static int |
| 1250 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, |
| 1251 | struct fcf_record *new_fcf_record, |
| 1252 | uint32_t *boot_flag, uint32_t *addr_mode, |
| 1253 | uint16_t *vlan_id) |
| 1254 | { |
| 1255 | struct lpfc_fcf_conn_entry *conn_entry; |
| 1256 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1257 | /* If FCF not available return 0 */ |
| 1258 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
| 1259 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record)) |
| 1260 | return 0; |
| 1261 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1262 | if (!phba->cfg_enable_fip) { |
| 1263 | *boot_flag = 0; |
| 1264 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1265 | new_fcf_record); |
| 1266 | if (phba->valid_vlan) |
| 1267 | *vlan_id = phba->vlan_id; |
| 1268 | else |
| 1269 | *vlan_id = 0xFFFF; |
| 1270 | return 1; |
| 1271 | } |
| 1272 | |
| 1273 | /* |
| 1274 | * If there are no FCF connection table entry, driver connect to all |
| 1275 | * FCFs. |
| 1276 | */ |
| 1277 | if (list_empty(&phba->fcf_conn_rec_list)) { |
| 1278 | *boot_flag = 0; |
| 1279 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1280 | new_fcf_record); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1281 | |
| 1282 | /* |
| 1283 | * When there are no FCF connect entries, use driver's default |
| 1284 | * addressing mode - FPMA. |
| 1285 | */ |
| 1286 | if (*addr_mode & LPFC_FCF_FPMA) |
| 1287 | *addr_mode = LPFC_FCF_FPMA; |
| 1288 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1289 | *vlan_id = 0xFFFF; |
| 1290 | return 1; |
| 1291 | } |
| 1292 | |
| 1293 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, list) { |
| 1294 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
| 1295 | continue; |
| 1296 | |
| 1297 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && |
| 1298 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1299 | new_fcf_record)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1300 | continue; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1301 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && |
| 1302 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, |
| 1303 | new_fcf_record)) |
| 1304 | continue; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1305 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
| 1306 | /* |
| 1307 | * If the vlan bit map does not have the bit set for the |
| 1308 | * vlan id to be used, then it is not a match. |
| 1309 | */ |
| 1310 | if (!(new_fcf_record->vlan_bitmap |
| 1311 | [conn_entry->conn_rec.vlan_tag / 8] & |
| 1312 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) |
| 1313 | continue; |
| 1314 | } |
| 1315 | |
| 1316 | /* |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1317 | * If connection record does not support any addressing mode, |
| 1318 | * skip the FCF record. |
| 1319 | */ |
| 1320 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) |
| 1321 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) |
| 1322 | continue; |
| 1323 | |
| 1324 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1325 | * Check if the connection record specifies a required |
| 1326 | * addressing mode. |
| 1327 | */ |
| 1328 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1329 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { |
| 1330 | |
| 1331 | /* |
| 1332 | * If SPMA required but FCF not support this continue. |
| 1333 | */ |
| 1334 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1335 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1336 | new_fcf_record) & LPFC_FCF_SPMA)) |
| 1337 | continue; |
| 1338 | |
| 1339 | /* |
| 1340 | * If FPMA required but FCF not support this continue. |
| 1341 | */ |
| 1342 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1343 | !(bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1344 | new_fcf_record) & LPFC_FCF_FPMA)) |
| 1345 | continue; |
| 1346 | } |
| 1347 | |
| 1348 | /* |
| 1349 | * This fcf record matches filtering criteria. |
| 1350 | */ |
| 1351 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) |
| 1352 | *boot_flag = 1; |
| 1353 | else |
| 1354 | *boot_flag = 0; |
| 1355 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1356 | /* |
| 1357 | * If user did not specify any addressing mode, or if the |
| 1358 | * prefered addressing mode specified by user is not supported |
| 1359 | * by FCF, allow fabric to pick the addressing mode. |
| 1360 | */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1361 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
| 1362 | new_fcf_record); |
| 1363 | /* |
| 1364 | * If the user specified a required address mode, assign that |
| 1365 | * address mode |
| 1366 | */ |
| 1367 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1368 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) |
| 1369 | *addr_mode = (conn_entry->conn_rec.flags & |
| 1370 | FCFCNCT_AM_SPMA) ? |
| 1371 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; |
| 1372 | /* |
| 1373 | * If the user specified a prefered address mode, use the |
| 1374 | * addr mode only if FCF support the addr_mode. |
| 1375 | */ |
| 1376 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1377 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1378 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1379 | (*addr_mode & LPFC_FCF_SPMA)) |
| 1380 | *addr_mode = LPFC_FCF_SPMA; |
| 1381 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && |
| 1382 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && |
| 1383 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && |
| 1384 | (*addr_mode & LPFC_FCF_FPMA)) |
| 1385 | *addr_mode = LPFC_FCF_FPMA; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1386 | |
| 1387 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
| 1388 | *vlan_id = conn_entry->conn_rec.vlan_tag; |
| 1389 | else |
| 1390 | *vlan_id = 0xFFFF; |
| 1391 | |
| 1392 | return 1; |
| 1393 | } |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | /** |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1399 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. |
| 1400 | * @phba: pointer to lpfc hba data structure. |
| 1401 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. |
| 1402 | * |
| 1403 | * This function check if there is any fcoe event pending while driver |
| 1404 | * scan FCF entries. If there is any pending event, it will restart the |
| 1405 | * FCF saning and return 1 else return 0. |
| 1406 | */ |
| 1407 | int |
| 1408 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) |
| 1409 | { |
| 1410 | LPFC_MBOXQ_t *mbox; |
| 1411 | int rc; |
| 1412 | /* |
| 1413 | * If the Link is up and no FCoE events while in the |
| 1414 | * FCF discovery, no need to restart FCF discovery. |
| 1415 | */ |
| 1416 | if ((phba->link_state >= LPFC_LINK_UP) && |
| 1417 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
| 1418 | return 0; |
| 1419 | |
| 1420 | spin_lock_irq(&phba->hbalock); |
| 1421 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; |
| 1422 | spin_unlock_irq(&phba->hbalock); |
| 1423 | |
| 1424 | if (phba->link_state >= LPFC_LINK_UP) |
| 1425 | lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 1426 | |
| 1427 | if (unreg_fcf) { |
| 1428 | spin_lock_irq(&phba->hbalock); |
| 1429 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; |
| 1430 | spin_unlock_irq(&phba->hbalock); |
| 1431 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1432 | if (!mbox) { |
| 1433 | lpfc_printf_log(phba, KERN_ERR, |
| 1434 | LOG_DISCOVERY|LOG_MBOX, |
| 1435 | "2610 UNREG_FCFI mbox allocation failed\n"); |
| 1436 | return 1; |
| 1437 | } |
| 1438 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 1439 | mbox->vport = phba->pport; |
| 1440 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 1441 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 1442 | if (rc == MBX_NOT_FINISHED) { |
| 1443 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 1444 | "2611 UNREG_FCFI issue mbox failed\n"); |
| 1445 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | return 1; |
| 1450 | } |
| 1451 | |
| 1452 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1453 | * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox. |
| 1454 | * @phba: pointer to lpfc hba data structure. |
| 1455 | * @mboxq: pointer to mailbox object. |
| 1456 | * |
| 1457 | * This function iterate through all the fcf records available in |
| 1458 | * HBA and choose the optimal FCF record for discovery. After finding |
| 1459 | * the FCF for discovery it register the FCF record and kick start |
| 1460 | * discovery. |
| 1461 | * If FCF_IN_USE flag is set in currently used FCF, the routine try to |
| 1462 | * use a FCF record which match fabric name and mac address of the |
| 1463 | * currently used FCF record. |
| 1464 | * If the driver support only one FCF, it will try to use the FCF record |
| 1465 | * used by BOOT_BIOS. |
| 1466 | */ |
| 1467 | void |
| 1468 | lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1469 | { |
| 1470 | void *virt_addr; |
| 1471 | dma_addr_t phys_addr; |
| 1472 | uint8_t *bytep; |
| 1473 | struct lpfc_mbx_sge sge; |
| 1474 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 1475 | uint32_t shdr_status, shdr_add_status; |
| 1476 | union lpfc_sli4_cfg_shdr *shdr; |
| 1477 | struct fcf_record *new_fcf_record; |
| 1478 | int rc; |
| 1479 | uint32_t boot_flag, addr_mode; |
| 1480 | uint32_t next_fcf_index; |
| 1481 | unsigned long flags; |
| 1482 | uint16_t vlan_id; |
| 1483 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1484 | /* If there is pending FCoE event restart FCF table scan */ |
| 1485 | if (lpfc_check_pending_fcoe_event(phba, 0)) { |
| 1486 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1487 | return; |
| 1488 | } |
| 1489 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1490 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 1491 | * routine only uses a single SGE. |
| 1492 | */ |
| 1493 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 1494 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1495 | if (unlikely(!mboxq->sge_array)) { |
| 1496 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1497 | "2524 Failed to get the non-embedded SGE " |
| 1498 | "virtual address\n"); |
| 1499 | goto out; |
| 1500 | } |
| 1501 | virt_addr = mboxq->sge_array->addr[0]; |
| 1502 | |
| 1503 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; |
| 1504 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 1505 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 1506 | &shdr->response); |
| 1507 | /* |
| 1508 | * The FCF Record was read and there is no reason for the driver |
| 1509 | * to maintain the FCF record data or memory. Instead, just need |
| 1510 | * to book keeping the FCFIs can be used. |
| 1511 | */ |
| 1512 | if (shdr_status || shdr_add_status) { |
| 1513 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1514 | "2521 READ_FCF_RECORD mailbox failed " |
| 1515 | "with status x%x add_status x%x, mbx\n", |
| 1516 | shdr_status, shdr_add_status); |
| 1517 | goto out; |
| 1518 | } |
| 1519 | /* Interpreting the returned information of FCF records */ |
| 1520 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 1521 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, |
| 1522 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1523 | next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf); |
| 1524 | |
| 1525 | new_fcf_record = (struct fcf_record *)(virt_addr + |
| 1526 | sizeof(struct lpfc_mbx_read_fcf_tbl)); |
| 1527 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, |
| 1528 | sizeof(struct fcf_record)); |
| 1529 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 1530 | |
| 1531 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, |
| 1532 | &boot_flag, &addr_mode, |
| 1533 | &vlan_id); |
| 1534 | /* |
| 1535 | * If the fcf record does not match with connect list entries |
| 1536 | * read the next entry. |
| 1537 | */ |
| 1538 | if (!rc) |
| 1539 | goto read_next_fcf; |
| 1540 | /* |
| 1541 | * If this is not the first FCF discovery of the HBA, use last |
| 1542 | * FCF record for the discovery. |
| 1543 | */ |
| 1544 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1545 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
| 1546 | if (lpfc_fab_name_match(phba->fcf.fabric_name, |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1547 | new_fcf_record) && |
| 1548 | lpfc_sw_name_match(phba->fcf.switch_name, |
| 1549 | new_fcf_record) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1550 | lpfc_mac_addr_match(phba, new_fcf_record)) { |
| 1551 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 1552 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1553 | goto out; |
| 1554 | } |
| 1555 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1556 | goto read_next_fcf; |
| 1557 | } |
| 1558 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
| 1559 | /* |
| 1560 | * If the current FCF record does not have boot flag |
| 1561 | * set and new fcf record has boot flag set, use the |
| 1562 | * new fcf record. |
| 1563 | */ |
| 1564 | if (boot_flag && !(phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) { |
| 1565 | /* Use this FCF record */ |
| 1566 | lpfc_copy_fcf_record(phba, new_fcf_record); |
| 1567 | phba->fcf.addr_mode = addr_mode; |
| 1568 | phba->fcf.fcf_flag |= FCF_BOOT_ENABLE; |
| 1569 | if (vlan_id != 0xFFFF) { |
| 1570 | phba->fcf.fcf_flag |= FCF_VALID_VLAN; |
| 1571 | phba->fcf.vlan_id = vlan_id; |
| 1572 | } |
| 1573 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1574 | goto read_next_fcf; |
| 1575 | } |
| 1576 | /* |
| 1577 | * If the current FCF record has boot flag set and the |
| 1578 | * new FCF record does not have boot flag, read the next |
| 1579 | * FCF record. |
| 1580 | */ |
| 1581 | if (!boot_flag && (phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) { |
| 1582 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1583 | goto read_next_fcf; |
| 1584 | } |
| 1585 | /* |
| 1586 | * If there is a record with lower priority value for |
| 1587 | * the current FCF, use that record. |
| 1588 | */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1589 | if (lpfc_fab_name_match(phba->fcf.fabric_name, |
| 1590 | new_fcf_record) && |
| 1591 | (new_fcf_record->fip_priority < phba->fcf.priority)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1592 | /* Use this FCF record */ |
| 1593 | lpfc_copy_fcf_record(phba, new_fcf_record); |
| 1594 | phba->fcf.addr_mode = addr_mode; |
| 1595 | if (vlan_id != 0xFFFF) { |
| 1596 | phba->fcf.fcf_flag |= FCF_VALID_VLAN; |
| 1597 | phba->fcf.vlan_id = vlan_id; |
| 1598 | } |
| 1599 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1600 | goto read_next_fcf; |
| 1601 | } |
| 1602 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1603 | goto read_next_fcf; |
| 1604 | } |
| 1605 | /* |
| 1606 | * This is the first available FCF record, use this |
| 1607 | * record. |
| 1608 | */ |
| 1609 | lpfc_copy_fcf_record(phba, new_fcf_record); |
| 1610 | phba->fcf.addr_mode = addr_mode; |
| 1611 | if (boot_flag) |
| 1612 | phba->fcf.fcf_flag |= FCF_BOOT_ENABLE; |
| 1613 | phba->fcf.fcf_flag |= FCF_AVAILABLE; |
| 1614 | if (vlan_id != 0xFFFF) { |
| 1615 | phba->fcf.fcf_flag |= FCF_VALID_VLAN; |
| 1616 | phba->fcf.vlan_id = vlan_id; |
| 1617 | } |
| 1618 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1619 | goto read_next_fcf; |
| 1620 | |
| 1621 | read_next_fcf: |
| 1622 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1623 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) |
| 1624 | lpfc_register_fcf(phba); |
| 1625 | else |
| 1626 | lpfc_sli4_read_fcf_record(phba, next_fcf_index); |
| 1627 | return; |
| 1628 | |
| 1629 | out: |
| 1630 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 1631 | lpfc_register_fcf(phba); |
| 1632 | |
| 1633 | return; |
| 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. |
| 1638 | * @phba: pointer to lpfc hba data structure. |
| 1639 | * |
| 1640 | * This function loops through the list of vports on the @phba and issues an |
| 1641 | * FDISC if possible. |
| 1642 | */ |
| 1643 | void |
| 1644 | lpfc_start_fdiscs(struct lpfc_hba *phba) |
| 1645 | { |
| 1646 | struct lpfc_vport **vports; |
| 1647 | int i; |
| 1648 | |
| 1649 | vports = lpfc_create_vport_work_array(phba); |
| 1650 | if (vports != NULL) { |
| 1651 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 1652 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 1653 | continue; |
| 1654 | /* There are no vpi for this vport */ |
| 1655 | if (vports[i]->vpi > phba->max_vpi) { |
| 1656 | lpfc_vport_set_state(vports[i], |
| 1657 | FC_VPORT_FAILED); |
| 1658 | continue; |
| 1659 | } |
| 1660 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1661 | lpfc_vport_set_state(vports[i], |
| 1662 | FC_VPORT_LINKDOWN); |
| 1663 | continue; |
| 1664 | } |
| 1665 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
| 1666 | lpfc_initial_fdisc(vports[i]); |
| 1667 | else { |
| 1668 | lpfc_vport_set_state(vports[i], |
| 1669 | FC_VPORT_NO_FABRIC_SUPP); |
| 1670 | lpfc_printf_vlog(vports[i], KERN_ERR, |
| 1671 | LOG_ELS, |
| 1672 | "0259 No NPIV " |
| 1673 | "Fabric support\n"); |
| 1674 | } |
| 1675 | } |
| 1676 | } |
| 1677 | lpfc_destroy_vport_work_array(phba, vports); |
| 1678 | } |
| 1679 | |
| 1680 | void |
| 1681 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1682 | { |
| 1683 | struct lpfc_dmabuf *dmabuf = mboxq->context1; |
| 1684 | struct lpfc_vport *vport = mboxq->vport; |
| 1685 | |
| 1686 | if (mboxq->u.mb.mbxStatus) { |
| 1687 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1688 | "2018 REG_VFI mbxStatus error x%x " |
| 1689 | "HBA state x%x\n", |
| 1690 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 1691 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1692 | /* FLOGI failed, use loop map to make discovery list */ |
| 1693 | lpfc_disc_list_loopmap(vport); |
| 1694 | /* Start discovery */ |
| 1695 | lpfc_disc_start(vport); |
| 1696 | goto fail_free_mem; |
| 1697 | } |
| 1698 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 1699 | goto fail_free_mem; |
| 1700 | } |
| 1701 | /* Mark the vport has registered with its VFI */ |
| 1702 | vport->vfi_state |= LPFC_VFI_REGISTERED; |
| 1703 | |
| 1704 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
| 1705 | lpfc_start_fdiscs(phba); |
| 1706 | lpfc_do_scr_ns_plogi(phba, vport); |
| 1707 | } |
| 1708 | |
| 1709 | fail_free_mem: |
| 1710 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 1711 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 1712 | kfree(dmabuf); |
| 1713 | return; |
| 1714 | } |
| 1715 | |
| 1716 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1717 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1719 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1720 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | |
| 1723 | |
| 1724 | /* Check for error */ |
| 1725 | if (mb->mbxStatus) { |
| 1726 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1727 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1728 | "0319 READ_SPARAM mbxStatus error x%x " |
| 1729 | "hba state x%x>\n", |
| 1730 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1731 | lpfc_linkdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | goto out; |
| 1733 | } |
| 1734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1735 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | sizeof (struct serv_parm)); |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1737 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 1739 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1740 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 1742 | vport->fc_sparam.portName.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1743 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 1744 | sizeof(vport->fc_nodename)); |
| 1745 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 1746 | sizeof(vport->fc_portname)); |
| 1747 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 1748 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); |
| 1749 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); |
| 1750 | } |
| 1751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1753 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1755 | return; |
| 1756 | |
| 1757 | out: |
| 1758 | pmb->context1 = NULL; |
| 1759 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1760 | kfree(mp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1761 | lpfc_issue_clear_la(phba, vport); |
| 1762 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | return; |
| 1764 | } |
| 1765 | |
| 1766 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1769 | struct lpfc_vport *vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1770 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | int i; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1772 | struct lpfc_dmabuf *mp; |
| 1773 | int rc; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1774 | struct fcf_record *fcf_record; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1775 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1778 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1779 | switch (la->UlnkSpeed) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1780 | case LA_1GHZ_LINK: |
| 1781 | phba->fc_linkspeed = LA_1GHZ_LINK; |
| 1782 | break; |
| 1783 | case LA_2GHZ_LINK: |
| 1784 | phba->fc_linkspeed = LA_2GHZ_LINK; |
| 1785 | break; |
| 1786 | case LA_4GHZ_LINK: |
| 1787 | phba->fc_linkspeed = LA_4GHZ_LINK; |
| 1788 | break; |
| 1789 | case LA_8GHZ_LINK: |
| 1790 | phba->fc_linkspeed = LA_8GHZ_LINK; |
| 1791 | break; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1792 | case LA_10GHZ_LINK: |
| 1793 | phba->fc_linkspeed = LA_10GHZ_LINK; |
| 1794 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1795 | default: |
| 1796 | phba->fc_linkspeed = LA_UNKNW_LINK; |
| 1797 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | phba->fc_topology = la->topology; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1801 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | |
| 1803 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1804 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1805 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1806 | if (phba->cfg_enable_npiv) |
| 1807 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 1808 | "1309 Link Up Event npiv not supported in loop " |
| 1809 | "topology\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1810 | /* Get Loop Map information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | if (la->il) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1812 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1813 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | vport->fc_myDID = la->granted_AL_PA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | i = la->un.lilpBde64.tus.f.bdeSize; |
| 1816 | |
| 1817 | if (i == 0) { |
| 1818 | phba->alpa_map[0] = 0; |
| 1819 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1820 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | int numalpa, j, k; |
| 1822 | union { |
| 1823 | uint8_t pamap[16]; |
| 1824 | struct { |
| 1825 | uint32_t wd1; |
| 1826 | uint32_t wd2; |
| 1827 | uint32_t wd3; |
| 1828 | uint32_t wd4; |
| 1829 | } pa; |
| 1830 | } un; |
| 1831 | numalpa = phba->alpa_map[0]; |
| 1832 | j = 0; |
| 1833 | while (j < numalpa) { |
| 1834 | memset(un.pamap, 0, 16); |
| 1835 | for (k = 1; j < numalpa; k++) { |
| 1836 | un.pamap[k - 1] = |
| 1837 | phba->alpa_map[j + 1]; |
| 1838 | j++; |
| 1839 | if (k == 16) |
| 1840 | break; |
| 1841 | } |
| 1842 | /* Link Up Event ALPA map */ |
| 1843 | lpfc_printf_log(phba, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1844 | KERN_WARNING, |
| 1845 | LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1846 | "1304 Link Up Event " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | "ALPA map Data: x%x " |
| 1848 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1849 | un.pa.wd1, un.pa.wd2, |
| 1850 | un.pa.wd3, un.pa.wd4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1855 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1856 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | (phba->sli_rev == 3)) |
| 1858 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 1859 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1860 | vport->fc_myDID = phba->fc_pref_DID; |
| 1861 | vport->fc_flag |= FC_LBIT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1863 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | |
| 1865 | lpfc_linkup(phba); |
| 1866 | if (sparam_mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1867 | lpfc_read_sparam(phba, sparam_mbox, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | sparam_mbox->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1869 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1870 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1871 | if (rc == MBX_NOT_FINISHED) { |
| 1872 | mp = (struct lpfc_dmabuf *) sparam_mbox->context1; |
| 1873 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1874 | kfree(mp); |
| 1875 | mempool_free(sparam_mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1876 | goto out; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1877 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | } |
| 1879 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1880 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) { |
| 1881 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1882 | if (!cfglink_mbox) |
| 1883 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1884 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | lpfc_config_link(phba, cfglink_mbox); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1886 | cfglink_mbox->vport = vport; |
Jamie Wellnitz | 25594c6 | 2006-02-28 19:25:34 -0500 | [diff] [blame] | 1887 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1888 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1889 | if (rc == MBX_NOT_FINISHED) { |
| 1890 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); |
| 1891 | goto out; |
| 1892 | } |
| 1893 | } else { |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1894 | vport->port_state = LPFC_VPORT_UNKNOWN; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1895 | /* |
| 1896 | * Add the driver's default FCF record at FCF index 0 now. This |
| 1897 | * is phase 1 implementation that support FCF index 0 and driver |
| 1898 | * defaults. |
| 1899 | */ |
| 1900 | if (phba->cfg_enable_fip == 0) { |
| 1901 | fcf_record = kzalloc(sizeof(struct fcf_record), |
| 1902 | GFP_KERNEL); |
| 1903 | if (unlikely(!fcf_record)) { |
| 1904 | lpfc_printf_log(phba, KERN_ERR, |
| 1905 | LOG_MBOX | LOG_SLI, |
| 1906 | "2554 Could not allocate memmory for " |
| 1907 | "fcf record\n"); |
| 1908 | rc = -ENODEV; |
| 1909 | goto out; |
| 1910 | } |
| 1911 | |
| 1912 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, |
| 1913 | LPFC_FCOE_FCF_DEF_INDEX); |
| 1914 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); |
| 1915 | if (unlikely(rc)) { |
| 1916 | lpfc_printf_log(phba, KERN_ERR, |
| 1917 | LOG_MBOX | LOG_SLI, |
| 1918 | "2013 Could not manually add FCF " |
| 1919 | "record 0, status %d\n", rc); |
| 1920 | rc = -ENODEV; |
| 1921 | kfree(fcf_record); |
| 1922 | goto out; |
| 1923 | } |
| 1924 | kfree(fcf_record); |
| 1925 | } |
| 1926 | /* |
| 1927 | * The driver is expected to do FIP/FCF. Call the port |
| 1928 | * and get the FCF Table. |
| 1929 | */ |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 1930 | spin_lock_irq(&phba->hbalock); |
| 1931 | if (phba->hba_flag & FCF_DISC_INPROGRESS) { |
| 1932 | spin_unlock_irq(&phba->hbalock); |
| 1933 | return; |
| 1934 | } |
| 1935 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1936 | rc = lpfc_sli4_read_fcf_record(phba, |
| 1937 | LPFC_FCOE_FCF_GET_FIRST); |
| 1938 | if (rc) |
| 1939 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1941 | |
| 1942 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1943 | out: |
| 1944 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1945 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 1946 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", |
| 1947 | vport->port_state, sparam_mbox, cfglink_mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1948 | lpfc_issue_clear_la(phba, vport); |
| 1949 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | static void |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1953 | lpfc_enable_la(struct lpfc_hba *phba) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | uint32_t control; |
| 1956 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1957 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | psli->sli_flag |= LPFC_PROCESS_LA; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1959 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 1960 | control = readl(phba->HCregaddr); |
| 1961 | control |= HC_LAINT_ENA; |
| 1962 | writel(control, phba->HCregaddr); |
| 1963 | readl(phba->HCregaddr); /* flush */ |
| 1964 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | } |
| 1967 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1968 | static void |
| 1969 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) |
| 1970 | { |
| 1971 | lpfc_linkdown(phba); |
| 1972 | lpfc_enable_la(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1973 | lpfc_unregister_unused_fcf(phba); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1974 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
| 1975 | } |
| 1976 | |
| 1977 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1978 | /* |
| 1979 | * This routine handles processing a READ_LA mailbox |
| 1980 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 1981 | * as the completion routine when the command is |
| 1982 | * handed off to the SLI layer. |
| 1983 | */ |
| 1984 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1985 | lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1987 | struct lpfc_vport *vport = pmb->vport; |
| 1988 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | READ_LA_VAR *la; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1990 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1991 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 1992 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1993 | /* Unblock ELS traffic */ |
| 1994 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | /* Check for error */ |
| 1996 | if (mb->mbxStatus) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1997 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1998 | "1307 READ_LA mbox error x%x state x%x\n", |
| 1999 | mb->mbxStatus, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | lpfc_mbx_issue_link_down(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2001 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | goto lpfc_mbx_cmpl_read_la_free_mbuf; |
| 2003 | } |
| 2004 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2005 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | |
| 2007 | memcpy(&phba->alpa_map[0], mp->virt, 128); |
| 2008 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2010 | if (la->pb) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2011 | vport->fc_flag |= FC_BYPASSED_MODE; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2012 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2013 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
| 2014 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2015 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 2016 | if ((phba->fc_eventTag < la->eventTag) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2017 | (phba->fc_eventTag == la->eventTag)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | phba->fc_stat.LinkMultiEvent++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | if (la->attType == AT_LINK_UP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | if (phba->fc_eventTag != 0) |
| 2021 | lpfc_linkdown(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2022 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | |
| 2024 | phba->fc_eventTag = la->eventTag; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2025 | if (la->mm) |
| 2026 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; |
| 2027 | else |
| 2028 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2030 | if (la->attType == AT_LINK_UP && (!la->mm)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2031 | phba->fc_stat.LinkUp++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2033 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2034 | "1306 Link Up Event in loop back mode " |
| 2035 | "x%x received Data: x%x x%x x%x x%x\n", |
| 2036 | la->eventTag, phba->fc_eventTag, |
| 2037 | la->granted_AL_PA, la->UlnkSpeed, |
| 2038 | phba->alpa_map[0]); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2039 | } else { |
| 2040 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2041 | "1303 Link Up Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2042 | "Data: x%x x%x x%x x%x x%x x%x %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2043 | la->eventTag, phba->fc_eventTag, |
| 2044 | la->granted_AL_PA, la->UlnkSpeed, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2045 | phba->alpa_map[0], |
| 2046 | la->mm, la->fa, |
| 2047 | phba->wait_4_mlo_maint_flg); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2048 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2049 | lpfc_mbx_process_link_up(phba, la); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2050 | } else if (la->attType == AT_LINK_DOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | phba->fc_stat.LinkDown++; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2052 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
| 2053 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2054 | "1308 Link Down Event in loop back mode " |
| 2055 | "x%x received " |
| 2056 | "Data: x%x x%x x%x\n", |
| 2057 | la->eventTag, phba->fc_eventTag, |
| 2058 | phba->pport->port_state, vport->fc_flag); |
| 2059 | } |
| 2060 | else { |
| 2061 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2062 | "1305 Link Down Event x%x received " |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2063 | "Data: x%x x%x x%x x%x x%x\n", |
| 2064 | la->eventTag, phba->fc_eventTag, |
| 2065 | phba->pport->port_state, vport->fc_flag, |
| 2066 | la->mm, la->fa); |
| 2067 | } |
| 2068 | lpfc_mbx_issue_link_down(phba); |
| 2069 | } |
| 2070 | if (la->mm && la->attType == AT_LINK_UP) { |
| 2071 | if (phba->link_state != LPFC_LINK_DOWN) { |
| 2072 | phba->fc_stat.LinkDown++; |
| 2073 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2074 | "1312 Link Down Event x%x received " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2076 | la->eventTag, phba->fc_eventTag, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | phba->pport->port_state, vport->fc_flag); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2078 | lpfc_mbx_issue_link_down(phba); |
| 2079 | } else |
| 2080 | lpfc_enable_la(phba); |
| 2081 | |
| 2082 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 2083 | "1310 Menlo Maint Mode Link up Event x%x rcvd " |
| 2084 | "Data: x%x x%x x%x\n", |
| 2085 | la->eventTag, phba->fc_eventTag, |
| 2086 | phba->pport->port_state, vport->fc_flag); |
| 2087 | /* |
| 2088 | * The cmnd that triggered this will be waiting for this |
| 2089 | * signal. |
| 2090 | */ |
| 2091 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ |
| 2092 | if (phba->wait_4_mlo_maint_flg) { |
| 2093 | phba->wait_4_mlo_maint_flg = 0; |
| 2094 | wake_up_interruptible(&phba->wait_4_mlo_m_q); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2095 | } |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | if (la->fa) { |
| 2099 | if (la->mm) |
| 2100 | lpfc_issue_clear_la(phba, vport); |
| 2101 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 2102 | "1311 fa %d\n", la->fa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | lpfc_mbx_cmpl_read_la_free_mbuf: |
| 2106 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2107 | kfree(mp); |
| 2108 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2109 | return; |
| 2110 | } |
| 2111 | |
| 2112 | /* |
| 2113 | * This routine handles processing a REG_LOGIN mailbox |
| 2114 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2115 | * as the completion routine when the command is |
| 2116 | * handed off to the SLI layer. |
| 2117 | */ |
| 2118 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2122 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | pmb->context1 = NULL; |
| 2126 | |
| 2127 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2128 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2130 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2131 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2132 | /* decrement the node reference count held for this callback |
| 2133 | * function. |
| 2134 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2135 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | |
| 2137 | return; |
| 2138 | } |
| 2139 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2140 | static void |
| 2141 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2142 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2143 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2144 | struct lpfc_vport *vport = pmb->vport; |
| 2145 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2146 | |
| 2147 | switch (mb->mbxStatus) { |
| 2148 | case 0x0011: |
| 2149 | case 0x0020: |
| 2150 | case 0x9700: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2151 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2152 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", |
| 2153 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2154 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2155 | } |
| 2156 | vport->unreg_vpi_cmpl = VPORT_OK; |
| 2157 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2158 | /* |
| 2159 | * This shost reference might have been taken at the beginning of |
| 2160 | * lpfc_vport_delete() |
| 2161 | */ |
| 2162 | if (vport->load_flag & FC_UNLOADING) |
| 2163 | scsi_host_put(shost); |
| 2164 | } |
| 2165 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2166 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2167 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
| 2168 | { |
| 2169 | struct lpfc_hba *phba = vport->phba; |
| 2170 | LPFC_MBOXQ_t *mbox; |
| 2171 | int rc; |
| 2172 | |
| 2173 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2174 | if (!mbox) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2175 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2176 | |
| 2177 | lpfc_unreg_vpi(phba, vport->vpi, mbox); |
| 2178 | mbox->vport = vport; |
| 2179 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2180 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2181 | if (rc == MBX_NOT_FINISHED) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2182 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 2183 | "1800 Could not issue unreg_vpi\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2185 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2186 | return rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2187 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2188 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | static void |
| 2192 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2193 | { |
| 2194 | struct lpfc_vport *vport = pmb->vport; |
| 2195 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2196 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | |
| 2198 | switch (mb->mbxStatus) { |
| 2199 | case 0x0011: |
| 2200 | case 0x9601: |
| 2201 | case 0x9602: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2202 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2203 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", |
| 2204 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 2206 | spin_lock_irq(shost->host_lock); |
| 2207 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 2208 | spin_unlock_irq(shost->host_lock); |
| 2209 | vport->fc_myDID = 0; |
| 2210 | goto out; |
| 2211 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | |
| 2213 | vport->num_disc_nodes = 0; |
| 2214 | /* go thru NPR list and issue ELS PLOGIs */ |
| 2215 | if (vport->fc_npr_cnt) |
| 2216 | lpfc_els_disc_plogi(vport); |
| 2217 | |
| 2218 | if (!vport->num_disc_nodes) { |
| 2219 | spin_lock_irq(shost->host_lock); |
| 2220 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2221 | spin_unlock_irq(shost->host_lock); |
| 2222 | lpfc_can_disctmo(vport); |
| 2223 | } |
| 2224 | vport->port_state = LPFC_VPORT_READY; |
| 2225 | |
| 2226 | out: |
| 2227 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2228 | return; |
| 2229 | } |
| 2230 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2231 | /** |
| 2232 | * lpfc_create_static_vport - Read HBA config region to create static vports. |
| 2233 | * @phba: pointer to lpfc hba data structure. |
| 2234 | * |
| 2235 | * This routine issue a DUMP mailbox command for config region 22 to get |
| 2236 | * the list of static vports to be created. The function create vports |
| 2237 | * based on the information returned from the HBA. |
| 2238 | **/ |
| 2239 | void |
| 2240 | lpfc_create_static_vport(struct lpfc_hba *phba) |
| 2241 | { |
| 2242 | LPFC_MBOXQ_t *pmb = NULL; |
| 2243 | MAILBOX_t *mb; |
| 2244 | struct static_vport_info *vport_info; |
| 2245 | int rc, i; |
| 2246 | struct fc_vport_identifiers vport_id; |
| 2247 | struct fc_vport *new_fc_vport; |
| 2248 | struct Scsi_Host *shost; |
| 2249 | struct lpfc_vport *vport; |
| 2250 | uint16_t offset = 0; |
| 2251 | uint8_t *vport_buff; |
| 2252 | |
| 2253 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2254 | if (!pmb) { |
| 2255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2256 | "0542 lpfc_create_static_vport failed to" |
| 2257 | " allocate mailbox memory\n"); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | mb = &pmb->u.mb; |
| 2262 | |
| 2263 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); |
| 2264 | if (!vport_info) { |
| 2265 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2266 | "0543 lpfc_create_static_vport failed to" |
| 2267 | " allocate vport_info\n"); |
| 2268 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2269 | return; |
| 2270 | } |
| 2271 | |
| 2272 | vport_buff = (uint8_t *) vport_info; |
| 2273 | do { |
| 2274 | lpfc_dump_static_vport(phba, pmb, offset); |
| 2275 | pmb->vport = phba->pport; |
| 2276 | rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO); |
| 2277 | |
| 2278 | if ((rc != MBX_SUCCESS) || mb->mbxStatus) { |
| 2279 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2280 | "0544 lpfc_create_static_vport failed to" |
| 2281 | " issue dump mailbox command ret 0x%x " |
| 2282 | "status 0x%x\n", |
| 2283 | rc, mb->mbxStatus); |
| 2284 | goto out; |
| 2285 | } |
| 2286 | |
| 2287 | if (mb->un.varDmp.word_cnt > |
| 2288 | sizeof(struct static_vport_info) - offset) |
| 2289 | mb->un.varDmp.word_cnt = |
| 2290 | sizeof(struct static_vport_info) - offset; |
| 2291 | |
| 2292 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 2293 | vport_buff + offset, |
| 2294 | mb->un.varDmp.word_cnt); |
| 2295 | offset += mb->un.varDmp.word_cnt; |
| 2296 | |
| 2297 | } while (mb->un.varDmp.word_cnt && |
| 2298 | offset < sizeof(struct static_vport_info)); |
| 2299 | |
| 2300 | |
| 2301 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || |
| 2302 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) |
| 2303 | != VPORT_INFO_REV)) { |
| 2304 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2305 | "0545 lpfc_create_static_vport bad" |
| 2306 | " information header 0x%x 0x%x\n", |
| 2307 | le32_to_cpu(vport_info->signature), |
| 2308 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); |
| 2309 | |
| 2310 | goto out; |
| 2311 | } |
| 2312 | |
| 2313 | shost = lpfc_shost_from_vport(phba->pport); |
| 2314 | |
| 2315 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { |
| 2316 | memset(&vport_id, 0, sizeof(vport_id)); |
| 2317 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); |
| 2318 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); |
| 2319 | if (!vport_id.port_name || !vport_id.node_name) |
| 2320 | continue; |
| 2321 | |
| 2322 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 2323 | vport_id.vport_type = FC_PORTTYPE_NPIV; |
| 2324 | vport_id.disable = false; |
| 2325 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); |
| 2326 | |
| 2327 | if (!new_fc_vport) { |
| 2328 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2329 | "0546 lpfc_create_static_vport failed to" |
| 2330 | " create vport \n"); |
| 2331 | continue; |
| 2332 | } |
| 2333 | |
| 2334 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; |
| 2335 | vport->vport_flag |= STATIC_VPORT; |
| 2336 | } |
| 2337 | |
| 2338 | out: |
| 2339 | /* |
| 2340 | * If this is timed out command, setting NULL to context2 tell SLI |
| 2341 | * layer not to use this buffer. |
| 2342 | */ |
| 2343 | spin_lock_irq(&phba->hbalock); |
| 2344 | pmb->context2 = NULL; |
| 2345 | spin_unlock_irq(&phba->hbalock); |
| 2346 | kfree(vport_info); |
| 2347 | if (rc != MBX_TIMEOUT) |
| 2348 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2349 | |
| 2350 | return; |
| 2351 | } |
| 2352 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | /* |
| 2354 | * This routine handles processing a Fabric REG_LOGIN mailbox |
| 2355 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2356 | * as the completion routine when the command is |
| 2357 | * handed off to the SLI layer. |
| 2358 | */ |
| 2359 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2362 | struct lpfc_vport *vport = pmb->vport; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2363 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2365 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2367 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2368 | pmb->context1 = NULL; |
| 2369 | pmb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | if (mb->mbxStatus) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2371 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 2372 | "0258 Register Fabric login error: 0x%x\n", |
| 2373 | mb->mbxStatus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2375 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2376 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2378 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2379 | /* FLOGI failed, use loop map to make discovery list */ |
| 2380 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2382 | /* Start discovery */ |
| 2383 | lpfc_disc_start(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2384 | /* Decrement the reference count to ndlp after the |
| 2385 | * reference to the ndlp are done. |
| 2386 | */ |
| 2387 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | return; |
| 2389 | } |
| 2390 | |
| 2391 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2392 | /* Decrement the reference count to ndlp after the reference |
| 2393 | * to the ndlp are done. |
| 2394 | */ |
| 2395 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | return; |
| 2397 | } |
| 2398 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2400 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2402 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2405 | lpfc_start_fdiscs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2406 | lpfc_do_scr_ns_plogi(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2410 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2411 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2412 | |
| 2413 | /* Drop the reference count from the mbox at the end after |
| 2414 | * all the current reference to the ndlp have been done. |
| 2415 | */ |
| 2416 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | return; |
| 2418 | } |
| 2419 | |
| 2420 | /* |
| 2421 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 2422 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 2423 | * as the completion routine when the command is |
| 2424 | * handed off to the SLI layer. |
| 2425 | */ |
| 2426 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2427 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2429 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2430 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2431 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2432 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | |
| 2434 | if (mb->mbxStatus) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2435 | out: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2436 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2437 | "0260 Register NameServer error: 0x%x\n", |
| 2438 | mb->mbxStatus); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2439 | /* decrement the node reference count held for this |
| 2440 | * callback function. |
| 2441 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2442 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2444 | kfree(mp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2445 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2446 | |
| 2447 | /* If no other thread is using the ndlp, free it */ |
| 2448 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2450 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2451 | /* |
| 2452 | * RegLogin failed, use loop map to make discovery |
| 2453 | * list |
| 2454 | */ |
| 2455 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2457 | /* Start discovery */ |
| 2458 | lpfc_disc_start(vport); |
| 2459 | return; |
| 2460 | } |
| 2461 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | return; |
| 2463 | } |
| 2464 | |
| 2465 | pmb->context1 = NULL; |
| 2466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2468 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2472 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2473 | /* Link up discovery requires Fabric registration. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2474 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */ |
| 2475 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
| 2476 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); |
| 2477 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); |
| 2478 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); |
| 2479 | |
| 2480 | /* Issue SCR just before NameServer GID_FT Query */ |
| 2481 | lpfc_issue_els_scr(vport, SCR_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 | } |
| 2483 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | /* Good status, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2486 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | /* Cannot issue NameServer Query, so finish up discovery */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2488 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2489 | } |
| 2490 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2491 | /* decrement the node reference count held for this |
| 2492 | * callback function. |
| 2493 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2494 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2496 | kfree(mp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2497 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | |
| 2499 | return; |
| 2500 | } |
| 2501 | |
| 2502 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2503 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2505 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2506 | struct fc_rport *rport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | struct lpfc_rport_data *rdata; |
| 2508 | struct fc_rport_identifiers rport_ids; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2509 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | |
| 2511 | /* Remote port has reappeared. Re-register w/ FC transport */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 2512 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| 2513 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | rport_ids.port_id = ndlp->nlp_DID; |
| 2515 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2517 | /* |
| 2518 | * We leave our node pointer in rport->dd_data when we unregister a |
| 2519 | * FCP target port. But fc_remote_port_add zeros the space to which |
| 2520 | * rport->dd_data points. So, if we're reusing a previously |
| 2521 | * registered port, drop the reference that we took the last time we |
| 2522 | * registered the port. |
| 2523 | */ |
| 2524 | if (ndlp->rport && ndlp->rport->dd_data && |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2525 | ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2526 | lpfc_nlp_put(ndlp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2527 | |
| 2528 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
| 2529 | "rport add: did:x%x flg:x%x type x%x", |
| 2530 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 2531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2532 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2533 | if (!rport || !get_device(&rport->dev)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
| 2535 | "Warning: fc_remote_port_add failed\n"); |
| 2536 | return; |
| 2537 | } |
| 2538 | |
| 2539 | /* initialize static port data */ |
| 2540 | rport->maxframe_size = ndlp->nlp_maxframe; |
| 2541 | rport->supported_classes = ndlp->nlp_class_sup; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | rdata = rport->dd_data; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2543 | rdata->pnode = lpfc_nlp_get(ndlp); |
James.Smart@Emulex.Com | 23dc04f | 2005-11-28 11:41:44 -0500 | [diff] [blame] | 2544 | |
| 2545 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 2546 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 2547 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
| 2548 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2549 | |
| 2550 | |
| 2551 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
| 2552 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 2553 | |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 2554 | if ((rport->scsi_target_id != -1) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 2556 | ndlp->nlp_sid = rport->scsi_target_id; |
| 2557 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2558 | return; |
| 2559 | } |
| 2560 | |
| 2561 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2562 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2563 | { |
| 2564 | struct fc_rport *rport = ndlp->rport; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2565 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2566 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
| 2567 | "rport delete: did:x%x flg:x%x type x%x", |
| 2568 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 2569 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2570 | fc_remote_port_delete(rport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | |
| 2572 | return; |
| 2573 | } |
| 2574 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2575 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2576 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2577 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2578 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2579 | |
| 2580 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2581 | switch (state) { |
| 2582 | case NLP_STE_UNUSED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2583 | vport->fc_unused_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2584 | break; |
| 2585 | case NLP_STE_PLOGI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2586 | vport->fc_plogi_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2587 | break; |
| 2588 | case NLP_STE_ADISC_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | vport->fc_adisc_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2590 | break; |
| 2591 | case NLP_STE_REG_LOGIN_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2592 | vport->fc_reglogin_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2593 | break; |
| 2594 | case NLP_STE_PRLI_ISSUE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | vport->fc_prli_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2596 | break; |
| 2597 | case NLP_STE_UNMAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | vport->fc_unmap_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2599 | break; |
| 2600 | case NLP_STE_MAPPED_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2601 | vport->fc_map_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2602 | break; |
| 2603 | case NLP_STE_NPR_NODE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | vport->fc_npr_cnt += count; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2605 | break; |
| 2606 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2607 | spin_unlock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2608 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 2609 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2610 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2611 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2612 | int old_state, int new_state) |
| 2613 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2614 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2615 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2616 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
| 2617 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
| 2618 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 2619 | ndlp->nlp_type |= NLP_FC_NODE; |
| 2620 | } |
| 2621 | if (new_state == NLP_STE_MAPPED_NODE) |
| 2622 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
| 2623 | if (new_state == NLP_STE_NPR_NODE) |
| 2624 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2626 | /* Transport interface */ |
| 2627 | if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE || |
| 2628 | old_state == NLP_STE_UNMAPPED_NODE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2629 | vport->phba->nport_event_cnt++; |
| 2630 | lpfc_unregister_remote_port(ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2633 | if (new_state == NLP_STE_MAPPED_NODE || |
| 2634 | new_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | vport->phba->nport_event_cnt++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2636 | /* |
| 2637 | * Tell the fc transport about the port, if we haven't |
| 2638 | * already. If we have, and it's a scsi entity, be |
| 2639 | * sure to unblock any attached scsi devices |
| 2640 | */ |
| 2641 | lpfc_register_remote_port(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2642 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2643 | if ((new_state == NLP_STE_MAPPED_NODE) && |
| 2644 | (vport->stat_data_enabled)) { |
| 2645 | /* |
| 2646 | * A new target is discovered, if there is no buffer for |
| 2647 | * statistical data collection allocate buffer. |
| 2648 | */ |
| 2649 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 2650 | sizeof(struct lpfc_scsicmd_bkt), |
| 2651 | GFP_KERNEL); |
| 2652 | |
| 2653 | if (!ndlp->lat_data) |
| 2654 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 2655 | "0286 lpfc_nlp_state_cleanup failed to " |
| 2656 | "allocate statistical data buffer DID " |
| 2657 | "0x%x\n", ndlp->nlp_DID); |
| 2658 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2659 | /* |
| 2660 | * if we added to Mapped list, but the remote port |
| 2661 | * registration failed or assigned a target id outside |
| 2662 | * our presentable range - move the node to the |
| 2663 | * Unmapped List |
| 2664 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2665 | if (new_state == NLP_STE_MAPPED_NODE && |
| 2666 | (!ndlp->rport || |
| 2667 | ndlp->rport->scsi_target_id == -1 || |
| 2668 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | spin_lock_irq(shost->host_lock); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2670 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | spin_unlock_irq(shost->host_lock); |
| 2672 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2674 | } |
| 2675 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2676 | static char * |
| 2677 | lpfc_nlp_state_name(char *buffer, size_t size, int state) |
| 2678 | { |
| 2679 | static char *states[] = { |
| 2680 | [NLP_STE_UNUSED_NODE] = "UNUSED", |
| 2681 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", |
| 2682 | [NLP_STE_ADISC_ISSUE] = "ADISC", |
| 2683 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", |
| 2684 | [NLP_STE_PRLI_ISSUE] = "PRLI", |
| 2685 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
| 2686 | [NLP_STE_MAPPED_NODE] = "MAPPED", |
| 2687 | [NLP_STE_NPR_NODE] = "NPR", |
| 2688 | }; |
| 2689 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2690 | if (state < NLP_STE_MAX_STATE && states[state]) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2691 | strlcpy(buffer, states[state], size); |
| 2692 | else |
| 2693 | snprintf(buffer, size, "unknown (%d)", state); |
| 2694 | return buffer; |
| 2695 | } |
| 2696 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2697 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2699 | int state) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2700 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2701 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2702 | int old_state = ndlp->nlp_state; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2703 | char name1[16], name2[16]; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2704 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2705 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 2706 | "0904 NPort state transition x%06x, %s -> %s\n", |
| 2707 | ndlp->nlp_DID, |
| 2708 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), |
| 2709 | lpfc_nlp_state_name(name2, sizeof(name2), state)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2710 | |
| 2711 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 2712 | "node statechg did:x%x old:%d ste:%d", |
| 2713 | ndlp->nlp_DID, old_state, state); |
| 2714 | |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2715 | if (old_state == NLP_STE_NPR_NODE && |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2716 | state != NLP_STE_NPR_NODE) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2717 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2718 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
| 2719 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
| 2720 | ndlp->nlp_type &= ~NLP_FC_NODE; |
| 2721 | } |
| 2722 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2723 | if (list_empty(&ndlp->nlp_listp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | spin_lock_irq(shost->host_lock); |
| 2725 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 2726 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2727 | } else if (old_state) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2728 | lpfc_nlp_counters(vport, old_state, -1); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2729 | |
| 2730 | ndlp->nlp_state = state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | lpfc_nlp_counters(vport, state, 1); |
| 2732 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2736 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2737 | { |
| 2738 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2739 | |
| 2740 | if (list_empty(&ndlp->nlp_listp)) { |
| 2741 | spin_lock_irq(shost->host_lock); |
| 2742 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); |
| 2743 | spin_unlock_irq(shost->host_lock); |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2748 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2749 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2750 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2751 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2752 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2753 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 2755 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2756 | list_del_init(&ndlp->nlp_listp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2757 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2758 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2759 | NLP_STE_UNUSED_NODE); |
| 2760 | } |
| 2761 | |
Adrian Bunk | 4d9db01 | 2008-02-14 23:24:02 +0200 | [diff] [blame] | 2762 | static void |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2763 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2764 | { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2765 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2766 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
| 2767 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
| 2768 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
| 2769 | NLP_STE_UNUSED_NODE); |
| 2770 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2772 | * lpfc_initialize_node - Initialize all fields of node object |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2773 | * @vport: Pointer to Virtual Port object. |
| 2774 | * @ndlp: Pointer to FC node object. |
| 2775 | * @did: FC_ID of the node. |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2776 | * |
| 2777 | * This function is always called when node object need to be initialized. |
| 2778 | * It initializes all the fields of the node object. Although the reference |
| 2779 | * to phba from @ndlp can be obtained indirectly through it's reference to |
| 2780 | * @vport, a direct reference to phba is taken here by @ndlp. This is due |
| 2781 | * to the life-span of the @ndlp might go beyond the existence of @vport as |
| 2782 | * the final release of ndlp is determined by its reference count. And, the |
| 2783 | * operation on @ndlp needs the reference to phba. |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2784 | **/ |
| 2785 | static inline void |
| 2786 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2787 | uint32_t did) |
| 2788 | { |
| 2789 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
| 2790 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); |
| 2791 | init_timer(&ndlp->nlp_delayfunc); |
| 2792 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; |
| 2793 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; |
| 2794 | ndlp->nlp_DID = did; |
| 2795 | ndlp->vport = vport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2796 | ndlp->phba = vport->phba; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2797 | ndlp->nlp_sid = NLP_NO_SID; |
| 2798 | kref_init(&ndlp->kref); |
| 2799 | NLP_INT_NODE_ACT(ndlp); |
| 2800 | atomic_set(&ndlp->cmd_pending, 0); |
| 2801 | ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; |
| 2802 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2803 | |
| 2804 | struct lpfc_nodelist * |
| 2805 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2806 | int state) |
| 2807 | { |
| 2808 | struct lpfc_hba *phba = vport->phba; |
| 2809 | uint32_t did; |
| 2810 | unsigned long flags; |
| 2811 | |
| 2812 | if (!ndlp) |
| 2813 | return NULL; |
| 2814 | |
| 2815 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 2816 | /* The ndlp should not be in memory free mode */ |
| 2817 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2818 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 2819 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2820 | "0277 lpfc_enable_node: ndlp:x%p " |
| 2821 | "usgmap:x%x refcnt:%d\n", |
| 2822 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2823 | atomic_read(&ndlp->kref.refcount)); |
| 2824 | return NULL; |
| 2825 | } |
| 2826 | /* The ndlp should not already be in active mode */ |
| 2827 | if (NLP_CHK_NODE_ACT(ndlp)) { |
| 2828 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 2829 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 2830 | "0278 lpfc_enable_node: ndlp:x%p " |
| 2831 | "usgmap:x%x refcnt:%d\n", |
| 2832 | (void *)ndlp, ndlp->nlp_usg_map, |
| 2833 | atomic_read(&ndlp->kref.refcount)); |
| 2834 | return NULL; |
| 2835 | } |
| 2836 | |
| 2837 | /* Keep the original DID */ |
| 2838 | did = ndlp->nlp_DID; |
| 2839 | |
| 2840 | /* re-initialize ndlp except of ndlp linked list pointer */ |
| 2841 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
| 2842 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2843 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2844 | |
| 2845 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 2846 | |
| 2847 | if (state != NLP_STE_UNUSED_NODE) |
| 2848 | lpfc_nlp_set_state(vport, ndlp, state); |
| 2849 | |
| 2850 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 2851 | "node enable: did:x%x", |
| 2852 | ndlp->nlp_DID, 0, 0); |
| 2853 | return ndlp; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2858 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2859 | /* |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2860 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2861 | * be used if we wish to issue the "last" lpfc_nlp_put() to remove |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2862 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
| 2863 | * until ALL other outstanding threads have completed. We check |
| 2864 | * that the ndlp not already in the UNUSED state before we proceed. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2865 | */ |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2866 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2867 | return; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2868 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2869 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2870 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | /* |
| 2874 | * Start / ReStart rescue timer for Discovery / RSCN handling |
| 2875 | */ |
| 2876 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | lpfc_set_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2880 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | uint32_t tmo; |
| 2882 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2884 | /* For FAN, timeout should be greater than edtov */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2885 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
| 2886 | } else { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2887 | /* Normal discovery timeout should be > than ELS/CT timeout |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2888 | * FC spec states we need 3 * ratov for CT requests |
| 2889 | */ |
| 2890 | tmo = ((phba->fc_ratov * 3) + 3); |
| 2891 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2892 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2893 | |
| 2894 | if (!timer_pending(&vport->fc_disctmo)) { |
| 2895 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2896 | "set disc timer: tmo:x%x state:x%x flg:x%x", |
| 2897 | tmo, vport->port_state, vport->fc_flag); |
| 2898 | } |
| 2899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo); |
| 2901 | spin_lock_irq(shost->host_lock); |
| 2902 | vport->fc_flag |= FC_DISC_TMO; |
| 2903 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | |
| 2905 | /* Start Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2906 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2907 | "0247 Start Discovery Timer state x%x " |
| 2908 | "Data: x%x x%lx x%x x%x\n", |
| 2909 | vport->port_state, tmo, |
| 2910 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, |
| 2911 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | |
| 2913 | return; |
| 2914 | } |
| 2915 | |
| 2916 | /* |
| 2917 | * Cancel rescue timer for Discovery / RSCN handling |
| 2918 | */ |
| 2919 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | lpfc_can_disctmo(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2922 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2923 | unsigned long iflags; |
| 2924 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2925 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2926 | "can disc timer: state:x%x rtry:x%x flg:x%x", |
| 2927 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 2928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | /* Turn off discovery timer if its running */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2930 | if (vport->fc_flag & FC_DISC_TMO) { |
| 2931 | spin_lock_irqsave(shost->host_lock, iflags); |
| 2932 | vport->fc_flag &= ~FC_DISC_TMO; |
| 2933 | spin_unlock_irqrestore(shost->host_lock, iflags); |
| 2934 | del_timer_sync(&vport->fc_disctmo); |
| 2935 | spin_lock_irqsave(&vport->work_port_lock, iflags); |
| 2936 | vport->work_port_events &= ~WORKER_DISC_TMO; |
| 2937 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | /* Cancel Discovery Timer state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2941 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2942 | "0248 Cancel Discovery Timer state x%x " |
| 2943 | "Data: x%x x%x x%x\n", |
| 2944 | vport->port_state, vport->fc_flag, |
| 2945 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2946 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /* |
| 2950 | * Check specified ring for outstanding IOCB on the SLI queue |
| 2951 | * Return true if iocb matches the specified nport |
| 2952 | */ |
| 2953 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2954 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
| 2955 | struct lpfc_sli_ring *pring, |
| 2956 | struct lpfc_iocbq *iocb, |
| 2957 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2958 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2959 | struct lpfc_sli *psli = &phba->sli; |
| 2960 | IOCB_t *icmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2961 | struct lpfc_vport *vport = ndlp->vport; |
| 2962 | |
| 2963 | if (iocb->vport != vport) |
| 2964 | return 0; |
| 2965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | if (pring->ringno == LPFC_ELS_RING) { |
| 2967 | switch (icmd->ulpCommand) { |
| 2968 | case CMD_GEN_REQUEST64_CR: |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2969 | if (iocb->context_un.ndlp == ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2970 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | case CMD_ELS_REQUEST64_CR: |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 2972 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
| 2973 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | case CMD_XMIT_ELS_RSP64_CX: |
| 2975 | if (iocb->context1 == (uint8_t *) ndlp) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | } |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2978 | } else if (pring->ringno == psli->extra_ring) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | |
| 2980 | } else if (pring->ringno == psli->fcp_ring) { |
| 2981 | /* Skip match check if waiting to relogin to FCP target */ |
| 2982 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2984 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | } |
| 2986 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2987 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | } |
| 2989 | } else if (pring->ringno == psli->next_ring) { |
| 2990 | |
| 2991 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2992 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | /* |
| 2996 | * Free resources / clean up outstanding I/Os |
| 2997 | * associated with nlp_rpi in the LPFC_NODELIST entry. |
| 2998 | */ |
| 2999 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3000 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3002 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | struct lpfc_sli *psli; |
| 3004 | struct lpfc_sli_ring *pring; |
| 3005 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | uint32_t rpi, i; |
| 3007 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3008 | lpfc_fabric_abort_nport(ndlp); |
| 3009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | /* |
| 3011 | * Everything that matches on txcmplq will be returned |
| 3012 | * by firmware with a no rpi error. |
| 3013 | */ |
| 3014 | psli = &phba->sli; |
| 3015 | rpi = ndlp->nlp_rpi; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3016 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | /* Now process each ring */ |
| 3018 | for (i = 0; i < psli->num_rings; i++) { |
| 3019 | pring = &psli->ring[i]; |
| 3020 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3021 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3023 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3024 | /* |
| 3025 | * Check to see if iocb matches the nport we are |
| 3026 | * looking for |
| 3027 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3028 | if ((lpfc_check_sli_ndlp(phba, pring, iocb, |
| 3029 | ndlp))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | /* It matches, so deque and call compl |
| 3031 | with an error */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3032 | list_move_tail(&iocb->list, |
| 3033 | &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | } |
| 3036 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3037 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | } |
| 3039 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3040 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3041 | /* Cancel all the IOCBs from the completions list */ |
| 3042 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3043 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3044 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3045 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | /* |
| 3049 | * Free rpi associated with LPFC_NODELIST entry. |
| 3050 | * This routine is called from lpfc_freenode(), when we are removing |
| 3051 | * a LPFC_NODELIST entry. It is also called if the driver initiates a |
| 3052 | * LOGO that completes successfully, and we are waiting to PLOGI back |
| 3053 | * to the remote NPort. In addition, it is called after we receive |
| 3054 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and |
| 3055 | * we are waiting to PLOGI back to the remote NPort. |
| 3056 | */ |
| 3057 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3058 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3059 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3060 | struct lpfc_hba *phba = vport->phba; |
| 3061 | LPFC_MBOXQ_t *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | int rc; |
| 3063 | |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3064 | if (ndlp->nlp_flag & NLP_RPI_VALID) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3065 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3066 | if (mbox) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3068 | mbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3070 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | if (rc == MBX_NOT_FINISHED) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3072 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3074 | lpfc_no_rpi(phba, ndlp); |
| 3075 | ndlp->nlp_rpi = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3076 | ndlp->nlp_flag &= ~NLP_RPI_VALID; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 3077 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | return 1; |
| 3079 | } |
| 3080 | return 0; |
| 3081 | } |
| 3082 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3083 | void |
| 3084 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) |
| 3085 | { |
| 3086 | struct lpfc_hba *phba = vport->phba; |
| 3087 | LPFC_MBOXQ_t *mbox; |
| 3088 | int rc; |
| 3089 | |
| 3090 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3091 | if (mbox) { |
| 3092 | lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); |
| 3093 | mbox->vport = vport; |
| 3094 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3095 | mbox->context1 = NULL; |
| 3096 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3097 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3098 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3099 | |
| 3100 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
| 3101 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3102 | "1836 Could not issue " |
| 3103 | "unreg_login(all_rpis) status %d\n", rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | void |
| 3108 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) |
| 3109 | { |
| 3110 | struct lpfc_hba *phba = vport->phba; |
| 3111 | LPFC_MBOXQ_t *mbox; |
| 3112 | int rc; |
| 3113 | |
| 3114 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3115 | if (mbox) { |
| 3116 | lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox); |
| 3117 | mbox->vport = vport; |
| 3118 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3119 | mbox->context1 = NULL; |
| 3120 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3121 | if (rc != MBX_TIMEOUT) |
| 3122 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3123 | |
| 3124 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3125 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 3126 | "1815 Could not issue " |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3127 | "unreg_did (default rpis) status %d\n", |
| 3128 | rc); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | /* |
| 3133 | * Free resources associated with LPFC_NODELIST entry |
| 3134 | * so it can be freed. |
| 3135 | */ |
| 3136 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3137 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3138 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3139 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3140 | struct lpfc_hba *phba = vport->phba; |
| 3141 | LPFC_MBOXQ_t *mb, *nextmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | |
| 3144 | /* Cleanup node for NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3145 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3146 | "0900 Cleanup node for NPort x%x " |
| 3147 | "Data: x%x x%x x%x\n", |
| 3148 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3149 | ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3150 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 3151 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3152 | "0280 lpfc_cleanup_node: ndlp:x%p " |
| 3153 | "usgmap:x%x refcnt:%d\n", |
| 3154 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3155 | atomic_read(&ndlp->kref.refcount)); |
| 3156 | lpfc_dequeue_node(vport, ndlp); |
| 3157 | } else { |
| 3158 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, |
| 3159 | "0281 lpfc_cleanup_node: ndlp:x%p " |
| 3160 | "usgmap:x%x refcnt:%d\n", |
| 3161 | (void *)ndlp, ndlp->nlp_usg_map, |
| 3162 | atomic_read(&ndlp->kref.refcount)); |
| 3163 | lpfc_disable_node(vport, ndlp); |
| 3164 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
| 3167 | if ((mb = phba->sli.mbox_active)) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3168 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| 3170 | mb->context2 = NULL; |
| 3171 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3172 | } |
| 3173 | } |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3174 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3175 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3177 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3178 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 3180 | if (mp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | kfree(mp); |
| 3183 | } |
| 3184 | list_del(&mb->list); |
| 3185 | mempool_free(mb, phba->mbox_mem_pool); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3186 | /* We shall not invoke the lpfc_nlp_put to decrement |
| 3187 | * the ndlp reference count as we are in the process |
| 3188 | * of lpfc_nlp_release. |
| 3189 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | } |
| 3191 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3192 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3194 | lpfc_els_abort(phba, ndlp); |
| 3195 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3196 | spin_lock_irq(shost->host_lock); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 3197 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3198 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3200 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | del_timer_sync(&ndlp->nlp_delayfunc); |
| 3202 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3203 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
| 3204 | list_del_init(&ndlp->dev_loss_evt.evt_listp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | lpfc_unreg_rpi(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3208 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | /* |
| 3212 | * Check to see if we can free the nlp back to the freelist. |
| 3213 | * If we are in the middle of using the nlp in the discovery state |
| 3214 | * machine, defer the free till we reach the end of the state machine. |
| 3215 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3216 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3217 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3219 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3220 | struct lpfc_rport_data *rdata; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3221 | LPFC_MBOXQ_t *mbox; |
| 3222 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3224 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3225 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
| 3226 | !(ndlp->nlp_flag & NLP_RPI_VALID)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3227 | /* For this case we need to cleanup the default rpi |
| 3228 | * allocated by the firmware. |
| 3229 | */ |
| 3230 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
| 3231 | != NULL) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3232 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3233 | (uint8_t *) &vport->fc_sparam, mbox, 0); |
| 3234 | if (rc) { |
| 3235 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3236 | } |
| 3237 | else { |
| 3238 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3239 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3240 | mbox->vport = vport; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3241 | mbox->context2 = NULL; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3242 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 3243 | if (rc == MBX_NOT_FINISHED) { |
| 3244 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | lpfc_cleanup_node(vport, ndlp); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3251 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3252 | * We can get here with a non-NULL ndlp->rport because when we |
| 3253 | * unregister a rport we don't break the rport/node linkage. So if we |
| 3254 | * do, make sure we don't leaving any dangling pointers behind. |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3255 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3256 | if (ndlp->rport) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3257 | rdata = ndlp->rport->dd_data; |
| 3258 | rdata->pnode = NULL; |
| 3259 | ndlp->rport = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 3265 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3267 | D_ID mydid, ndlpdid, matchdid; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | |
| 3269 | if (did == Bcast_DID) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3270 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | /* First check for Direct match */ |
| 3273 | if (ndlp->nlp_DID == did) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3274 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | |
| 3276 | /* Next check for area/domain identically equals 0 match */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3277 | mydid.un.word = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3278 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3279 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | matchdid.un.word = did; |
| 3283 | ndlpdid.un.word = ndlp->nlp_DID; |
| 3284 | if (matchdid.un.b.id == ndlpdid.un.b.id) { |
| 3285 | if ((mydid.un.b.domain == matchdid.un.b.domain) && |
| 3286 | (mydid.un.b.area == matchdid.un.b.area)) { |
| 3287 | if ((ndlpdid.un.b.domain == 0) && |
| 3288 | (ndlpdid.un.b.area == 0)) { |
| 3289 | if (ndlpdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3290 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3292 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | matchdid.un.word = ndlp->nlp_DID; |
| 3296 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && |
| 3297 | (mydid.un.b.area == ndlpdid.un.b.area)) { |
| 3298 | if ((matchdid.un.b.domain == 0) && |
| 3299 | (matchdid.un.b.area == 0)) { |
| 3300 | if (matchdid.un.b.id) |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3301 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3305 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | } |
| 3307 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3308 | /* Search for a nodelist entry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3309 | static struct lpfc_nodelist * |
| 3310 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3311 | { |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 3312 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | uint32_t data1; |
| 3314 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3315 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 3316 | if (lpfc_matchdid(vport, ndlp, did)) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3317 | data1 = (((uint32_t) ndlp->nlp_state << 24) | |
| 3318 | ((uint32_t) ndlp->nlp_xri << 16) | |
| 3319 | ((uint32_t) ndlp->nlp_type << 8) | |
| 3320 | ((uint32_t) ndlp->nlp_rpi & 0xff)); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3321 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3322 | "0929 FIND node DID " |
| 3323 | "Data: x%p x%x x%x x%x\n", |
| 3324 | ndlp, ndlp->nlp_DID, |
| 3325 | ndlp->nlp_flag, data1); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3326 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | } |
| 3328 | } |
Jamie Wellnitz | 66a9ed6 | 2006-02-28 22:33:10 -0500 | [diff] [blame] | 3329 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | /* FIND node did <did> NOT FOUND */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3331 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
| 3332 | "0932 FIND node did x%x NOT FOUND.\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | return NULL; |
| 3334 | } |
| 3335 | |
| 3336 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3337 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3342 | spin_lock_irq(shost->host_lock); |
| 3343 | ndlp = __lpfc_findnode_did(vport, did); |
| 3344 | spin_unlock_irq(shost->host_lock); |
| 3345 | return ndlp; |
| 3346 | } |
| 3347 | |
| 3348 | struct lpfc_nodelist * |
| 3349 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) |
| 3350 | { |
| 3351 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3352 | struct lpfc_nodelist *ndlp; |
| 3353 | |
| 3354 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3355 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
| 3357 | lpfc_rscn_payload_check(vport, did) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | return NULL; |
| 3359 | ndlp = (struct lpfc_nodelist *) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | if (!ndlp) |
| 3362 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | lpfc_nlp_init(vport, ndlp, did); |
| 3364 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3365 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3369 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3370 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
| 3371 | if (!ndlp) |
| 3372 | return NULL; |
| 3373 | spin_lock_irq(shost->host_lock); |
| 3374 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 3375 | spin_unlock_irq(shost->host_lock); |
| 3376 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3378 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3379 | if ((vport->fc_flag & FC_RSCN_MODE) && |
| 3380 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | if (lpfc_rscn_payload_check(vport, did)) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3382 | /* If we've already recieved a PLOGI from this NPort |
| 3383 | * we don't need to try to discover it again. |
| 3384 | */ |
| 3385 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) |
| 3386 | return NULL; |
| 3387 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3388 | /* Since this node is marked for discovery, |
| 3389 | * delay timeout is not needed. |
| 3390 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3391 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3392 | spin_lock_irq(shost->host_lock); |
| 3393 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 3394 | spin_unlock_irq(shost->host_lock); |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 3395 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | ndlp = NULL; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3397 | } else { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3398 | /* If we've already recieved a PLOGI from this NPort, |
| 3399 | * or we are already in the process of discovery on it, |
| 3400 | * we don't need to try to discover it again. |
| 3401 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3402 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3403 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 3404 | ndlp->nlp_flag & NLP_RCV_PLOGI) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3406 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3407 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3409 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | } |
| 3411 | return ndlp; |
| 3412 | } |
| 3413 | |
| 3414 | /* Build a list of nodes to discover based on the loopmap */ |
| 3415 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3416 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | int j; |
| 3420 | uint32_t alpa, index; |
| 3421 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3424 | |
| 3425 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | |
| 3428 | /* Check for loop map present or not */ |
| 3429 | if (phba->alpa_map[0]) { |
| 3430 | for (j = 1; j <= phba->alpa_map[0]; j++) { |
| 3431 | alpa = phba->alpa_map[j]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3432 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3434 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | } |
| 3436 | } else { |
| 3437 | /* No alpamap, so try all alpa's */ |
| 3438 | for (j = 0; j < FC_MAXLOOP; j++) { |
| 3439 | /* If cfg_scan_down is set, start from highest |
| 3440 | * ALPA (0xef) to lowest (0x1). |
| 3441 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3442 | if (vport->cfg_scan_down) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | index = j; |
| 3444 | else |
| 3445 | index = FC_MAXLOOP - j - 1; |
| 3446 | alpa = lpfcAlpaArray[index]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3447 | if ((vport->fc_myDID & 0xff) == alpa) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3449 | lpfc_setup_disc_node(vport, alpa); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | return; |
| 3453 | } |
| 3454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | LPFC_MBOXQ_t *mbox; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3459 | struct lpfc_sli *psli = &phba->sli; |
| 3460 | struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring]; |
| 3461 | struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring]; |
| 3462 | struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring]; |
| 3463 | int rc; |
| 3464 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3465 | /* |
| 3466 | * if it's not a physical port or if we already send |
| 3467 | * clear_la then don't send it. |
| 3468 | */ |
| 3469 | if ((phba->link_state >= LPFC_CLEAR_LA) || |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3470 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
| 3471 | (phba->sli_rev == LPFC_SLI_REV4)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3472 | return; |
| 3473 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3474 | /* Link up discovery */ |
| 3475 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { |
| 3476 | phba->link_state = LPFC_CLEAR_LA; |
| 3477 | lpfc_clear_la(phba, mbox); |
| 3478 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 3479 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3480 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3481 | if (rc == MBX_NOT_FINISHED) { |
| 3482 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3483 | lpfc_disc_flush_list(vport); |
| 3484 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3485 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3486 | next_ring->flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3487 | phba->link_state = LPFC_HBA_ERROR; |
| 3488 | } |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | /* Reg_vpi to tell firmware to resume normal operations */ |
| 3493 | void |
| 3494 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 3495 | { |
| 3496 | LPFC_MBOXQ_t *regvpimbox; |
| 3497 | |
| 3498 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3499 | if (regvpimbox) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3500 | lpfc_reg_vpi(vport, regvpimbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3501 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
| 3502 | regvpimbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3503 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3504 | == MBX_NOT_FINISHED) { |
| 3505 | mempool_free(regvpimbox, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | /* Start Link up / RSCN discovery on NPR nodes */ |
| 3511 | void |
| 3512 | lpfc_disc_start(struct lpfc_vport *vport) |
| 3513 | { |
| 3514 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3515 | struct lpfc_hba *phba = vport->phba; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3516 | uint32_t num_sent; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | uint32_t clear_la_pending; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3518 | int did_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3520 | if (!lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3521 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | |
| 3523 | if (phba->link_state == LPFC_CLEAR_LA) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | clear_la_pending = 1; |
| 3525 | else |
| 3526 | clear_la_pending = 0; |
| 3527 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3528 | if (vport->port_state < LPFC_VPORT_READY) |
| 3529 | vport->port_state = LPFC_DISC_AUTH; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3531 | lpfc_set_disctmo(vport); |
| 3532 | |
| 3533 | if (vport->fc_prevDID == vport->fc_myDID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | did_changed = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3535 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | did_changed = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | |
| 3538 | vport->fc_prevDID = vport->fc_myDID; |
| 3539 | vport->num_disc_nodes = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | |
| 3541 | /* Start Discovery state <hba_state> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3542 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3543 | "0202 Start Discovery hba state x%x " |
| 3544 | "Data: x%x x%x x%x\n", |
| 3545 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, |
| 3546 | vport->fc_adisc_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | |
| 3548 | /* First do ADISCs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3549 | num_sent = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | |
| 3551 | if (num_sent) |
| 3552 | return; |
| 3553 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3554 | /* |
| 3555 | * For SLI3, cmpl_reg_vpi will set port_state to READY, and |
| 3556 | * continue discovery. |
| 3557 | */ |
| 3558 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3559 | !(vport->fc_flag & FC_PT2PT) && |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3560 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 3561 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | lpfc_issue_reg_vpi(phba, vport); |
| 3563 | return; |
| 3564 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3565 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3566 | /* |
| 3567 | * For SLI2, we need to set port_state to READY and continue |
| 3568 | * discovery. |
| 3569 | */ |
| 3570 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
| 3571 | /* If we get here, there is nothing to ADISC */ |
| 3572 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 3573 | lpfc_issue_clear_la(phba, vport); |
| 3574 | |
| 3575 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | vport->num_disc_nodes = 0; |
| 3577 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 3578 | if (vport->fc_npr_cnt) |
| 3579 | lpfc_els_disc_plogi(vport); |
| 3580 | |
| 3581 | if (!vport->num_disc_nodes) { |
| 3582 | spin_lock_irq(shost->host_lock); |
| 3583 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 3584 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3585 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | } |
| 3587 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3588 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | } else { |
| 3590 | /* Next do PLOGIs - if any */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3591 | num_sent = lpfc_els_disc_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | |
| 3593 | if (num_sent) |
| 3594 | return; |
| 3595 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3596 | if (vport->fc_flag & FC_RSCN_MODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | /* Check to see if more RSCNs came in while we |
| 3598 | * were processing this one. |
| 3599 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3600 | if ((vport->fc_rscn_id_cnt == 0) && |
| 3601 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { |
| 3602 | spin_lock_irq(shost->host_lock); |
| 3603 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 3604 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3605 | lpfc_can_disctmo(vport); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3606 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3607 | lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | } |
| 3609 | } |
| 3610 | return; |
| 3611 | } |
| 3612 | |
| 3613 | /* |
| 3614 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS |
| 3615 | * ring the match the sppecified nodelist. |
| 3616 | */ |
| 3617 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3618 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3620 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | struct lpfc_sli *psli; |
| 3622 | IOCB_t *icmd; |
| 3623 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3624 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | |
| 3626 | psli = &phba->sli; |
| 3627 | pring = &psli->ring[LPFC_ELS_RING]; |
| 3628 | |
| 3629 | /* Error matching iocb on txq or txcmplq |
| 3630 | * First check the txq. |
| 3631 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3632 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 3634 | if (iocb->context1 != ndlp) { |
| 3635 | continue; |
| 3636 | } |
| 3637 | icmd = &iocb->iocb; |
| 3638 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || |
| 3639 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { |
| 3640 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3641 | list_move_tail(&iocb->list, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | /* Next check the txcmplq */ |
| 3647 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 3648 | if (iocb->context1 != ndlp) { |
| 3649 | continue; |
| 3650 | } |
| 3651 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
| 3653 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3654 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | } |
| 3656 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3658 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3659 | /* Cancel all the IOCBs from the completions list */ |
| 3660 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3661 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | } |
| 3663 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3664 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3665 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | { |
| 3667 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3668 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3670 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
| 3671 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3672 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3673 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3674 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3675 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
| 3676 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { |
| 3677 | lpfc_free_tx(phba, ndlp); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | } |
| 3680 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | } |
| 3682 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3683 | void |
| 3684 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) |
| 3685 | { |
| 3686 | lpfc_els_flush_rscn(vport); |
| 3687 | lpfc_els_flush_cmd(vport); |
| 3688 | lpfc_disc_flush_list(vport); |
| 3689 | } |
| 3690 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | /*****************************************************************************/ |
| 3692 | /* |
| 3693 | * NAME: lpfc_disc_timeout |
| 3694 | * |
| 3695 | * FUNCTION: Fibre Channel driver discovery timeout routine. |
| 3696 | * |
| 3697 | * EXECUTION ENVIRONMENT: interrupt only |
| 3698 | * |
| 3699 | * CALLED FROM: |
| 3700 | * Timer function |
| 3701 | * |
| 3702 | * RETURNS: |
| 3703 | * none |
| 3704 | */ |
| 3705 | /*****************************************************************************/ |
| 3706 | void |
| 3707 | lpfc_disc_timeout(unsigned long ptr) |
| 3708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 3710 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3711 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | unsigned long flags = 0; |
| 3713 | |
| 3714 | if (unlikely(!phba)) |
| 3715 | return; |
| 3716 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3717 | spin_lock_irqsave(&vport->work_port_lock, flags); |
| 3718 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; |
| 3719 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3720 | vport->work_port_events |= WORKER_DISC_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3721 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3722 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3723 | if (!tmo_posted) |
| 3724 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | return; |
| 3726 | } |
| 3727 | |
| 3728 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3729 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3731 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3732 | struct lpfc_hba *phba = vport->phba; |
| 3733 | struct lpfc_sli *psli = &phba->sli; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3734 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3735 | LPFC_MBOXQ_t *initlinkmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | int rc, clrlaerr = 0; |
| 3737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3738 | if (!(vport->fc_flag & FC_DISC_TMO)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | return; |
| 3740 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | spin_lock_irq(shost->host_lock); |
| 3742 | vport->fc_flag &= ~FC_DISC_TMO; |
| 3743 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3745 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 3746 | "disc timeout: state:x%x rtry:x%x flg:x%x", |
| 3747 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); |
| 3748 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | switch (vport->port_state) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3750 | |
| 3751 | case LPFC_LOCAL_CFG_LINK: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for |
| 3753 | * FAN |
| 3754 | */ |
| 3755 | /* FAN timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3756 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 3757 | "0221 FAN timeout\n"); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3758 | /* Start discovery by sending FLOGI, clean up old rpis */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3760 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3761 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3762 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3763 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3764 | continue; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3765 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3766 | /* Clean up the ndlp on Fabric connections */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3767 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3768 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3769 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3770 | /* Fail outstanding IO now since device |
| 3771 | * is marked for PLOGI. |
| 3772 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3773 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3774 | } |
| 3775 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3776 | if (vport->port_state != LPFC_FLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3777 | lpfc_initial_flogi(vport); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3778 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3779 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | break; |
| 3781 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3782 | case LPFC_FDISC: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | case LPFC_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | /* Initial FLOGI timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3787 | "0222 Initial %s timeout\n", |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3788 | vport->vpi ? "FDISC" : "FLOGI"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | |
| 3790 | /* Assume no Fabric and go on with discovery. |
| 3791 | * Check for outstanding ELS FLOGI to abort. |
| 3792 | */ |
| 3793 | |
| 3794 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3795 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | |
| 3797 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3798 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | break; |
| 3800 | |
| 3801 | case LPFC_FABRIC_CFG_LINK: |
| 3802 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for |
| 3803 | NameServer login */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3804 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3805 | "0223 Timeout while waiting for " |
| 3806 | "NameServer login\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | /* Next look for NameServer ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3809 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3810 | lpfc_els_abort(phba, ndlp); |
| 3811 | |
| 3812 | /* ReStart discovery */ |
| 3813 | goto restart_disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | |
| 3815 | case LPFC_NS_QRY: |
| 3816 | /* Check for wait for NameServer Rsp timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3817 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3818 | "0224 NameServer Query timeout " |
| 3819 | "Data: x%x x%x\n", |
| 3820 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3822 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
| 3823 | /* Try it one more time */ |
| 3824 | vport->fc_ns_retry++; |
| 3825 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
| 3826 | vport->fc_ns_retry, 0); |
| 3827 | if (rc == 0) |
| 3828 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3830 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3832 | restart_disc: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3833 | /* |
| 3834 | * Discovery is over. |
| 3835 | * set port_state to PORT_READY if SLI2. |
| 3836 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 3837 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3838 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3839 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3840 | lpfc_issue_reg_vpi(phba, vport); |
| 3841 | else { /* NPIV Not enabled */ |
| 3842 | lpfc_issue_clear_la(phba, vport); |
| 3843 | vport->port_state = LPFC_VPORT_READY; |
| 3844 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | /* Setup and issue mailbox INITIALIZE LINK command */ |
| 3848 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3849 | if (!initlinkmbox) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3850 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3851 | "0206 Device Discovery " |
| 3852 | "completion error\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3853 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | break; |
| 3855 | } |
| 3856 | |
| 3857 | lpfc_linkdown(phba); |
| 3858 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, |
| 3859 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3860 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3861 | initlinkmbox->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3862 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3863 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3864 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | if (rc == MBX_NOT_FINISHED) |
| 3866 | mempool_free(initlinkmbox, phba->mbox_mem_pool); |
| 3867 | |
| 3868 | break; |
| 3869 | |
| 3870 | case LPFC_DISC_AUTH: |
| 3871 | /* Node Authentication timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3872 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3873 | "0227 Node Authentication timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3874 | lpfc_disc_flush_list(vport); |
| 3875 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3876 | /* |
| 3877 | * set port_state to PORT_READY if SLI2. |
| 3878 | * cmpl_reg_vpi will set port_state to READY for SLI3. |
| 3879 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3880 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3881 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3882 | lpfc_issue_reg_vpi(phba, vport); |
| 3883 | else { /* NPIV Not enabled */ |
| 3884 | lpfc_issue_clear_la(phba, vport); |
| 3885 | vport->port_state = LPFC_VPORT_READY; |
| 3886 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | } |
| 3888 | break; |
| 3889 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3890 | case LPFC_VPORT_READY: |
| 3891 | if (vport->fc_flag & FC_RSCN_MODE) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3892 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3893 | "0231 RSCN timeout Data: x%x " |
| 3894 | "x%x\n", |
| 3895 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | |
| 3897 | /* Cleanup any outstanding ELS commands */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | lpfc_els_flush_cmd(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3900 | lpfc_els_flush_rscn(vport); |
| 3901 | lpfc_disc_flush_list(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | } |
| 3903 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3904 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3905 | default: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3906 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3907 | "0273 Unexpected discovery timeout, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3908 | "vport State x%x\n", vport->port_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3909 | break; |
| 3910 | } |
| 3911 | |
| 3912 | switch (phba->link_state) { |
| 3913 | case LPFC_CLEAR_LA: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3914 | /* CLEAR LA timeout */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3915 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3916 | "0228 CLEAR LA timeout\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | clrlaerr = 1; |
| 3918 | break; |
| 3919 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3920 | case LPFC_LINK_UP: |
| 3921 | lpfc_issue_clear_la(phba, vport); |
| 3922 | /* Drop thru */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3923 | case LPFC_LINK_UNKNOWN: |
| 3924 | case LPFC_WARM_START: |
| 3925 | case LPFC_INIT_START: |
| 3926 | case LPFC_INIT_MBX_CMDS: |
| 3927 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | case LPFC_HBA_ERROR: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3929 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3930 | "0230 Unexpected timeout, hba link " |
| 3931 | "state x%x\n", phba->link_state); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | clrlaerr = 1; |
| 3933 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3934 | |
| 3935 | case LPFC_HBA_READY: |
| 3936 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | if (clrlaerr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3940 | lpfc_disc_flush_list(vport); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3941 | psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
| 3943 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3944 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | return; |
| 3948 | } |
| 3949 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | /* |
| 3951 | * This routine handles processing a NameServer REG_LOGIN mailbox |
| 3952 | * command upon completion. It is setup in the LPFC_MBOXQ |
| 3953 | * as the completion routine when the command is |
| 3954 | * handed off to the SLI layer. |
| 3955 | */ |
| 3956 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3959 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3960 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3961 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3962 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3963 | |
| 3964 | pmb->context1 = NULL; |
| 3965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | ndlp->nlp_rpi = mb->un.varWords[0]; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3967 | ndlp->nlp_flag |= NLP_RPI_VALID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | /* |
| 3972 | * Start issuing Fabric-Device Management Interface (FDMI) command to |
| 3973 | * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if |
| 3974 | * fdmi-on=2 (supporting RPA/hostnmae) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3977 | if (vport->cfg_fdmi_on == 1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3978 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); |
| 3979 | else |
| 3980 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3982 | /* decrement the node reference count held for this callback |
| 3983 | * function. |
| 3984 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3985 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3987 | kfree(mp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3988 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | |
| 3990 | return; |
| 3991 | } |
| 3992 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3993 | static int |
| 3994 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) |
| 3995 | { |
| 3996 | uint16_t *rpi = param; |
| 3997 | |
| 3998 | return ndlp->nlp_rpi == *rpi; |
| 3999 | } |
| 4000 | |
| 4001 | static int |
| 4002 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) |
| 4003 | { |
| 4004 | return memcmp(&ndlp->nlp_portname, param, |
| 4005 | sizeof(ndlp->nlp_portname)) == 0; |
| 4006 | } |
| 4007 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4008 | static struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | { |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4011 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4014 | if (filter(ndlp, param)) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4015 | return ndlp; |
| 4016 | } |
James.Smart@Emulex.Com | 21568f5 | 2005-10-28 20:29:36 -0400 | [diff] [blame] | 4017 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | } |
| 4019 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4020 | /* |
| 4021 | * 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] | 4022 | * returns the node list element pointer else return NULL. |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4023 | */ |
| 4024 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4025 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4026 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4027 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4028 | } |
| 4029 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4030 | /* |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4031 | * 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] | 4032 | * returns the node element list pointer else return NULL. |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4033 | */ |
| 4034 | struct lpfc_nodelist * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4035 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4036 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4038 | struct lpfc_nodelist *ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4039 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4040 | spin_lock_irq(shost->host_lock); |
| 4041 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); |
| 4042 | spin_unlock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4043 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4044 | } |
| 4045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4048 | uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | { |
| 4050 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4051 | |
| 4052 | lpfc_initialize_node(vport, ndlp, did); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4053 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4054 | |
| 4055 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, |
| 4056 | "node init: did:x%x", |
| 4057 | ndlp->nlp_DID, 0, 0); |
| 4058 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | return; |
| 4060 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4061 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4062 | /* This routine releases all resources associated with a specifc NPort's ndlp |
| 4063 | * and mempool_free's the nodelist. |
| 4064 | */ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 4065 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4066 | lpfc_nlp_release(struct kref *kref) |
| 4067 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4068 | struct lpfc_hba *phba; |
| 4069 | unsigned long flags; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4070 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
| 4071 | kref); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4072 | |
| 4073 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4074 | "node release: did:x%x flg:x%x type:x%x", |
| 4075 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); |
| 4076 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4077 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 4078 | "0279 lpfc_nlp_release: ndlp:x%p " |
| 4079 | "usgmap:x%x refcnt:%d\n", |
| 4080 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4081 | atomic_read(&ndlp->kref.refcount)); |
| 4082 | |
| 4083 | /* remove ndlp from action. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4084 | lpfc_nlp_remove(ndlp->vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4085 | |
| 4086 | /* clear the ndlp active flag for all release cases */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4087 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4088 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4089 | NLP_CLR_NODE_ACT(ndlp); |
| 4090 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4091 | |
| 4092 | /* free ndlp memory for final ndlp release */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4093 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 4094 | kfree(ndlp->lat_data); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4095 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4096 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4097 | } |
| 4098 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4099 | /* This routine bumps the reference count for a ndlp structure to ensure |
| 4100 | * that one discovery thread won't free a ndlp while another discovery thread |
| 4101 | * is using it. |
| 4102 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4103 | struct lpfc_nodelist * |
| 4104 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) |
| 4105 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4106 | struct lpfc_hba *phba; |
| 4107 | unsigned long flags; |
| 4108 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4109 | if (ndlp) { |
| 4110 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4111 | "node get: did:x%x flg:x%x refcnt:x%x", |
| 4112 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4113 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4114 | /* The check of ndlp usage to prevent incrementing the |
| 4115 | * ndlp reference count that is in the process of being |
| 4116 | * released. |
| 4117 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4118 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4119 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4120 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { |
| 4121 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4122 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4123 | "0276 lpfc_nlp_get: ndlp:x%p " |
| 4124 | "usgmap:x%x refcnt:%d\n", |
| 4125 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4126 | atomic_read(&ndlp->kref.refcount)); |
| 4127 | return NULL; |
| 4128 | } else |
| 4129 | kref_get(&ndlp->kref); |
| 4130 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4131 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4132 | return ndlp; |
| 4133 | } |
| 4134 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4135 | /* This routine decrements the reference count for a ndlp structure. If the |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4136 | * count goes to 0, this indicates the the associated nodelist should be |
| 4137 | * freed. Returning 1 indicates the ndlp resource has been released; on the |
| 4138 | * other hand, returning 0 indicates the ndlp resource has not been released |
| 4139 | * yet. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4140 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4141 | int |
| 4142 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) |
| 4143 | { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4144 | struct lpfc_hba *phba; |
| 4145 | unsigned long flags; |
| 4146 | |
| 4147 | if (!ndlp) |
| 4148 | return 1; |
| 4149 | |
| 4150 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4151 | "node put: did:x%x flg:x%x refcnt:x%x", |
| 4152 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4153 | atomic_read(&ndlp->kref.refcount)); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4154 | phba = ndlp->phba; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4155 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 4156 | /* Check the ndlp memory free acknowledge flag to avoid the |
| 4157 | * possible race condition that kref_put got invoked again |
| 4158 | * after previous one has done ndlp memory free. |
| 4159 | */ |
| 4160 | if (NLP_CHK_FREE_ACK(ndlp)) { |
| 4161 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4162 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4163 | "0274 lpfc_nlp_put: ndlp:x%p " |
| 4164 | "usgmap:x%x refcnt:%d\n", |
| 4165 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4166 | atomic_read(&ndlp->kref.refcount)); |
| 4167 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4168 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4169 | /* Check the ndlp inactivate log flag to avoid the possible |
| 4170 | * race condition that kref_put got invoked again after ndlp |
| 4171 | * is already in inactivating state. |
| 4172 | */ |
| 4173 | if (NLP_CHK_IACT_REQ(ndlp)) { |
| 4174 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4175 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, |
| 4176 | "0275 lpfc_nlp_put: ndlp:x%p " |
| 4177 | "usgmap:x%x refcnt:%d\n", |
| 4178 | (void *)ndlp, ndlp->nlp_usg_map, |
| 4179 | atomic_read(&ndlp->kref.refcount)); |
| 4180 | return 1; |
| 4181 | } |
| 4182 | /* For last put, mark the ndlp usage flags to make sure no |
| 4183 | * other kref_get and kref_put on the same ndlp shall get |
| 4184 | * in between the process when the final kref_put has been |
| 4185 | * invoked on this ndlp. |
| 4186 | */ |
| 4187 | if (atomic_read(&ndlp->kref.refcount) == 1) { |
| 4188 | /* Indicate ndlp is put to inactive state. */ |
| 4189 | NLP_SET_IACT_REQ(ndlp); |
| 4190 | /* Acknowledge ndlp memory free has been seen. */ |
| 4191 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 4192 | NLP_SET_FREE_ACK(ndlp); |
| 4193 | } |
| 4194 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 4195 | /* Note, the kref_put returns 1 when decrementing a reference |
| 4196 | * count that was 1, it invokes the release callback function, |
| 4197 | * but it still left the reference count as 1 (not actually |
| 4198 | * performs the last decrementation). Otherwise, it actually |
| 4199 | * decrements the reference count and returns 0. |
| 4200 | */ |
| 4201 | return kref_put(&ndlp->kref, lpfc_nlp_release); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4202 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4203 | |
| 4204 | /* This routine free's the specified nodelist if it is not in use |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4205 | * by any other discovery thread. This routine returns 1 if the |
| 4206 | * ndlp has been freed. A return value of 0 indicates the ndlp is |
| 4207 | * not yet been released. |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4208 | */ |
| 4209 | int |
| 4210 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) |
| 4211 | { |
| 4212 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, |
| 4213 | "node not used: did:x%x flg:x%x refcnt:x%x", |
| 4214 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 4215 | atomic_read(&ndlp->kref.refcount)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4216 | if (atomic_read(&ndlp->kref.refcount) == 1) |
| 4217 | if (lpfc_nlp_put(ndlp)) |
| 4218 | return 1; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4219 | return 0; |
| 4220 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4221 | |
| 4222 | /** |
| 4223 | * lpfc_fcf_inuse - Check if FCF can be unregistered. |
| 4224 | * @phba: Pointer to hba context object. |
| 4225 | * |
| 4226 | * This function iterate through all FC nodes associated |
| 4227 | * will all vports to check if there is any node with |
| 4228 | * fc_rports associated with it. If there is an fc_rport |
| 4229 | * associated with the node, then the node is either in |
| 4230 | * discovered state or its devloss_timer is pending. |
| 4231 | */ |
| 4232 | static int |
| 4233 | lpfc_fcf_inuse(struct lpfc_hba *phba) |
| 4234 | { |
| 4235 | struct lpfc_vport **vports; |
| 4236 | int i, ret = 0; |
| 4237 | struct lpfc_nodelist *ndlp; |
| 4238 | struct Scsi_Host *shost; |
| 4239 | |
| 4240 | vports = lpfc_create_vport_work_array(phba); |
| 4241 | |
| 4242 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4243 | shost = lpfc_shost_from_vport(vports[i]); |
| 4244 | spin_lock_irq(shost->host_lock); |
| 4245 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
| 4246 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && |
| 4247 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { |
| 4248 | ret = 1; |
| 4249 | spin_unlock_irq(shost->host_lock); |
| 4250 | goto out; |
| 4251 | } |
| 4252 | } |
| 4253 | spin_unlock_irq(shost->host_lock); |
| 4254 | } |
| 4255 | out: |
| 4256 | lpfc_destroy_vport_work_array(phba, vports); |
| 4257 | return ret; |
| 4258 | } |
| 4259 | |
| 4260 | /** |
| 4261 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. |
| 4262 | * @phba: Pointer to hba context object. |
| 4263 | * @mboxq: Pointer to mailbox object. |
| 4264 | * |
| 4265 | * This function frees memory associated with the mailbox command. |
| 4266 | */ |
| 4267 | static void |
| 4268 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 4269 | { |
| 4270 | struct lpfc_vport *vport = mboxq->vport; |
| 4271 | |
| 4272 | if (mboxq->u.mb.mbxStatus) { |
| 4273 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4274 | "2555 UNREG_VFI mbxStatus error x%x " |
| 4275 | "HBA state x%x\n", |
| 4276 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 4277 | } |
| 4278 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4279 | return; |
| 4280 | } |
| 4281 | |
| 4282 | /** |
| 4283 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. |
| 4284 | * @phba: Pointer to hba context object. |
| 4285 | * @mboxq: Pointer to mailbox object. |
| 4286 | * |
| 4287 | * This function frees memory associated with the mailbox command. |
| 4288 | */ |
| 4289 | static void |
| 4290 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 4291 | { |
| 4292 | struct lpfc_vport *vport = mboxq->vport; |
| 4293 | |
| 4294 | if (mboxq->u.mb.mbxStatus) { |
| 4295 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4296 | "2550 UNREG_FCFI mbxStatus error x%x " |
| 4297 | "HBA state x%x\n", |
| 4298 | mboxq->u.mb.mbxStatus, vport->port_state); |
| 4299 | } |
| 4300 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4301 | return; |
| 4302 | } |
| 4303 | |
| 4304 | /** |
| 4305 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. |
| 4306 | * @phba: Pointer to hba context object. |
| 4307 | * |
| 4308 | * This function check if there are any connected remote port for the FCF and |
| 4309 | * if all the devices are disconnected, this function unregister FCFI. |
| 4310 | * This function also tries to use another FCF for discovery. |
| 4311 | */ |
| 4312 | void |
| 4313 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) |
| 4314 | { |
| 4315 | LPFC_MBOXQ_t *mbox; |
| 4316 | int rc; |
| 4317 | struct lpfc_vport **vports; |
| 4318 | int i; |
| 4319 | |
| 4320 | spin_lock_irq(&phba->hbalock); |
| 4321 | /* |
| 4322 | * If HBA is not running in FIP mode or |
| 4323 | * If HBA does not support FCoE or |
| 4324 | * If FCF is not registered. |
| 4325 | * do nothing. |
| 4326 | */ |
| 4327 | if (!(phba->hba_flag & HBA_FCOE_SUPPORT) || |
| 4328 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
| 4329 | (phba->cfg_enable_fip == 0)) { |
| 4330 | spin_unlock_irq(&phba->hbalock); |
| 4331 | return; |
| 4332 | } |
| 4333 | spin_unlock_irq(&phba->hbalock); |
| 4334 | |
| 4335 | if (lpfc_fcf_inuse(phba)) |
| 4336 | return; |
| 4337 | |
| 4338 | |
| 4339 | /* Unregister VPIs */ |
| 4340 | vports = lpfc_create_vport_work_array(phba); |
| 4341 | if (vports && |
| 4342 | (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
| 4343 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 4344 | lpfc_mbx_unreg_vpi(vports[i]); |
| 4345 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 4346 | vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED; |
| 4347 | } |
| 4348 | lpfc_destroy_vport_work_array(phba, vports); |
| 4349 | |
| 4350 | /* Unregister VFI */ |
| 4351 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4352 | if (!mbox) { |
| 4353 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4354 | "2556 UNREG_VFI mbox allocation failed" |
| 4355 | "HBA state x%x\n", |
| 4356 | phba->pport->port_state); |
| 4357 | return; |
| 4358 | } |
| 4359 | |
| 4360 | lpfc_unreg_vfi(mbox, phba->pport->vfi); |
| 4361 | mbox->vport = phba->pport; |
| 4362 | mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 4363 | |
| 4364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4365 | if (rc == MBX_NOT_FINISHED) { |
| 4366 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4367 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 4368 | "HBA state x%x\n", |
| 4369 | rc, phba->pport->port_state); |
| 4370 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4371 | return; |
| 4372 | } |
| 4373 | |
| 4374 | /* Unregister FCF */ |
| 4375 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4376 | if (!mbox) { |
| 4377 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4378 | "2551 UNREG_FCFI mbox allocation failed" |
| 4379 | "HBA state x%x\n", |
| 4380 | phba->pport->port_state); |
| 4381 | return; |
| 4382 | } |
| 4383 | |
| 4384 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
| 4385 | mbox->vport = phba->pport; |
| 4386 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; |
| 4387 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 4388 | |
| 4389 | if (rc == MBX_NOT_FINISHED) { |
| 4390 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4391 | "2552 UNREG_FCFI issue mbox failed rc x%x " |
| 4392 | "HBA state x%x\n", |
| 4393 | rc, phba->pport->port_state); |
| 4394 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4395 | return; |
| 4396 | } |
| 4397 | |
| 4398 | spin_lock_irq(&phba->hbalock); |
| 4399 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED | |
| 4400 | FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE | |
| 4401 | FCF_VALID_VLAN); |
| 4402 | spin_unlock_irq(&phba->hbalock); |
| 4403 | |
| 4404 | /* |
| 4405 | * If driver is not unloading, check if there is any other |
| 4406 | * FCF record that can be used for discovery. |
| 4407 | */ |
| 4408 | if ((phba->pport->load_flag & FC_UNLOADING) || |
| 4409 | (phba->link_state < LPFC_LINK_UP)) |
| 4410 | return; |
| 4411 | |
| 4412 | rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST); |
| 4413 | |
| 4414 | if (rc) |
| 4415 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 4416 | "2553 lpfc_unregister_unused_fcf failed to read FCF" |
| 4417 | " record HBA state x%x\n", |
| 4418 | phba->pport->port_state); |
| 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. |
| 4423 | * @phba: Pointer to hba context object. |
| 4424 | * @buff: Buffer containing the FCF connection table as in the config |
| 4425 | * region. |
| 4426 | * This function create driver data structure for the FCF connection |
| 4427 | * record table read from config region 23. |
| 4428 | */ |
| 4429 | static void |
| 4430 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, |
| 4431 | uint8_t *buff) |
| 4432 | { |
| 4433 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 4434 | struct lpfc_fcf_conn_hdr *conn_hdr; |
| 4435 | struct lpfc_fcf_conn_rec *conn_rec; |
| 4436 | uint32_t record_count; |
| 4437 | int i; |
| 4438 | |
| 4439 | /* Free the current connect table */ |
| 4440 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
| 4441 | &phba->fcf_conn_rec_list, list) |
| 4442 | kfree(conn_entry); |
| 4443 | |
| 4444 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; |
| 4445 | record_count = conn_hdr->length * sizeof(uint32_t)/ |
| 4446 | sizeof(struct lpfc_fcf_conn_rec); |
| 4447 | |
| 4448 | conn_rec = (struct lpfc_fcf_conn_rec *) |
| 4449 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); |
| 4450 | |
| 4451 | for (i = 0; i < record_count; i++) { |
| 4452 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) |
| 4453 | continue; |
| 4454 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), |
| 4455 | GFP_KERNEL); |
| 4456 | if (!conn_entry) { |
| 4457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4458 | "2566 Failed to allocate connection" |
| 4459 | " table entry\n"); |
| 4460 | return; |
| 4461 | } |
| 4462 | |
| 4463 | memcpy(&conn_entry->conn_rec, &conn_rec[i], |
| 4464 | sizeof(struct lpfc_fcf_conn_rec)); |
| 4465 | conn_entry->conn_rec.vlan_tag = |
| 4466 | le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF; |
| 4467 | conn_entry->conn_rec.flags = |
| 4468 | le16_to_cpu(conn_entry->conn_rec.flags); |
| 4469 | list_add_tail(&conn_entry->list, |
| 4470 | &phba->fcf_conn_rec_list); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. |
| 4476 | * @phba: Pointer to hba context object. |
| 4477 | * @buff: Buffer containing the FCoE parameter data structure. |
| 4478 | * |
| 4479 | * This function update driver data structure with config |
| 4480 | * parameters read from config region 23. |
| 4481 | */ |
| 4482 | static void |
| 4483 | lpfc_read_fcoe_param(struct lpfc_hba *phba, |
| 4484 | uint8_t *buff) |
| 4485 | { |
| 4486 | struct lpfc_fip_param_hdr *fcoe_param_hdr; |
| 4487 | struct lpfc_fcoe_params *fcoe_param; |
| 4488 | |
| 4489 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) |
| 4490 | buff; |
| 4491 | fcoe_param = (struct lpfc_fcoe_params *) |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame^] | 4492 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4493 | |
| 4494 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || |
| 4495 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) |
| 4496 | return; |
| 4497 | |
| 4498 | if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) == |
| 4499 | FIPP_MODE_ON) |
| 4500 | phba->cfg_enable_fip = 1; |
| 4501 | |
| 4502 | if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) == |
| 4503 | FIPP_MODE_OFF) |
| 4504 | phba->cfg_enable_fip = 0; |
| 4505 | |
| 4506 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
| 4507 | phba->valid_vlan = 1; |
| 4508 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & |
| 4509 | 0xFFF; |
| 4510 | } |
| 4511 | |
| 4512 | phba->fc_map[0] = fcoe_param->fc_map[0]; |
| 4513 | phba->fc_map[1] = fcoe_param->fc_map[1]; |
| 4514 | phba->fc_map[2] = fcoe_param->fc_map[2]; |
| 4515 | return; |
| 4516 | } |
| 4517 | |
| 4518 | /** |
| 4519 | * lpfc_get_rec_conf23 - Get a record type in config region data. |
| 4520 | * @buff: Buffer containing config region 23 data. |
| 4521 | * @size: Size of the data buffer. |
| 4522 | * @rec_type: Record type to be searched. |
| 4523 | * |
| 4524 | * This function searches config region data to find the begining |
| 4525 | * of the record specified by record_type. If record found, this |
| 4526 | * function return pointer to the record else return NULL. |
| 4527 | */ |
| 4528 | static uint8_t * |
| 4529 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) |
| 4530 | { |
| 4531 | uint32_t offset = 0, rec_length; |
| 4532 | |
| 4533 | if ((buff[0] == LPFC_REGION23_LAST_REC) || |
| 4534 | (size < sizeof(uint32_t))) |
| 4535 | return NULL; |
| 4536 | |
| 4537 | rec_length = buff[offset + 1]; |
| 4538 | |
| 4539 | /* |
| 4540 | * One TLV record has one word header and number of data words |
| 4541 | * specified in the rec_length field of the record header. |
| 4542 | */ |
| 4543 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) |
| 4544 | <= size) { |
| 4545 | if (buff[offset] == rec_type) |
| 4546 | return &buff[offset]; |
| 4547 | |
| 4548 | if (buff[offset] == LPFC_REGION23_LAST_REC) |
| 4549 | return NULL; |
| 4550 | |
| 4551 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); |
| 4552 | rec_length = buff[offset + 1]; |
| 4553 | } |
| 4554 | return NULL; |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. |
| 4559 | * @phba: Pointer to lpfc_hba data structure. |
| 4560 | * @buff: Buffer containing config region 23 data. |
| 4561 | * @size: Size of the data buffer. |
| 4562 | * |
| 4563 | * This fuction parse the FCoE config parameters in config region 23 and |
| 4564 | * populate driver data structure with the parameters. |
| 4565 | */ |
| 4566 | void |
| 4567 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, |
| 4568 | uint8_t *buff, |
| 4569 | uint32_t size) |
| 4570 | { |
| 4571 | uint32_t offset = 0, rec_length; |
| 4572 | uint8_t *rec_ptr; |
| 4573 | |
| 4574 | /* |
| 4575 | * If data size is less than 2 words signature and version cannot be |
| 4576 | * verified. |
| 4577 | */ |
| 4578 | if (size < 2*sizeof(uint32_t)) |
| 4579 | return; |
| 4580 | |
| 4581 | /* Check the region signature first */ |
| 4582 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { |
| 4583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4584 | "2567 Config region 23 has bad signature\n"); |
| 4585 | return; |
| 4586 | } |
| 4587 | |
| 4588 | offset += 4; |
| 4589 | |
| 4590 | /* Check the data structure version */ |
| 4591 | if (buff[offset] != LPFC_REGION23_VERSION) { |
| 4592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4593 | "2568 Config region 23 has bad version\n"); |
| 4594 | return; |
| 4595 | } |
| 4596 | offset += 4; |
| 4597 | |
| 4598 | rec_length = buff[offset + 1]; |
| 4599 | |
| 4600 | /* Read FCoE param record */ |
| 4601 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 4602 | size - offset, FCOE_PARAM_TYPE); |
| 4603 | if (rec_ptr) |
| 4604 | lpfc_read_fcoe_param(phba, rec_ptr); |
| 4605 | |
| 4606 | /* Read FCF connection table */ |
| 4607 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], |
| 4608 | size - offset, FCOE_CONN_TBL_TYPE); |
| 4609 | if (rec_ptr) |
| 4610 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); |
| 4611 | |
| 4612 | } |