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