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