| 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/interrupt.h> |
| 25 | #include <linux/delay.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_cmnd.h> |
| 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 31 | #include <scsi/scsi_transport_fc.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
| 35 | #include "lpfc_disc.h" |
| 36 | #include "lpfc_scsi.h" |
| 37 | #include "lpfc.h" |
| 38 | #include "lpfc_crtn.h" |
| 39 | #include "lpfc_logmsg.h" |
| 40 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 41 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 45 | * This allows multiple uses of lpfc_msgBlk0311 |
| 46 | * w/o perturbing log msg utility. |
| 47 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 48 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | lpfc_printf_log(phba, \ |
| 50 | KERN_INFO, \ |
| 51 | LOG_MBOX | LOG_SLI, \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | "%d (%d):0311 Mailbox command x%x cannot " \ |
| 53 | "issue Data: x%x x%x x%x\n", \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | phba->brd_no, \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 55 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 56 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | |
| 62 | /* There are only four IOCB completion types. */ |
| 63 | typedef enum _lpfc_iocb_type { |
| 64 | LPFC_UNKNOWN_IOCB, |
| 65 | LPFC_UNSOL_IOCB, |
| 66 | LPFC_SOL_IOCB, |
| 67 | LPFC_ABORT_IOCB |
| 68 | } lpfc_iocb_type; |
| 69 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 70 | /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer |
| 71 | * to the start of the ring, and the slot number of the |
| 72 | * desired iocb entry, calc a pointer to that entry. |
| 73 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 74 | static inline IOCB_t * |
| 75 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 76 | { |
| 77 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 78 | pring->cmdidx * phba->iocb_cmd_size); |
| 79 | } |
| 80 | |
| 81 | static inline IOCB_t * |
| 82 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 83 | { |
| 84 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 85 | pring->rspidx * phba->iocb_rsp_size); |
| 86 | } |
| 87 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 88 | static struct lpfc_iocbq * |
| 89 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 90 | { |
| 91 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 92 | struct lpfc_iocbq * iocbq = NULL; |
| 93 | |
| 94 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 95 | return iocbq; |
| 96 | } |
| 97 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 98 | struct lpfc_iocbq * |
| 99 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 100 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 101 | struct lpfc_iocbq * iocbq = NULL; |
| 102 | unsigned long iflags; |
| 103 | |
| 104 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 105 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 106 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 107 | return iocbq; |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 112 | { |
| 113 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 114 | |
| 115 | /* |
| 116 | * Clean all volatile data fields, preserve iotag and node struct. |
| 117 | */ |
| 118 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 119 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 120 | } |
| 121 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 122 | void |
| 123 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 124 | { |
| 125 | unsigned long iflags; |
| 126 | |
| 127 | /* |
| 128 | * Clean all volatile data fields, preserve iotag and node struct. |
| 129 | */ |
| 130 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 131 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 132 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 133 | } |
| 134 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | /* |
| 136 | * Translate the iocb command to an iocb command type used to decide the final |
| 137 | * disposition of each completed IOCB. |
| 138 | */ |
| 139 | static lpfc_iocb_type |
| 140 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 141 | { |
| 142 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 143 | |
| 144 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 145 | return 0; |
| 146 | |
| 147 | switch (iocb_cmnd) { |
| 148 | case CMD_XMIT_SEQUENCE_CR: |
| 149 | case CMD_XMIT_SEQUENCE_CX: |
| 150 | case CMD_XMIT_BCAST_CN: |
| 151 | case CMD_XMIT_BCAST_CX: |
| 152 | case CMD_ELS_REQUEST_CR: |
| 153 | case CMD_ELS_REQUEST_CX: |
| 154 | case CMD_CREATE_XRI_CR: |
| 155 | case CMD_CREATE_XRI_CX: |
| 156 | case CMD_GET_RPI_CN: |
| 157 | case CMD_XMIT_ELS_RSP_CX: |
| 158 | case CMD_GET_RPI_CR: |
| 159 | case CMD_FCP_IWRITE_CR: |
| 160 | case CMD_FCP_IWRITE_CX: |
| 161 | case CMD_FCP_IREAD_CR: |
| 162 | case CMD_FCP_IREAD_CX: |
| 163 | case CMD_FCP_ICMND_CR: |
| 164 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 165 | case CMD_FCP_TSEND_CX: |
| 166 | case CMD_FCP_TRSP_CX: |
| 167 | case CMD_FCP_TRECEIVE_CX: |
| 168 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | case CMD_ADAPTER_MSG: |
| 170 | case CMD_ADAPTER_DUMP: |
| 171 | case CMD_XMIT_SEQUENCE64_CR: |
| 172 | case CMD_XMIT_SEQUENCE64_CX: |
| 173 | case CMD_XMIT_BCAST64_CN: |
| 174 | case CMD_XMIT_BCAST64_CX: |
| 175 | case CMD_ELS_REQUEST64_CR: |
| 176 | case CMD_ELS_REQUEST64_CX: |
| 177 | case CMD_FCP_IWRITE64_CR: |
| 178 | case CMD_FCP_IWRITE64_CX: |
| 179 | case CMD_FCP_IREAD64_CR: |
| 180 | case CMD_FCP_IREAD64_CX: |
| 181 | case CMD_FCP_ICMND64_CR: |
| 182 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 183 | case CMD_FCP_TSEND64_CX: |
| 184 | case CMD_FCP_TRSP64_CX: |
| 185 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | case CMD_GEN_REQUEST64_CR: |
| 187 | case CMD_GEN_REQUEST64_CX: |
| 188 | case CMD_XMIT_ELS_RSP64_CX: |
| 189 | type = LPFC_SOL_IOCB; |
| 190 | break; |
| 191 | case CMD_ABORT_XRI_CN: |
| 192 | case CMD_ABORT_XRI_CX: |
| 193 | case CMD_CLOSE_XRI_CN: |
| 194 | case CMD_CLOSE_XRI_CX: |
| 195 | case CMD_XRI_ABORTED_CX: |
| 196 | case CMD_ABORT_MXRI64_CN: |
| 197 | type = LPFC_ABORT_IOCB; |
| 198 | break; |
| 199 | case CMD_RCV_SEQUENCE_CX: |
| 200 | case CMD_RCV_ELS_REQ_CX: |
| 201 | case CMD_RCV_SEQUENCE64_CX: |
| 202 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 203 | case CMD_IOCB_RCV_SEQ64_CX: |
| 204 | case CMD_IOCB_RCV_ELS64_CX: |
| 205 | case CMD_IOCB_RCV_CONT64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | type = LPFC_UNSOL_IOCB; |
| 207 | break; |
| 208 | default: |
| 209 | type = LPFC_UNKNOWN_IOCB; |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | return type; |
| 214 | } |
| 215 | |
| 216 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 217 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | { |
| 219 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 220 | LPFC_MBOXQ_t *pmb; |
| 221 | MAILBOX_t *pmbox; |
| 222 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 224 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 225 | if (!pmb) |
| 226 | return -ENOMEM; |
| 227 | pmbox = &pmb->mb; |
| 228 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | lpfc_config_ring(phba, i, pmb); |
| 231 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 232 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 234 | "%d:0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 236 | "ring %d\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | phba->brd_no, rc, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | pmbox->mbxCommand, |
| 239 | pmbox->mbxStatus, |
| 240 | i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 241 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 242 | ret = -ENXIO; |
| 243 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | } |
| 245 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 246 | mempool_free(pmb, phba->mbox_mem_pool); |
| 247 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 251 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 252 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 255 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 257 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 258 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 259 | if (!piocb->vport) |
| 260 | BUG(); |
| 261 | else |
| 262 | mod_timer(&piocb->vport->els_tmofunc, |
| 263 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 264 | } |
| 265 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 266 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 267 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 271 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 272 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 273 | struct lpfc_iocbq *cmd_iocb; |
| 274 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 275 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 276 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 277 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 278 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static IOCB_t * |
| 282 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 283 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 284 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
| 285 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : |
| 286 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 288 | |
| 289 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 290 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 291 | pring->next_cmdidx = 0; |
| 292 | |
| 293 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 294 | |
| 295 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 296 | |
| 297 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 298 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 299 | "%d:0315 Ring %d issue: portCmdGet %d " |
| 300 | "is bigger then cmd ring %d\n", |
| 301 | phba->brd_no, pring->ringno, |
| 302 | pring->local_getidx, max_cmd_idx); |
| 303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 304 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | /* |
| 306 | * All error attention handlers are posted to |
| 307 | * worker thread |
| 308 | */ |
| 309 | phba->work_ha |= HA_ERATT; |
| 310 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 311 | |
| 312 | /* hbalock should already be held */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 313 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 314 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | if (pring->local_getidx == pring->next_cmdidx) |
| 320 | return NULL; |
| 321 | } |
| 322 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 323 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | } |
| 325 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 326 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 327 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 328 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 329 | struct lpfc_iocbq **new_arr; |
| 330 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 331 | size_t new_len; |
| 332 | struct lpfc_sli *psli = &phba->sli; |
| 333 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 335 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 336 | iotag = psli->last_iotag; |
| 337 | if(++iotag < psli->iocbq_lookup_len) { |
| 338 | psli->last_iotag = iotag; |
| 339 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 340 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 341 | iocbq->iotag = iotag; |
| 342 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 343 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 344 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 345 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 346 | spin_unlock_irq(&phba->hbalock); |
| 347 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 348 | GFP_KERNEL); |
| 349 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 350 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 351 | old_arr = psli->iocbq_lookup; |
| 352 | if (new_len <= psli->iocbq_lookup_len) { |
| 353 | /* highly unprobable case */ |
| 354 | kfree(new_arr); |
| 355 | iotag = psli->last_iotag; |
| 356 | if(++iotag < psli->iocbq_lookup_len) { |
| 357 | psli->last_iotag = iotag; |
| 358 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 359 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 360 | iocbq->iotag = iotag; |
| 361 | return iotag; |
| 362 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 363 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | if (psli->iocbq_lookup) |
| 367 | memcpy(new_arr, old_arr, |
| 368 | ((psli->last_iotag + 1) * |
| 369 | sizeof (struct lpfc_iocbq *))); |
| 370 | psli->iocbq_lookup = new_arr; |
| 371 | psli->iocbq_lookup_len = new_len; |
| 372 | psli->last_iotag = iotag; |
| 373 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 374 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 375 | iocbq->iotag = iotag; |
| 376 | kfree(old_arr); |
| 377 | return iotag; |
| 378 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 379 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 380 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 381 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 382 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
| 383 | "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 384 | phba->brd_no, psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 386 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void |
| 390 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 391 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 392 | { |
| 393 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 394 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 395 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 396 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * Issue iocb command to adapter |
| 400 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 401 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 402 | wmb(); |
| 403 | pring->stats.iocb_cmd++; |
| 404 | |
| 405 | /* |
| 406 | * If there is no completion routine to call, we can release the |
| 407 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 408 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 409 | */ |
| 410 | if (nextiocb->iocb_cmpl) |
| 411 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 412 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | |
| 415 | /* |
| 416 | * Let the HBA know what IOCB slot will be the next one the |
| 417 | * driver will put a command into. |
| 418 | */ |
| 419 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 420 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 424 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | { |
| 426 | int ringno = pring->ringno; |
| 427 | |
| 428 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 429 | |
| 430 | wmb(); |
| 431 | |
| 432 | /* |
| 433 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 434 | * The HBA will tell us when an IOCB entry is available. |
| 435 | */ |
| 436 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 437 | readl(phba->CAregaddr); /* flush */ |
| 438 | |
| 439 | pring->stats.iocb_cmd_full++; |
| 440 | } |
| 441 | |
| 442 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 443 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | { |
| 445 | int ringno = pring->ringno; |
| 446 | |
| 447 | /* |
| 448 | * Tell the HBA that there is work to do in this ring. |
| 449 | */ |
| 450 | wmb(); |
| 451 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 452 | readl(phba->CAregaddr); /* flush */ |
| 453 | } |
| 454 | |
| 455 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 456 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 457 | { |
| 458 | IOCB_t *iocb; |
| 459 | struct lpfc_iocbq *nextiocb; |
| 460 | |
| 461 | /* |
| 462 | * Check to see if: |
| 463 | * (a) there is anything on the txq to send |
| 464 | * (b) link is up |
| 465 | * (c) link attention events can be processed (fcp ring only) |
| 466 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 467 | */ |
| 468 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 469 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 470 | (pring->ringno != phba->sli.fcp_ring || |
| 471 | phba->sli.sli_flag & LPFC_PROCESS_LA) && |
| 472 | !(pring->flag & LPFC_STOP_IOCB_MBX)) { |
| 473 | |
| 474 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 475 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 476 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 477 | |
| 478 | if (iocb) |
| 479 | lpfc_sli_update_ring(phba, pring); |
| 480 | else |
| 481 | lpfc_sli_update_full_ring(phba, pring); |
| 482 | } |
| 483 | |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */ |
| 488 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 489 | lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 491 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
| 492 | &phba->slim2p->mbx.us.s3_pgp.port[ringno] : |
| 493 | &phba->slim2p->mbx.us.s2.port[ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 494 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 495 | |
| 496 | /* If the ring is active, flag it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 497 | spin_lock_irqsave(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | if (phba->sli.ring[ringno].cmdringaddr) { |
| 499 | if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) { |
| 500 | phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX; |
| 501 | /* |
| 502 | * Force update of the local copy of cmdGetInx |
| 503 | */ |
| 504 | phba->sli.ring[ringno].local_getidx |
| 505 | = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | } |
| 508 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 509 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | } |
| 511 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 512 | struct lpfc_hbq_entry * |
| 513 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 514 | { |
| 515 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 516 | |
| 517 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 518 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 519 | hbqp->next_hbqPutIdx = 0; |
| 520 | |
| 521 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 522 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 523 | uint32_t getidx = le32_to_cpu(raw_index); |
| 524 | |
| 525 | hbqp->local_hbqGetIdx = getidx; |
| 526 | |
| 527 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 528 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 529 | LOG_SLI | LOG_VPORT, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 530 | "%d:1802 HBQ %d: local_hbqGetIdx " |
| 531 | "%u is > than hbqp->entry_count %u\n", |
| 532 | phba->brd_no, hbqno, |
| 533 | hbqp->local_hbqGetIdx, |
| 534 | hbqp->entry_count); |
| 535 | |
| 536 | phba->link_state = LPFC_HBA_ERROR; |
| 537 | return NULL; |
| 538 | } |
| 539 | |
| 540 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 541 | return NULL; |
| 542 | } |
| 543 | |
| 544 | return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx; |
| 545 | } |
| 546 | |
| 547 | void |
| 548 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 549 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 550 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 551 | struct hbq_dmabuf *hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 552 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 553 | /* Return all memory used by all HBQs */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 554 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 555 | &phba->hbq_buffer_list, list) { |
| 556 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 557 | list_del(&hbq_buf->dbuf.list); |
| 558 | lpfc_hbq_free(phba, hbq_buf->dbuf.virt, hbq_buf->dbuf.phys); |
| 559 | kfree(hbq_buf); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 560 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static void |
| 564 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 565 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 566 | { |
| 567 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 568 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 569 | |
| 570 | /* Get next HBQ entry slot to use */ |
| 571 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 572 | if (hbqe) { |
| 573 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 575 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 576 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 577 | hbqe->bde.tus.f.bdeSize = FCELSSIZE; |
| 578 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 579 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 580 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 581 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 582 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 583 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 584 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 585 | readl(phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 586 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 590 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 591 | .rn = 1, |
| 592 | .entry_count = 200, |
| 593 | .mask_count = 0, |
| 594 | .profile = 0, |
| 595 | .ring_mask = 1 << LPFC_ELS_RING, |
| 596 | .buffer_count = 0, |
| 597 | .init_count = 20, |
| 598 | .add_count = 5, |
| 599 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 600 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 601 | static struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
| 602 | &lpfc_els_hbq, |
| 603 | }; |
| 604 | |
| 605 | int |
| 606 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 607 | { |
| 608 | uint32_t i, start, end; |
| 609 | struct hbq_dmabuf *hbq_buffer; |
| 610 | |
| 611 | start = lpfc_hbq_defs[hbqno]->buffer_count; |
| 612 | end = count + lpfc_hbq_defs[hbqno]->buffer_count; |
| 613 | if (end > lpfc_hbq_defs[hbqno]->entry_count) { |
| 614 | end = lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 615 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 616 | |
| 617 | /* Populate HBQ entries */ |
| 618 | for (i = start; i < end; i++) { |
| 619 | hbq_buffer = kmalloc(sizeof(struct hbq_dmabuf), |
| 620 | GFP_KERNEL); |
| 621 | if (!hbq_buffer) |
| 622 | return 1; |
| 623 | hbq_buffer->dbuf.virt = lpfc_hbq_alloc(phba, MEM_PRI, |
| 624 | &hbq_buffer->dbuf.phys); |
| 625 | if (hbq_buffer->dbuf.virt == NULL) |
| 626 | return 1; |
| 627 | hbq_buffer->tag = (i | (hbqno << 16)); |
| 628 | lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer); |
| 629 | lpfc_hbq_defs[hbqno]->buffer_count++; |
| 630 | } |
| 631 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 635 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 636 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 637 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 638 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 639 | } |
| 640 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 641 | int |
| 642 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 643 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 644 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 645 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | struct hbq_dmabuf * |
| 649 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 650 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 651 | struct lpfc_dmabuf *d_buf; |
| 652 | struct hbq_dmabuf *hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 653 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 654 | list_for_each_entry(d_buf, &phba->hbq_buffer_list, list) { |
| 655 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 656 | if ((hbq_buf->tag & 0xffff) == tag) { |
| 657 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 658 | } |
| 659 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
| 661 | "%d:1803 Bad hbq tag. Data: x%x x%x\n", |
| 662 | phba->brd_no, tag, |
| 663 | lpfc_hbq_defs[tag >> 16]->buffer_count); |
| 664 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void |
| 668 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp) |
| 669 | { |
| 670 | uint32_t hbqno; |
| 671 | |
| 672 | if (sp) { |
| 673 | hbqno = sp->tag >> 16; |
| 674 | lpfc_sli_hbq_to_firmware(phba, hbqno, sp); |
| 675 | } |
| 676 | } |
| 677 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | static int |
| 679 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 680 | { |
| 681 | uint8_t ret; |
| 682 | |
| 683 | switch (mbxCommand) { |
| 684 | case MBX_LOAD_SM: |
| 685 | case MBX_READ_NV: |
| 686 | case MBX_WRITE_NV: |
| 687 | case MBX_RUN_BIU_DIAG: |
| 688 | case MBX_INIT_LINK: |
| 689 | case MBX_DOWN_LINK: |
| 690 | case MBX_CONFIG_LINK: |
| 691 | case MBX_CONFIG_RING: |
| 692 | case MBX_RESET_RING: |
| 693 | case MBX_READ_CONFIG: |
| 694 | case MBX_READ_RCONFIG: |
| 695 | case MBX_READ_SPARM: |
| 696 | case MBX_READ_STATUS: |
| 697 | case MBX_READ_RPI: |
| 698 | case MBX_READ_XRI: |
| 699 | case MBX_READ_REV: |
| 700 | case MBX_READ_LNK_STAT: |
| 701 | case MBX_REG_LOGIN: |
| 702 | case MBX_UNREG_LOGIN: |
| 703 | case MBX_READ_LA: |
| 704 | case MBX_CLEAR_LA: |
| 705 | case MBX_DUMP_MEMORY: |
| 706 | case MBX_DUMP_CONTEXT: |
| 707 | case MBX_RUN_DIAGS: |
| 708 | case MBX_RESTART: |
| 709 | case MBX_UPDATE_CFG: |
| 710 | case MBX_DOWN_LOAD: |
| 711 | case MBX_DEL_LD_ENTRY: |
| 712 | case MBX_RUN_PROGRAM: |
| 713 | case MBX_SET_MASK: |
| 714 | case MBX_SET_SLIM: |
| 715 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 716 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 718 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 719 | case MBX_LOAD_AREA: |
| 720 | case MBX_RUN_BIU_DIAG64: |
| 721 | case MBX_CONFIG_PORT: |
| 722 | case MBX_READ_SPARM64: |
| 723 | case MBX_READ_RPI64: |
| 724 | case MBX_REG_LOGIN64: |
| 725 | case MBX_READ_LA64: |
| 726 | case MBX_FLASH_WR_ULA: |
| 727 | case MBX_SET_DEBUG: |
| 728 | case MBX_LOAD_EXP_ROM: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 729 | case MBX_REG_VPI: |
| 730 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 731 | case MBX_HEARTBEAT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | ret = mbxCommand; |
| 733 | break; |
| 734 | default: |
| 735 | ret = MBX_SHUTDOWN; |
| 736 | break; |
| 737 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 738 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | } |
| 740 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 741 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | { |
| 743 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 744 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | |
| 746 | /* |
| 747 | * If pdone_q is empty, the driver thread gave up waiting and |
| 748 | * continued running. |
| 749 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 750 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 751 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 753 | if (pdone_q) |
| 754 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 755 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | |
| 759 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 760 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | { |
| 762 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 763 | uint16_t rpi; |
| 764 | int rc; |
| 765 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | if (mp) { |
| 769 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 770 | kfree(mp); |
| 771 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 772 | |
| 773 | /* |
| 774 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 775 | * is in re-discovery driver need to cleanup the RPI. |
| 776 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 778 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 779 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 780 | |
| 781 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 782 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 783 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 784 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 785 | if (rc != MBX_NOT_FINISHED) |
| 786 | return; |
| 787 | } |
| 788 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 789 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | return; |
| 791 | } |
| 792 | |
| 793 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 794 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 798 | int rc; |
| 799 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | |
| 801 | phba->sli.slistat.mbox_event++; |
| 802 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | /* Get all completed mailboxe buffers into the cmplq */ |
| 804 | spin_lock_irq(&phba->hbalock); |
| 805 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 806 | spin_unlock_irq(&phba->hbalock); |
| 807 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 808 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 809 | do { |
| 810 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 811 | if (pmb == NULL) |
| 812 | break; |
| 813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 815 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 816 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 817 | if (pmb->vport) { |
| 818 | lpfc_debugfs_disc_trc(pmb->vport, |
| 819 | LPFC_DISC_TRC_MBOX_VPORT, |
| 820 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 821 | (uint32_t)pmbox->mbxCommand, |
| 822 | pmbox->un.varWords[0], |
| 823 | pmbox->un.varWords[1]); |
| 824 | } |
| 825 | else { |
| 826 | lpfc_debugfs_disc_trc(phba->pport, |
| 827 | LPFC_DISC_TRC_MBOX, |
| 828 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 829 | (uint32_t)pmbox->mbxCommand, |
| 830 | pmbox->un.varWords[0], |
| 831 | pmbox->un.varWords[1]); |
| 832 | } |
| 833 | } |
| 834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 835 | /* |
| 836 | * It is a fatal error if unknown mbox command completion. |
| 837 | */ |
| 838 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 839 | MBX_SHUTDOWN) { |
| 840 | |
| 841 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 842 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 843 | "%d (%d):0323 Unknown Mailbox command " |
| 844 | "%x Cmpl\n", |
| 845 | phba->brd_no, |
| 846 | pmb->vport ? pmb->vport->vpi : 0, |
| 847 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 848 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | phba->work_hs = HS_FFER3; |
| 850 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 851 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 854 | if (pmbox->mbxStatus) { |
| 855 | phba->sli.slistat.mbox_stat_err++; |
| 856 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 857 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 858 | lpfc_printf_log(phba, KERN_INFO, |
| 859 | LOG_MBOX | LOG_SLI, |
| 860 | "%d (%d):0305 Mbox cmd cmpl " |
| 861 | "error - RETRYing Data: x%x " |
| 862 | "x%x x%x x%x\n", |
| 863 | phba->brd_no, |
| 864 | pmb->vport ? pmb->vport->vpi :0, |
| 865 | pmbox->mbxCommand, |
| 866 | pmbox->mbxStatus, |
| 867 | pmbox->un.varWords[0], |
| 868 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | pmbox->mbxStatus = 0; |
| 870 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 871 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 873 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 874 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 875 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 876 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 881 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 882 | "%d (%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
| 884 | phba->brd_no, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 885 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | pmbox->mbxCommand, |
| 887 | pmb->mbox_cmpl, |
| 888 | *((uint32_t *) pmbox), |
| 889 | pmbox->un.varWords[0], |
| 890 | pmbox->un.varWords[1], |
| 891 | pmbox->un.varWords[2], |
| 892 | pmbox->un.varWords[3], |
| 893 | pmbox->un.varWords[4], |
| 894 | pmbox->un.varWords[5], |
| 895 | pmbox->un.varWords[6], |
| 896 | pmbox->un.varWords[7]); |
| 897 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 899 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 900 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 903 | |
| 904 | static struct lpfc_dmabuf * |
| 905 | lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) |
| 906 | { |
| 907 | struct hbq_dmabuf *hbq_entry, *new_hbq_entry; |
| 908 | |
| 909 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 910 | if (hbq_entry == NULL) |
| 911 | return NULL; |
| 912 | list_del(&hbq_entry->dbuf.list); |
| 913 | new_hbq_entry = kmalloc(sizeof(struct hbq_dmabuf), GFP_ATOMIC); |
| 914 | if (new_hbq_entry == NULL) |
| 915 | return &hbq_entry->dbuf; |
| 916 | new_hbq_entry->dbuf = hbq_entry->dbuf; |
| 917 | new_hbq_entry->tag = -1; |
| 918 | hbq_entry->dbuf.virt = lpfc_hbq_alloc(phba, 0, &hbq_entry->dbuf.phys); |
| 919 | if (hbq_entry->dbuf.virt == NULL) { |
| 920 | kfree(new_hbq_entry); |
| 921 | return &hbq_entry->dbuf; |
| 922 | } |
| 923 | lpfc_sli_free_hbq(phba, hbq_entry); |
| 924 | return &new_hbq_entry->dbuf; |
| 925 | } |
| 926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | static int |
| 928 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 929 | struct lpfc_iocbq *saveq) |
| 930 | { |
| 931 | IOCB_t * irsp; |
| 932 | WORD5 * w5p; |
| 933 | uint32_t Rctl, Type; |
| 934 | uint32_t match, i; |
| 935 | |
| 936 | match = 0; |
| 937 | irsp = &(saveq->iocb); |
| 938 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 939 | || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) |
| 940 | || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX) |
| 941 | || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 942 | Rctl = FC_ELS_REQ; |
| 943 | Type = FC_ELS_DATA; |
| 944 | } else { |
| 945 | w5p = |
| 946 | (WORD5 *) & (saveq->iocb.un. |
| 947 | ulpWord[5]); |
| 948 | Rctl = w5p->hcsw.Rctl; |
| 949 | Type = w5p->hcsw.Type; |
| 950 | |
| 951 | /* Firmware Workaround */ |
| 952 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 953 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 954 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | Rctl = FC_ELS_REQ; |
| 956 | Type = FC_ELS_DATA; |
| 957 | w5p->hcsw.Rctl = Rctl; |
| 958 | w5p->hcsw.Type = Type; |
| 959 | } |
| 960 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | |
| 962 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 963 | if (irsp->ulpBdeCount != 0) |
| 964 | saveq->context2 = lpfc_sli_replace_hbqbuff(phba, |
| 965 | irsp->un.ulpWord[3]); |
| 966 | if (irsp->ulpBdeCount == 2) |
| 967 | saveq->context3 = lpfc_sli_replace_hbqbuff(phba, |
| 968 | irsp->un.ulpWord[15]); |
| 969 | } |
| 970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | /* unSolicited Responses */ |
| 972 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 973 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 974 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 975 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | match = 1; |
| 977 | } else { |
| 978 | /* We must search, based on rctl / type |
| 979 | for the right routine */ |
| 980 | for (i = 0; i < pring->num_mask; |
| 981 | i++) { |
| 982 | if ((pring->prt[i].rctl == |
| 983 | Rctl) |
| 984 | && (pring->prt[i]. |
| 985 | type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 986 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 987 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 988 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | match = 1; |
| 990 | break; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | if (match == 0) { |
| 995 | /* Unexpected Rctl / Type received */ |
| 996 | /* Ring <ringno> handler: unexpected |
| 997 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 998 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | "%d:0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1000 | "Type x%x received\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | phba->brd_no, |
| 1002 | pring->ringno, |
| 1003 | Rctl, |
| 1004 | Type); |
| 1005 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1006 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1010 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1011 | struct lpfc_sli_ring *pring, |
| 1012 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1015 | uint16_t iotag; |
| 1016 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1017 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1019 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1020 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1021 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1022 | pring->txcmplq_cnt--; |
| 1023 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1027 | "%d:0317 iotag x%x is out off " |
| 1028 | "range: max iotag x%x wd0 x%x\n", |
| 1029 | phba->brd_no, iotag, |
| 1030 | phba->sli.last_iotag, |
| 1031 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | return NULL; |
| 1033 | } |
| 1034 | |
| 1035 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1036 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | struct lpfc_iocbq *saveq) |
| 1038 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1039 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | int rc = 1; |
| 1041 | unsigned long iflag; |
| 1042 | |
| 1043 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1044 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1045 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1046 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1047 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | if (cmdiocbp) { |
| 1049 | if (cmdiocbp->iocb_cmpl) { |
| 1050 | /* |
| 1051 | * Post all ELS completions to the worker thread. |
| 1052 | * All other are passed to the completion callback. |
| 1053 | */ |
| 1054 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1055 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1056 | cmdiocbp->iocb_flag &= |
| 1057 | ~LPFC_DRIVER_ABORTED; |
| 1058 | saveq->iocb.ulpStatus = |
| 1059 | IOSTAT_LOCAL_REJECT; |
| 1060 | saveq->iocb.un.ulpWord[4] = |
| 1061 | IOERR_SLI_ABORTED; |
| 1062 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1064 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1065 | } else |
| 1066 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | } else { |
| 1068 | /* |
| 1069 | * Unknown initiating command based on the response iotag. |
| 1070 | * This could be the case on the ELS ring because of |
| 1071 | * lpfc_els_abort(). |
| 1072 | */ |
| 1073 | if (pring->ringno != LPFC_ELS_RING) { |
| 1074 | /* |
| 1075 | * Ring <ringno> handler: unexpected completion IoTag |
| 1076 | * <IoTag> |
| 1077 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1078 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 1079 | "%d (%d):0322 Ring %d handler: " |
| 1080 | "unexpected completion IoTag x%x " |
| 1081 | "Data: x%x x%x x%x x%x\n", |
| 1082 | phba->brd_no, |
| 1083 | cmdiocbp->vport->vpi, |
| 1084 | pring->ringno, |
| 1085 | saveq->iocb.ulpIoTag, |
| 1086 | saveq->iocb.ulpStatus, |
| 1087 | saveq->iocb.un.ulpWord[4], |
| 1088 | saveq->iocb.ulpCommand, |
| 1089 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | } |
| 1091 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1092 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | return rc; |
| 1094 | } |
| 1095 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1098 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1099 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
| 1100 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : |
| 1101 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1102 | /* |
| 1103 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 1104 | * rsp ring <portRspMax> |
| 1105 | */ |
| 1106 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 1107 | "%d:0312 Ring %d handler: portRspPut %d " |
| 1108 | "is bigger then rsp ring %d\n", |
| 1109 | phba->brd_no, pring->ringno, |
| 1110 | le32_to_cpu(pgp->rspPutInx), |
| 1111 | pring->numRiocb); |
| 1112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1114 | |
| 1115 | /* |
| 1116 | * All error attention handlers are posted to |
| 1117 | * worker thread |
| 1118 | */ |
| 1119 | phba->work_ha |= HA_ERATT; |
| 1120 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1121 | |
| 1122 | /* hbalock should already be held */ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1123 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1124 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1125 | |
| 1126 | return; |
| 1127 | } |
| 1128 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1130 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1131 | struct lpfc_sli *psli = &phba->sli; |
| 1132 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1133 | IOCB_t *irsp = NULL; |
| 1134 | IOCB_t *entry = NULL; |
| 1135 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1136 | struct lpfc_iocbq rspiocbq; |
| 1137 | struct lpfc_pgp *pgp; |
| 1138 | uint32_t status; |
| 1139 | uint32_t portRspPut, portRspMax; |
| 1140 | int type; |
| 1141 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1142 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1143 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1144 | |
| 1145 | pring->stats.iocb_event++; |
| 1146 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1147 | pgp = (phba->sli_rev == 3) ? |
| 1148 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : |
| 1149 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; |
| 1150 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1151 | |
| 1152 | /* |
| 1153 | * The next available response entry should never exceed the maximum |
| 1154 | * entries. If it does, treat it as an adapter hardware error. |
| 1155 | */ |
| 1156 | portRspMax = pring->numRiocb; |
| 1157 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1158 | if (unlikely(portRspPut >= portRspMax)) { |
| 1159 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | rmb(); |
| 1164 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1165 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1166 | if (++pring->rspidx >= portRspMax) |
| 1167 | pring->rspidx = 0; |
| 1168 | |
| 1169 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1170 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1171 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1172 | irsp = &rspiocbq.iocb; |
| 1173 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1174 | pring->stats.iocb_rsp++; |
| 1175 | rsp_cmpl++; |
| 1176 | |
| 1177 | if (unlikely(irsp->ulpStatus)) { |
| 1178 | /* Rsp ring <ringno> error: IOCB */ |
| 1179 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 1180 | "%d:0326 Rsp Ring %d error: IOCB Data: " |
| 1181 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
| 1182 | phba->brd_no, pring->ringno, |
| 1183 | irsp->un.ulpWord[0], |
| 1184 | irsp->un.ulpWord[1], |
| 1185 | irsp->un.ulpWord[2], |
| 1186 | irsp->un.ulpWord[3], |
| 1187 | irsp->un.ulpWord[4], |
| 1188 | irsp->un.ulpWord[5], |
| 1189 | *(((uint32_t *) irsp) + 6), |
| 1190 | *(((uint32_t *) irsp) + 7)); |
| 1191 | } |
| 1192 | |
| 1193 | switch (type) { |
| 1194 | case LPFC_ABORT_IOCB: |
| 1195 | case LPFC_SOL_IOCB: |
| 1196 | /* |
| 1197 | * Idle exchange closed via ABTS from port. No iocb |
| 1198 | * resources need to be recovered. |
| 1199 | */ |
| 1200 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1201 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1202 | "%d:0314 IOCB cmd 0x%x" |
| 1203 | " processed. Skipping" |
| 1204 | " completion", phba->brd_no, |
| 1205 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1206 | break; |
| 1207 | } |
| 1208 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1209 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1210 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1211 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1213 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1214 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1215 | &rspiocbq); |
| 1216 | } |
| 1217 | break; |
| 1218 | default: |
| 1219 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1220 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1221 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1222 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1223 | MAX_MSG_DATA); |
| 1224 | dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s", |
| 1225 | phba->brd_no, adaptermsg); |
| 1226 | } else { |
| 1227 | /* Unknown IOCB command */ |
| 1228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 1229 | "%d:0321 Unknown IOCB command " |
| 1230 | "Data: x%x, x%x x%x x%x x%x\n", |
| 1231 | phba->brd_no, type, |
| 1232 | irsp->ulpCommand, |
| 1233 | irsp->ulpStatus, |
| 1234 | irsp->ulpIoTag, |
| 1235 | irsp->ulpContext); |
| 1236 | } |
| 1237 | break; |
| 1238 | } |
| 1239 | |
| 1240 | /* |
| 1241 | * The response IOCB has been processed. Update the ring |
| 1242 | * pointer in SLIM. If the port response put pointer has not |
| 1243 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1244 | * response put pointer. |
| 1245 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1246 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1247 | |
| 1248 | if (pring->rspidx == portRspPut) |
| 1249 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1250 | } |
| 1251 | |
| 1252 | ha_copy = readl(phba->HAregaddr); |
| 1253 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1254 | |
| 1255 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1256 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1257 | pring->stats.iocb_rsp_full++; |
| 1258 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1259 | writel(status, phba->CAregaddr); |
| 1260 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1261 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1262 | } |
| 1263 | if ((ha_copy & HA_R0CE_RSP) && |
| 1264 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1265 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1266 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1267 | pring->stats.iocb_cmd_empty++; |
| 1268 | |
| 1269 | /* Force update of the local copy of cmdGetInx */ |
| 1270 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1271 | lpfc_sli_resume_iocb(phba, pring); |
| 1272 | |
| 1273 | if ((pring->lpfc_sli_cmd_available)) |
| 1274 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1275 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | return; |
| 1280 | } |
| 1281 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1282 | /* |
| 1283 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
| 1284 | * to check it explicitly. |
| 1285 | */ |
| 1286 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1287 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1288 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1290 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
| 1291 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : |
| 1292 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1294 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1296 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | uint32_t status; |
| 1298 | uint32_t portRspPut, portRspMax; |
| 1299 | int rc = 1; |
| 1300 | lpfc_iocb_type type; |
| 1301 | unsigned long iflag; |
| 1302 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1304 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | pring->stats.iocb_event++; |
| 1306 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | /* |
| 1308 | * The next available response entry should never exceed the maximum |
| 1309 | * entries. If it does, treat it as an adapter hardware error. |
| 1310 | */ |
| 1311 | portRspMax = pring->numRiocb; |
| 1312 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1313 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1314 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1315 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | return 1; |
| 1317 | } |
| 1318 | |
| 1319 | rmb(); |
| 1320 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1321 | /* |
| 1322 | * Fetch an entry off the ring and copy it into a local data |
| 1323 | * structure. The copy involves a byte-swap since the |
| 1324 | * network byte order and pci byte orders are different. |
| 1325 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1326 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1327 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1328 | |
| 1329 | if (++pring->rspidx >= portRspMax) |
| 1330 | pring->rspidx = 0; |
| 1331 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1332 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1333 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1334 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1335 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1336 | irsp = &rspiocbq.iocb; |
| 1337 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1339 | pring->stats.iocb_rsp++; |
| 1340 | rsp_cmpl++; |
| 1341 | |
| 1342 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1343 | /* |
| 1344 | * If resource errors reported from HBA, reduce |
| 1345 | * queuedepths of the SCSI device. |
| 1346 | */ |
| 1347 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1348 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1349 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1350 | lpfc_adjust_queue_depth(phba); |
| 1351 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1352 | } |
| 1353 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1354 | /* Rsp ring <ringno> error: IOCB */ |
| 1355 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1356 | "%d:0336 Rsp Ring %d error: IOCB Data: " |
| 1357 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
| 1358 | phba->brd_no, pring->ringno, |
| 1359 | irsp->un.ulpWord[0], |
| 1360 | irsp->un.ulpWord[1], |
| 1361 | irsp->un.ulpWord[2], |
| 1362 | irsp->un.ulpWord[3], |
| 1363 | irsp->un.ulpWord[4], |
| 1364 | irsp->un.ulpWord[5], |
| 1365 | *(((uint32_t *) irsp) + 6), |
| 1366 | *(((uint32_t *) irsp) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | switch (type) { |
| 1370 | case LPFC_ABORT_IOCB: |
| 1371 | case LPFC_SOL_IOCB: |
| 1372 | /* |
| 1373 | * Idle exchange closed via ABTS from port. No iocb |
| 1374 | * resources need to be recovered. |
| 1375 | */ |
| 1376 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1377 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1378 | "%d:0333 IOCB cmd 0x%x" |
| 1379 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1380 | " completion\n", |
| 1381 | phba->brd_no, |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1382 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | break; |
| 1384 | } |
| 1385 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1386 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1387 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1389 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 1390 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1391 | &rspiocbq); |
| 1392 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1393 | spin_unlock_irqrestore(&phba->hbalock, |
| 1394 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1395 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1396 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1397 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1398 | iflag); |
| 1399 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | } |
| 1401 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1402 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1403 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1404 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1406 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | default: |
| 1408 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1409 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1410 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1411 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1412 | MAX_MSG_DATA); |
| 1413 | dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s", |
| 1414 | phba->brd_no, adaptermsg); |
| 1415 | } else { |
| 1416 | /* Unknown IOCB command */ |
| 1417 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1418 | "%d:0334 Unknown IOCB command " |
| 1419 | "Data: x%x, x%x x%x x%x x%x\n", |
| 1420 | phba->brd_no, type, |
| 1421 | irsp->ulpCommand, |
| 1422 | irsp->ulpStatus, |
| 1423 | irsp->ulpIoTag, |
| 1424 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | } |
| 1426 | break; |
| 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * The response IOCB has been processed. Update the ring |
| 1431 | * pointer in SLIM. If the port response put pointer has not |
| 1432 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1433 | * response put pointer. |
| 1434 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1435 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | |
| 1437 | if (pring->rspidx == portRspPut) |
| 1438 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1439 | } |
| 1440 | |
| 1441 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 1442 | pring->stats.iocb_rsp_full++; |
| 1443 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 1444 | writel(status, phba->CAregaddr); |
| 1445 | readl(phba->CAregaddr); |
| 1446 | } |
| 1447 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 1448 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1449 | pring->stats.iocb_cmd_empty++; |
| 1450 | |
| 1451 | /* Force update of the local copy of cmdGetInx */ |
| 1452 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1453 | lpfc_sli_resume_iocb(phba, pring); |
| 1454 | |
| 1455 | if ((pring->lpfc_sli_cmd_available)) |
| 1456 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1457 | |
| 1458 | } |
| 1459 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | return rc; |
| 1462 | } |
| 1463 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 1466 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1468 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
| 1469 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : |
| 1470 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | IOCB_t *entry; |
| 1472 | IOCB_t *irsp = NULL; |
| 1473 | struct lpfc_iocbq *rspiocbp = NULL; |
| 1474 | struct lpfc_iocbq *next_iocb; |
| 1475 | struct lpfc_iocbq *cmdiocbp; |
| 1476 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | uint8_t iocb_cmd_type; |
| 1478 | lpfc_iocb_type type; |
| 1479 | uint32_t status, free_saveq; |
| 1480 | uint32_t portRspPut, portRspMax; |
| 1481 | int rc = 1; |
| 1482 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1483 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | pring->stats.iocb_event++; |
| 1486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | /* |
| 1488 | * The next available response entry should never exceed the maximum |
| 1489 | * entries. If it does, treat it as an adapter hardware error. |
| 1490 | */ |
| 1491 | portRspMax = pring->numRiocb; |
| 1492 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1493 | if (portRspPut >= portRspMax) { |
| 1494 | /* |
| 1495 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 1496 | * rsp ring <portRspMax> |
| 1497 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1498 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1499 | "%d:0303 Ring %d handler: portRspPut %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | "is bigger then rsp ring %d\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1501 | phba->brd_no, pring->ringno, portRspPut, |
| 1502 | portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1503 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1504 | phba->link_state = LPFC_HBA_ERROR; |
| 1505 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | |
| 1507 | phba->work_hs = HS_FFER3; |
| 1508 | lpfc_handle_eratt(phba); |
| 1509 | |
| 1510 | return 1; |
| 1511 | } |
| 1512 | |
| 1513 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1514 | while (pring->rspidx != portRspPut) { |
| 1515 | /* |
| 1516 | * Build a completion list and call the appropriate handler. |
| 1517 | * The process is to get the next available response iocb, get |
| 1518 | * a free iocb from the list, copy the response data into the |
| 1519 | * free iocb, insert to the continuation list, and update the |
| 1520 | * next response index to slim. This process makes response |
| 1521 | * iocb's in the ring available to DMA as fast as possible but |
| 1522 | * pays a penalty for a copy operation. Since the iocb is |
| 1523 | * only 32 bytes, this penalty is considered small relative to |
| 1524 | * the PCI reads for register values and a slim write. When |
| 1525 | * the ulpLe field is set, the entire Command has been |
| 1526 | * received. |
| 1527 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1528 | entry = lpfc_resp_iocb(phba, pring); |
| 1529 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 1530 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1531 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1532 | if (rspiocbp == NULL) { |
| 1533 | printk(KERN_ERR "%s: out of buffers! Failing " |
| 1534 | "completion.\n", __FUNCTION__); |
| 1535 | break; |
| 1536 | } |
| 1537 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1538 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 1539 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | irsp = &rspiocbp->iocb; |
| 1541 | |
| 1542 | if (++pring->rspidx >= portRspMax) |
| 1543 | pring->rspidx = 0; |
| 1544 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1545 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | |
| 1547 | if (list_empty(&(pring->iocb_continueq))) { |
| 1548 | list_add(&rspiocbp->list, &(pring->iocb_continueq)); |
| 1549 | } else { |
| 1550 | list_add_tail(&rspiocbp->list, |
| 1551 | &(pring->iocb_continueq)); |
| 1552 | } |
| 1553 | |
| 1554 | pring->iocb_continueq_cnt++; |
| 1555 | if (irsp->ulpLe) { |
| 1556 | /* |
| 1557 | * By default, the driver expects to free all resources |
| 1558 | * associated with this iocb completion. |
| 1559 | */ |
| 1560 | free_saveq = 1; |
| 1561 | saveq = list_get_first(&pring->iocb_continueq, |
| 1562 | struct lpfc_iocbq, list); |
| 1563 | irsp = &(saveq->iocb); |
| 1564 | list_del_init(&pring->iocb_continueq); |
| 1565 | pring->iocb_continueq_cnt = 0; |
| 1566 | |
| 1567 | pring->stats.iocb_rsp++; |
| 1568 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1569 | /* |
| 1570 | * If resource errors reported from HBA, reduce |
| 1571 | * queuedepths of the SCSI device. |
| 1572 | */ |
| 1573 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1574 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1575 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1576 | lpfc_adjust_queue_depth(phba); |
| 1577 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1578 | } |
| 1579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | if (irsp->ulpStatus) { |
| 1581 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1582 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 1583 | "%d:0328 Rsp Ring %d error: " |
| 1584 | "IOCB Data: " |
| 1585 | "x%x x%x x%x x%x " |
| 1586 | "x%x x%x x%x x%x " |
| 1587 | "x%x x%x x%x x%x " |
| 1588 | "x%x x%x x%x x%x\n", |
| 1589 | phba->brd_no, |
| 1590 | pring->ringno, |
| 1591 | irsp->un.ulpWord[0], |
| 1592 | irsp->un.ulpWord[1], |
| 1593 | irsp->un.ulpWord[2], |
| 1594 | irsp->un.ulpWord[3], |
| 1595 | irsp->un.ulpWord[4], |
| 1596 | irsp->un.ulpWord[5], |
| 1597 | *(((uint32_t *) irsp) + 6), |
| 1598 | *(((uint32_t *) irsp) + 7), |
| 1599 | *(((uint32_t *) irsp) + 8), |
| 1600 | *(((uint32_t *) irsp) + 9), |
| 1601 | *(((uint32_t *) irsp) + 10), |
| 1602 | *(((uint32_t *) irsp) + 11), |
| 1603 | *(((uint32_t *) irsp) + 12), |
| 1604 | *(((uint32_t *) irsp) + 13), |
| 1605 | *(((uint32_t *) irsp) + 14), |
| 1606 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | /* |
| 1610 | * Fetch the IOCB command type and call the correct |
| 1611 | * completion routine. Solicited and Unsolicited |
| 1612 | * IOCBs on the ELS ring get freed back to the |
| 1613 | * lpfc_iocb_list by the discovery kernel thread. |
| 1614 | */ |
| 1615 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 1616 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 1617 | if (type == LPFC_SOL_IOCB) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1618 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | iflag); |
| 1620 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1621 | saveq); |
| 1622 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1624 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | iflag); |
| 1626 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1627 | saveq); |
| 1628 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | } else if (type == LPFC_ABORT_IOCB) { |
| 1630 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 1631 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1632 | lpfc_sli_iocbq_lookup(phba, pring, |
| 1633 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | /* Call the specified completion |
| 1635 | routine */ |
| 1636 | if (cmdiocbp->iocb_cmpl) { |
| 1637 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1638 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | iflag); |
| 1640 | (cmdiocbp->iocb_cmpl) (phba, |
| 1641 | cmdiocbp, saveq); |
| 1642 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1643 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1645 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1647 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | } |
| 1649 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 1650 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1651 | |
| 1652 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1653 | |
| 1654 | memset(adaptermsg, 0, |
| 1655 | LPFC_MAX_ADPTMSG); |
| 1656 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1657 | MAX_MSG_DATA); |
| 1658 | dev_warn(&((phba->pcidev)->dev), |
| 1659 | "lpfc%d: %s", |
| 1660 | phba->brd_no, adaptermsg); |
| 1661 | } else { |
| 1662 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1663 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 1664 | "%d:0335 Unknown IOCB " |
| 1665 | "command Data: x%x " |
| 1666 | "x%x x%x x%x\n", |
| 1667 | phba->brd_no, |
| 1668 | irsp->ulpCommand, |
| 1669 | irsp->ulpStatus, |
| 1670 | irsp->ulpIoTag, |
| 1671 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 1677 | &saveq->list, list) { |
| 1678 | list_del(&rspiocbp->list); |
| 1679 | __lpfc_sli_release_iocbq(phba, |
| 1680 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1682 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1683 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1684 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | /* |
| 1688 | * If the port response put pointer has not been updated, sync |
| 1689 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 1690 | * response put pointer. |
| 1691 | */ |
| 1692 | if (pring->rspidx == portRspPut) { |
| 1693 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1694 | } |
| 1695 | } /* while (pring->rspidx != portRspPut) */ |
| 1696 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1697 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | /* At least one response entry has been freed */ |
| 1699 | pring->stats.iocb_rsp_full++; |
| 1700 | /* SET RxRE_RSP in Chip Att register */ |
| 1701 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 1702 | writel(status, phba->CAregaddr); |
| 1703 | readl(phba->CAregaddr); /* flush */ |
| 1704 | } |
| 1705 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 1706 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1707 | pring->stats.iocb_cmd_empty++; |
| 1708 | |
| 1709 | /* Force update of the local copy of cmdGetInx */ |
| 1710 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1711 | lpfc_sli_resume_iocb(phba, pring); |
| 1712 | |
| 1713 | if ((pring->lpfc_sli_cmd_available)) |
| 1714 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1715 | |
| 1716 | } |
| 1717 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | return rc; |
| 1720 | } |
| 1721 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1724 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1725 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1727 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1729 | if (pring->ringno == LPFC_ELS_RING) { |
| 1730 | lpfc_fabric_abort_hba(phba); |
| 1731 | } |
| 1732 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | /* Error everything on txq and txcmplq |
| 1734 | * First do the txq. |
| 1735 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1736 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1737 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1739 | |
| 1740 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1741 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 1742 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 1743 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 1745 | |
| 1746 | while (!list_empty(&completions)) { |
| 1747 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | cmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1749 | list_del_init(&iocb->list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | if (!iocb->iocb_cmpl) |
| 1752 | lpfc_sli_release_iocbq(phba, iocb); |
| 1753 | else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 1755 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1759 | } |
| 1760 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1761 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1762 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1764 | uint32_t status; |
| 1765 | int i = 0; |
| 1766 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1767 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1768 | /* Read the HBA Host Status Register */ |
| 1769 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1770 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1771 | /* |
| 1772 | * Check status register every 100ms for 5 retries, then every |
| 1773 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 1774 | * every 2.5 sec for 4. |
| 1775 | * Break our of the loop if errors occurred during init. |
| 1776 | */ |
| 1777 | while (((status & mask) != mask) && |
| 1778 | !(status & HS_FFERM) && |
| 1779 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1780 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1781 | if (i <= 5) |
| 1782 | msleep(10); |
| 1783 | else if (i <= 10) |
| 1784 | msleep(500); |
| 1785 | else |
| 1786 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1788 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1789 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1790 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1791 | lpfc_sli_brdrestart(phba); |
| 1792 | } |
| 1793 | /* Read the HBA Host Status Register */ |
| 1794 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1797 | /* Check to see if any errors occurred during init */ |
| 1798 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1799 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1800 | retval = 1; |
| 1801 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1803 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | } |
| 1805 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1806 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 1807 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1809 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 1810 | uint32_t __iomem *resp_buf; |
| 1811 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1812 | volatile uint32_t mbox; |
| 1813 | uint32_t hc_copy; |
| 1814 | int i; |
| 1815 | uint8_t hdrtype; |
| 1816 | |
| 1817 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 1818 | if (hdrtype != 0x80 || |
| 1819 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 1820 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 1821 | return; |
| 1822 | |
| 1823 | /* |
| 1824 | * Tell the other part of the chip to suspend temporarily all |
| 1825 | * its DMA activity. |
| 1826 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 1827 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1828 | |
| 1829 | /* Disable the error attention */ |
| 1830 | hc_copy = readl(phba->HCregaddr); |
| 1831 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 1832 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1834 | |
| 1835 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 1836 | /* Clear Chip error bit */ |
| 1837 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1838 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | mbox = 0; |
| 1842 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 1843 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 1844 | |
| 1845 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 1846 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1847 | writel(mbox, mbox_buf); |
| 1848 | |
| 1849 | for (i = 0; |
| 1850 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 1851 | mdelay(1); |
| 1852 | |
| 1853 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 1854 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1855 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1856 | goto restore_hc; |
| 1857 | else |
| 1858 | goto clear_errat; |
| 1859 | } |
| 1860 | |
| 1861 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 1862 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 1863 | mdelay(1); |
| 1864 | |
| 1865 | clear_errat: |
| 1866 | |
| 1867 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 1868 | mdelay(1); |
| 1869 | |
| 1870 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 1871 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1872 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1877 | writel(hc_copy, phba->HCregaddr); |
| 1878 | readl(phba->HCregaddr); /* flush */ |
| 1879 | } |
| 1880 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1881 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1882 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1884 | struct lpfc_sli *psli; |
| 1885 | LPFC_MBOXQ_t *pmb; |
| 1886 | uint32_t status; |
| 1887 | uint32_t ha_copy; |
| 1888 | int retval; |
| 1889 | int i = 0; |
| 1890 | |
| 1891 | psli = &phba->sli; |
| 1892 | |
| 1893 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1894 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1895 | "%d:0329 Kill HBA Data: x%x x%x\n", |
| 1896 | phba->brd_no, phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1897 | |
| 1898 | if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1899 | GFP_KERNEL)) == 0) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1900 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1901 | |
| 1902 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1903 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1904 | status = readl(phba->HCregaddr); |
| 1905 | status &= ~HC_ERINT_ENA; |
| 1906 | writel(status, phba->HCregaddr); |
| 1907 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1908 | phba->link_flag |= LS_IGNORE_ERATT; |
| 1909 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1910 | |
| 1911 | lpfc_kill_board(phba, pmb); |
| 1912 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 1913 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1914 | |
| 1915 | if (retval != MBX_SUCCESS) { |
| 1916 | if (retval != MBX_BUSY) |
| 1917 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | spin_lock_irq(&phba->hbalock); |
| 1919 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 1920 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1921 | return 1; |
| 1922 | } |
| 1923 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1924 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 1925 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1926 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1927 | |
| 1928 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 1929 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 1930 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 1931 | * board is now undefined. |
| 1932 | */ |
| 1933 | ha_copy = readl(phba->HAregaddr); |
| 1934 | |
| 1935 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 1936 | mdelay(100); |
| 1937 | ha_copy = readl(phba->HAregaddr); |
| 1938 | } |
| 1939 | |
| 1940 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1941 | if (ha_copy & HA_ERATT) { |
| 1942 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 1944 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1946 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1947 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 1948 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1949 | |
| 1950 | psli->mbox_active = NULL; |
| 1951 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1953 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1959 | { |
| 1960 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1962 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1965 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1967 | /* Reset HBA */ |
| 1968 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1969 | "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1970 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | |
| 1972 | /* perform board reset */ |
| 1973 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1974 | phba->pport->fc_myDID = 0; |
| 1975 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1977 | /* Turn off parity checking and serr during the physical reset */ |
| 1978 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 1979 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 1980 | (cfg_value & |
| 1981 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 1982 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 1983 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1984 | /* Now toggle INITFF bit in the Host Control Register */ |
| 1985 | writel(HC_INITFF, phba->HCregaddr); |
| 1986 | mdelay(1); |
| 1987 | readl(phba->HCregaddr); /* flush */ |
| 1988 | writel(0, phba->HCregaddr); |
| 1989 | readl(phba->HCregaddr); /* flush */ |
| 1990 | |
| 1991 | /* Restore PCI cmd register */ |
| 1992 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | |
| 1994 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1995 | for (i = 0; i < psli->num_rings; i++) { |
| 1996 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | pring->flag = 0; |
| 1998 | pring->rspidx = 0; |
| 1999 | pring->next_cmdidx = 0; |
| 2000 | pring->local_getidx = 0; |
| 2001 | pring->cmdidx = 0; |
| 2002 | pring->missbufcnt = 0; |
| 2003 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2005 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2006 | return 0; |
| 2007 | } |
| 2008 | |
| 2009 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2011 | { |
| 2012 | MAILBOX_t *mb; |
| 2013 | struct lpfc_sli *psli; |
| 2014 | uint16_t skip_post; |
| 2015 | volatile uint32_t word0; |
| 2016 | void __iomem *to_slim; |
| 2017 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2018 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2019 | |
| 2020 | psli = &phba->sli; |
| 2021 | |
| 2022 | /* Restart HBA */ |
| 2023 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2024 | "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2026 | |
| 2027 | word0 = 0; |
| 2028 | mb = (MAILBOX_t *) &word0; |
| 2029 | mb->mbxCommand = MBX_RESTART; |
| 2030 | mb->mbxHc = 1; |
| 2031 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2032 | lpfc_reset_barrier(phba); |
| 2033 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2034 | to_slim = phba->MBslimaddr; |
| 2035 | writel(*(uint32_t *) mb, to_slim); |
| 2036 | readl(to_slim); /* flush */ |
| 2037 | |
| 2038 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2039 | if (phba->pport->port_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2040 | skip_post = 1; |
| 2041 | word0 = 1; /* This is really setting up word1 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | } else { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2043 | skip_post = 0; |
| 2044 | word0 = 0; /* This is really setting up word1 */ |
| 2045 | } |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2046 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2047 | writel(*(uint32_t *) mb, to_slim); |
| 2048 | readl(to_slim); /* flush */ |
| 2049 | |
| 2050 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2051 | phba->pport->stopped = 0; |
| 2052 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2053 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2055 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2056 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2057 | psli->stats_start = get_seconds(); |
| 2058 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2059 | if (skip_post) |
| 2060 | mdelay(100); |
| 2061 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | mdelay(2000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2064 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
| 2069 | static int |
| 2070 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2071 | { |
| 2072 | uint32_t status, i = 0; |
| 2073 | |
| 2074 | /* Read the HBA Host Status Register */ |
| 2075 | status = readl(phba->HSregaddr); |
| 2076 | |
| 2077 | /* Check status register to see what current state is */ |
| 2078 | i = 0; |
| 2079 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2080 | |
| 2081 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2082 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2083 | * 4. |
| 2084 | */ |
| 2085 | if (i++ >= 20) { |
| 2086 | /* Adapter failed to init, timeout, status reg |
| 2087 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | "%d:0436 Adapter failed to init, " |
| 2090 | "timeout, status reg x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2091 | phba->brd_no, status); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2092 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | return -ETIMEDOUT; |
| 2094 | } |
| 2095 | |
| 2096 | /* Check to see if any errors occurred during init */ |
| 2097 | if (status & HS_FFERM) { |
| 2098 | /* ERROR: During chipset initialization */ |
| 2099 | /* Adapter failed to init, chipset, status reg |
| 2100 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2101 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | "%d:0437 Adapter failed to init, " |
| 2103 | "chipset, status reg x%x\n", |
| 2104 | phba->brd_no, |
| 2105 | status); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | return -EIO; |
| 2108 | } |
| 2109 | |
| 2110 | if (i <= 5) { |
| 2111 | msleep(10); |
| 2112 | } else if (i <= 10) { |
| 2113 | msleep(500); |
| 2114 | } else { |
| 2115 | msleep(2500); |
| 2116 | } |
| 2117 | |
| 2118 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2120 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2121 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | } |
| 2123 | /* Read the HBA Host Status Register */ |
| 2124 | status = readl(phba->HSregaddr); |
| 2125 | } |
| 2126 | |
| 2127 | /* Check to see if any errors occurred during init */ |
| 2128 | if (status & HS_FFERM) { |
| 2129 | /* ERROR: During chipset initialization */ |
| 2130 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | "%d:0438 Adapter failed to init, chipset, " |
| 2133 | "status reg x%x\n", |
| 2134 | phba->brd_no, |
| 2135 | status); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | return -EIO; |
| 2138 | } |
| 2139 | |
| 2140 | /* Clear all interrupt enable conditions */ |
| 2141 | writel(0, phba->HCregaddr); |
| 2142 | readl(phba->HCregaddr); /* flush */ |
| 2143 | |
| 2144 | /* setup host attn register */ |
| 2145 | writel(0xffffffff, phba->HAregaddr); |
| 2146 | readl(phba->HAregaddr); /* flush */ |
| 2147 | return 0; |
| 2148 | } |
| 2149 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2150 | static int |
| 2151 | lpfc_sli_hbq_count(void) |
| 2152 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2153 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | static int |
| 2157 | lpfc_sli_hbq_entry_count(void) |
| 2158 | { |
| 2159 | int hbq_count = lpfc_sli_hbq_count(); |
| 2160 | int count = 0; |
| 2161 | int i; |
| 2162 | |
| 2163 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2164 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2165 | return count; |
| 2166 | } |
| 2167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2169 | lpfc_sli_hbq_size(void) |
| 2170 | { |
| 2171 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2172 | } |
| 2173 | |
| 2174 | static int |
| 2175 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2176 | { |
| 2177 | int hbq_count = lpfc_sli_hbq_count(); |
| 2178 | LPFC_MBOXQ_t *pmb; |
| 2179 | MAILBOX_t *pmbox; |
| 2180 | uint32_t hbqno; |
| 2181 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2182 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2183 | /* Get a Mailbox buffer to setup mailbox |
| 2184 | * commands for HBA initialization |
| 2185 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2186 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2187 | |
| 2188 | if (!pmb) |
| 2189 | return -ENOMEM; |
| 2190 | |
| 2191 | pmbox = &pmb->mb; |
| 2192 | |
| 2193 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 2194 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| 2195 | |
| 2196 | hbq_entry_index = 0; |
| 2197 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2198 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 2199 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 2200 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 2201 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2202 | lpfc_hbq_defs[hbqno]->entry_count; |
| 2203 | lpfc_config_hbq(phba, lpfc_hbq_defs[hbqno], hbq_entry_index, |
| 2204 | pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2205 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 2206 | |
| 2207 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 2208 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 2209 | mbxStatus <status>, ring <num> */ |
| 2210 | |
| 2211 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | LOG_SLI | LOG_VPORT, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2213 | "%d:1805 Adapter failed to init. " |
| 2214 | "Data: x%x x%x x%x\n", |
| 2215 | phba->brd_no, pmbox->mbxCommand, |
| 2216 | pmbox->mbxStatus, hbqno); |
| 2217 | |
| 2218 | phba->link_state = LPFC_HBA_ERROR; |
| 2219 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2220 | return ENXIO; |
| 2221 | } |
| 2222 | } |
| 2223 | phba->hbq_count = hbq_count; |
| 2224 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2225 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2226 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2227 | /* Initially populate or replenish the HBQs */ |
| 2228 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2229 | if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno)) |
| 2230 | return -ENOMEM; |
| 2231 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2232 | return 0; |
| 2233 | } |
| 2234 | |
| 2235 | static int |
| 2236 | lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | { |
| 2238 | LPFC_MBOXQ_t *pmb; |
| 2239 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 2240 | |
| 2241 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2242 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2243 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | return -ENOMEM; |
| 2245 | } |
| 2246 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2247 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2249 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2250 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2252 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2253 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | msleep(2500); |
| 2255 | rc = lpfc_sli_chipset_init(phba); |
| 2256 | if (rc) |
| 2257 | break; |
| 2258 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2260 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2261 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | resetcount++; |
| 2263 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2264 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 2265 | * value of 0 means the call was successful. Any other |
| 2266 | * nonzero value is a failure, but if ERESTART is returned, |
| 2267 | * the driver may reset the HBA and try again. |
| 2268 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2269 | rc = lpfc_config_port_prep(phba); |
| 2270 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2271 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | continue; |
| 2273 | } else if (rc) { |
| 2274 | break; |
| 2275 | } |
| 2276 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2277 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | lpfc_config_port(phba, pmb); |
| 2279 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2280 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2282 | "%d:0442 Adapter failed to init, mbxCmd x%x " |
| 2283 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
| 2284 | phba->brd_no, pmb->mb.mbxCommand, |
| 2285 | pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2286 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2288 | spin_unlock_irq(&phba->hbalock); |
| 2289 | rc = -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2290 | } else { |
| 2291 | done = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | phba->max_vpi = (phba->max_vpi && |
| 2293 | pmb->mb.un.varCfgPort.gmv) != 0 |
| 2294 | ? pmb->mb.un.varCfgPort.max_vpi |
| 2295 | : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | } |
| 2297 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2298 | |
| 2299 | if (!done) { |
| 2300 | rc = -EINVAL; |
| 2301 | goto do_prep_failed; |
| 2302 | } |
| 2303 | |
| 2304 | if ((pmb->mb.un.varCfgPort.sli_mode == 3) && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | (!pmb->mb.un.varCfgPort.cMA)) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2306 | rc = -ENXIO; |
| 2307 | goto do_prep_failed; |
| 2308 | } |
| 2309 | return rc; |
| 2310 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2311 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2312 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2313 | return rc; |
| 2314 | } |
| 2315 | |
| 2316 | int |
| 2317 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 2318 | { |
| 2319 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2320 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2321 | |
| 2322 | switch (lpfc_sli_mode) { |
| 2323 | case 2: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2324 | if (phba->cfg_npiv_enable) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
| 2326 | "%d:1824 NPIV enabled: Override lpfc_sli_mode " |
| 2327 | "parameter (%d) to auto (0).\n", |
| 2328 | phba->brd_no, lpfc_sli_mode); |
| 2329 | break; |
| 2330 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2331 | mode = 2; |
| 2332 | break; |
| 2333 | case 0: |
| 2334 | case 3: |
| 2335 | break; |
| 2336 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2337 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2338 | "%d:1819 Unrecognized lpfc_sli_mode " |
| 2339 | "parameter: %d.\n", |
| 2340 | phba->brd_no, lpfc_sli_mode); |
| 2341 | |
| 2342 | break; |
| 2343 | } |
| 2344 | |
| 2345 | rc = lpfc_do_config_port(phba, mode); |
| 2346 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2348 | "%d:1820 Unable to select SLI-3. " |
| 2349 | "Not supported by adapter.\n", |
| 2350 | phba->brd_no); |
| 2351 | if (rc && mode != 2) |
| 2352 | rc = lpfc_do_config_port(phba, 2); |
| 2353 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | goto lpfc_sli_hba_setup_error; |
| 2355 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2356 | if (phba->sli_rev == 3) { |
| 2357 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 2358 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
| 2359 | phba->sli3_options |= LPFC_SLI3_ENABLED; |
| 2360 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 2361 | |
| 2362 | } else { |
| 2363 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 2364 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2365 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2369 | "%d:0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 2370 | phba->brd_no, phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2371 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | |
| 2373 | if (rc) |
| 2374 | goto lpfc_sli_hba_setup_error; |
| 2375 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2376 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2377 | |
| 2378 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 2379 | rc = lpfc_sli_hbq_setup(phba); |
| 2380 | if (rc) |
| 2381 | goto lpfc_sli_hba_setup_error; |
| 2382 | } |
| 2383 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 2385 | |
| 2386 | rc = lpfc_config_port_post(phba); |
| 2387 | if (rc) |
| 2388 | goto lpfc_sli_hba_setup_error; |
| 2389 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2390 | return rc; |
| 2391 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2392 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2393 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2394 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2395 | "%d:0445 Firmware initialization failed\n", |
| 2396 | phba->brd_no); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | return rc; |
| 2398 | } |
| 2399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | /*! lpfc_mbox_timeout |
| 2401 | * |
| 2402 | * \pre |
| 2403 | * \post |
| 2404 | * \param hba Pointer to per struct lpfc_hba structure |
| 2405 | * \param l1 Pointer to the driver's mailbox queue. |
| 2406 | * \return |
| 2407 | * void |
| 2408 | * |
| 2409 | * \b Description: |
| 2410 | * |
| 2411 | * This routine handles mailbox timeout events at timer interrupt context. |
| 2412 | */ |
| 2413 | void |
| 2414 | lpfc_mbox_timeout(unsigned long ptr) |
| 2415 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2416 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2418 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2420 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2421 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2422 | if (!tmo_posted) |
| 2423 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 2424 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 2425 | |
| 2426 | if (!tmo_posted) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2427 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | lpfc_worker_wake_up(phba); |
| 2430 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | void |
| 2435 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 2436 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 2438 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2439 | struct lpfc_sli *psli = &phba->sli; |
| 2440 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | return; |
| 2444 | } |
| 2445 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2447 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2448 | "%d:0310 Mailbox command x%x timeout Data: x%x x%x " |
| 2449 | "x%p\n", |
| 2450 | phba->brd_no, |
| 2451 | mb->mbxCommand, |
| 2452 | phba->pport->port_state, |
| 2453 | phba->sli.sli_flag, |
| 2454 | phba->sli.mbox_active); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2456 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 2457 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 2458 | * it to fail all oustanding SCSI IO. |
| 2459 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | spin_lock_irq(&phba->pport->work_port_lock); |
| 2461 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 2462 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 2463 | spin_lock_irq(&phba->hbalock); |
| 2464 | phba->link_state = LPFC_LINK_UNKNOWN; |
| 2465 | phba->pport->fc_flag |= FC_ESTABLISH_LINK; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2466 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2468 | |
| 2469 | pring = &psli->ring[psli->fcp_ring]; |
| 2470 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2471 | |
| 2472 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2473 | "%d:0316 Resetting board due to mailbox timeout\n", |
| 2474 | phba->brd_no); |
| 2475 | /* |
| 2476 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 2477 | * on oustanding mailbox commands. |
| 2478 | */ |
| 2479 | lpfc_offline_prep(phba); |
| 2480 | lpfc_offline(phba); |
| 2481 | lpfc_sli_brdrestart(phba); |
| 2482 | if (lpfc_online(phba) == 0) /* Initialize the HBA */ |
| 2483 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); |
| 2484 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | return; |
| 2486 | } |
| 2487 | |
| 2488 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2492 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | uint32_t status, evtctr; |
| 2494 | uint32_t ha_copy; |
| 2495 | int i; |
| 2496 | unsigned long drvr_flag = 0; |
| 2497 | volatile uint32_t word0, ldata; |
| 2498 | void __iomem *to_slim; |
| 2499 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2500 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2501 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2502 | if(!pmbox->vport) { |
| 2503 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2504 | LOG_MBOX | LOG_VPORT, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2505 | "%d:1806 Mbox x%x failed. No vport\n", |
| 2506 | phba->brd_no, |
| 2507 | pmbox->mb.mbxCommand); |
| 2508 | dump_stack(); |
| 2509 | return MBXERR_ERROR; |
| 2510 | } |
| 2511 | } |
| 2512 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2513 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2514 | /* If the PCI channel is in offline state, do not post mbox. */ |
| 2515 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 2516 | return MBX_NOT_FINISHED; |
| 2517 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2518 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2520 | |
| 2521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | mb = &pmbox->mb; |
| 2523 | status = MBX_SUCCESS; |
| 2524 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2525 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 2526 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2527 | |
| 2528 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2529 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2530 | return MBX_NOT_FINISHED; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2531 | } |
| 2532 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2533 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 2534 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2535 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2536 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | return MBX_NOT_FINISHED; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2538 | } |
| 2539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 2541 | /* Polling for a mbox command when another one is already active |
| 2542 | * is not allowed in SLI. Also, the driver must have established |
| 2543 | * SLI2 mode to queue and process multiple mbox commands. |
| 2544 | */ |
| 2545 | |
| 2546 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2547 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | |
| 2549 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2550 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2551 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2555 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2557 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2558 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | /* Handle STOP IOCB processing flag. This is only meaningful |
| 2562 | * if we are not polling for mbox completion. |
| 2563 | */ |
| 2564 | if (flag & MBX_STOP_IOCB) { |
| 2565 | flag &= ~MBX_STOP_IOCB; |
| 2566 | /* Now flag each ring */ |
| 2567 | for (i = 0; i < psli->num_rings; i++) { |
| 2568 | /* If the ring is active, flag it */ |
| 2569 | if (psli->ring[i].cmdringaddr) { |
| 2570 | psli->ring[i].flag |= |
| 2571 | LPFC_STOP_IOCB_MBX; |
| 2572 | } |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | /* Another mailbox command is still being processed, queue this |
| 2577 | * command to be processed later. |
| 2578 | */ |
| 2579 | lpfc_mbox_put(phba, pmbox); |
| 2580 | |
| 2581 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2582 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 | "%d (%d):0308 Mbox cmd issue - BUSY Data: " |
| 2584 | "x%x x%x x%x x%x\n", |
| 2585 | phba->brd_no, |
| 2586 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 2587 | mb->mbxCommand, phba->pport->port_state, |
| 2588 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | |
| 2590 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2591 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2593 | if (pmbox->vport) { |
| 2594 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 2595 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2596 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 2597 | (uint32_t)mb->mbxCommand, |
| 2598 | mb->un.varWords[0], mb->un.varWords[1]); |
| 2599 | } |
| 2600 | else { |
| 2601 | lpfc_debugfs_disc_trc(phba->pport, |
| 2602 | LPFC_DISC_TRC_MBOX, |
| 2603 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 2604 | (uint32_t)mb->mbxCommand, |
| 2605 | mb->un.varWords[0], mb->un.varWords[1]); |
| 2606 | } |
| 2607 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2608 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | /* Handle STOP IOCB processing flag. This is only meaningful |
| 2612 | * if we are not polling for mbox completion. |
| 2613 | */ |
| 2614 | if (flag & MBX_STOP_IOCB) { |
| 2615 | flag &= ~MBX_STOP_IOCB; |
| 2616 | if (flag == MBX_NOWAIT) { |
| 2617 | /* Now flag each ring */ |
| 2618 | for (i = 0; i < psli->num_rings; i++) { |
| 2619 | /* If the ring is active, flag it */ |
| 2620 | if (psli->ring[i].cmdringaddr) { |
| 2621 | psli->ring[i].flag |= |
| 2622 | LPFC_STOP_IOCB_MBX; |
| 2623 | } |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 2629 | |
| 2630 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 2631 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2632 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 2633 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2637 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2638 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | } |
| 2640 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 2641 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 2642 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2646 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2647 | "%d (%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
| 2648 | "x%x\n", |
| 2649 | phba->brd_no, pmbox->vport ? pmbox->vport->vpi : 0, |
| 2650 | mb->mbxCommand, phba->pport->port_state, |
| 2651 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2653 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 2654 | if (pmbox->vport) { |
| 2655 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 2656 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2657 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 2658 | (uint32_t)mb->mbxCommand, |
| 2659 | mb->un.varWords[0], mb->un.varWords[1]); |
| 2660 | } |
| 2661 | else { |
| 2662 | lpfc_debugfs_disc_trc(phba->pport, |
| 2663 | LPFC_DISC_TRC_MBOX, |
| 2664 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 2665 | (uint32_t)mb->mbxCommand, |
| 2666 | mb->un.varWords[0], mb->un.varWords[1]); |
| 2667 | } |
| 2668 | } |
| 2669 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | psli->slistat.mbox_cmd++; |
| 2671 | evtctr = psli->slistat.mbox_event; |
| 2672 | |
| 2673 | /* next set own bit for the adapter and copy over command word */ |
| 2674 | mb->mbxOwner = OWN_CHIP; |
| 2675 | |
| 2676 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | /* First copy command data to host SLIM area */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 2678 | lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2680 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | /* copy command data into host mbox for cmpl */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 2682 | lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2683 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | /* First copy mbox command data to HBA SLIM, skip past first |
| 2687 | word */ |
| 2688 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 2689 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 2690 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 2691 | |
| 2692 | /* Next copy over first word, with mbxOwner set */ |
| 2693 | ldata = *((volatile uint32_t *)mb); |
| 2694 | to_slim = phba->MBslimaddr; |
| 2695 | writel(ldata, to_slim); |
| 2696 | readl(to_slim); /* flush */ |
| 2697 | |
| 2698 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 2699 | /* switch over to host mailbox */ |
| 2700 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | wmb(); |
| 2705 | /* interrupt board to doit right away */ |
| 2706 | writel(CA_MBATT, phba->CAregaddr); |
| 2707 | readl(phba->CAregaddr); /* flush */ |
| 2708 | |
| 2709 | switch (flag) { |
| 2710 | case MBX_NOWAIT: |
| 2711 | /* Don't wait for it to finish, just return */ |
| 2712 | psli->mbox_active = pmbox; |
| 2713 | break; |
| 2714 | |
| 2715 | case MBX_POLL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | psli->mbox_active = NULL; |
| 2717 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 2718 | /* First read mbox status word */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 2719 | word0 = *((volatile uint32_t *)&phba->slim2p->mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | word0 = le32_to_cpu(word0); |
| 2721 | } else { |
| 2722 | /* First read mbox status word */ |
| 2723 | word0 = readl(phba->MBslimaddr); |
| 2724 | } |
| 2725 | |
| 2726 | /* Read the HBA Host Attention Register */ |
| 2727 | ha_copy = readl(phba->HAregaddr); |
| 2728 | |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 2729 | i = lpfc_mbox_tmo_val(phba, mb->mbxCommand); |
| 2730 | i *= 1000; /* Convert to ms */ |
| 2731 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2733 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 2734 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2735 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 2736 | if (i-- <= 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | drvr_flag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | /* Check if we took a mbox interrupt while we were |
| 2744 | polling */ |
| 2745 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 2746 | && (evtctr != psli->slistat.mbox_event)) |
| 2747 | break; |
| 2748 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2749 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | drvr_flag); |
| 2751 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2752 | msleep(1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | |
| 2756 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 2757 | /* First copy command data */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 2758 | word0 = *((volatile uint32_t *) |
| 2759 | &phba->slim2p->mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | word0 = le32_to_cpu(word0); |
| 2761 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 2762 | MAILBOX_t *slimmb; |
| 2763 | volatile uint32_t slimword0; |
| 2764 | /* Check real SLIM for any errors */ |
| 2765 | slimword0 = readl(phba->MBslimaddr); |
| 2766 | slimmb = (MAILBOX_t *) & slimword0; |
| 2767 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 2768 | && slimmb->mbxStatus) { |
| 2769 | psli->sli_flag &= |
| 2770 | ~LPFC_SLI2_ACTIVE; |
| 2771 | word0 = slimword0; |
| 2772 | } |
| 2773 | } |
| 2774 | } else { |
| 2775 | /* First copy command data */ |
| 2776 | word0 = readl(phba->MBslimaddr); |
| 2777 | } |
| 2778 | /* Read the HBA Host Attention Register */ |
| 2779 | ha_copy = readl(phba->HAregaddr); |
| 2780 | } |
| 2781 | |
| 2782 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | /* copy results back to user */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 2784 | lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2785 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | } else { |
| 2787 | /* First copy command data */ |
| 2788 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 2789 | MAILBOX_CMD_SIZE); |
| 2790 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 2791 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2792 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 2794 | mb->un.varDmp.word_cnt); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | writel(HA_MBATT, phba->HAregaddr); |
| 2799 | readl(phba->HAregaddr); /* flush */ |
| 2800 | |
| 2801 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 2802 | status = mb->mbxStatus; |
| 2803 | } |
| 2804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2805 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 2806 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | } |
| 2808 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2809 | /* |
| 2810 | * Caller needs to hold lock. |
| 2811 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 2812 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2813 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2814 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | { |
| 2816 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 2817 | list_add_tail(&piocb->list, &pring->txq); |
| 2818 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | static struct lpfc_iocbq * |
| 2822 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | { |
| 2825 | struct lpfc_iocbq * nextiocb; |
| 2826 | |
| 2827 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 2828 | if (!nextiocb) { |
| 2829 | nextiocb = *piocb; |
| 2830 | *piocb = NULL; |
| 2831 | } |
| 2832 | |
| 2833 | return nextiocb; |
| 2834 | } |
| 2835 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2836 | /* |
| 2837 | * Lockless version of lpfc_sli_issue_iocb. |
| 2838 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2840 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 2842 | { |
| 2843 | struct lpfc_iocbq *nextiocb; |
| 2844 | IOCB_t *iocb; |
| 2845 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2846 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 2847 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 2848 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 2849 | lpfc_printf_log(phba, KERN_ERR, |
| 2850 | LOG_SLI | LOG_VPORT, |
| 2851 | "%d:1807 IOCB x%x failed. No vport\n", |
| 2852 | phba->brd_no, |
| 2853 | piocb->iocb.ulpCommand); |
| 2854 | dump_stack(); |
| 2855 | return IOCB_ERROR; |
| 2856 | } |
| 2857 | |
| 2858 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2859 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 2860 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 2861 | return IOCB_ERROR; |
| 2862 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | /* |
| 2864 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 2865 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | return IOCB_ERROR; |
| 2868 | |
| 2869 | /* |
| 2870 | * Check to see if we are blocking IOCB processing because of a |
| 2871 | * outstanding mbox command. |
| 2872 | */ |
| 2873 | if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX)) |
| 2874 | goto iocb_busy; |
| 2875 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2876 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 2878 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | * can be issued if the link is not up. |
| 2880 | */ |
| 2881 | switch (piocb->iocb.ulpCommand) { |
| 2882 | case CMD_QUE_RING_BUF_CN: |
| 2883 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | /* |
| 2885 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 2886 | * completion, iocb_cmpl MUST be 0. |
| 2887 | */ |
| 2888 | if (piocb->iocb_cmpl) |
| 2889 | piocb->iocb_cmpl = NULL; |
| 2890 | /*FALLTHROUGH*/ |
| 2891 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 2892 | case CMD_CLOSE_XRI_CN: |
| 2893 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | break; |
| 2895 | default: |
| 2896 | goto iocb_busy; |
| 2897 | } |
| 2898 | |
| 2899 | /* |
| 2900 | * For FCP commands, we must be in a state where we can process link |
| 2901 | * attention events. |
| 2902 | */ |
| 2903 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2904 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2905 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2906 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 2909 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 2910 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 2911 | |
| 2912 | if (iocb) |
| 2913 | lpfc_sli_update_ring(phba, pring); |
| 2914 | else |
| 2915 | lpfc_sli_update_full_ring(phba, pring); |
| 2916 | |
| 2917 | if (!piocb) |
| 2918 | return IOCB_SUCCESS; |
| 2919 | |
| 2920 | goto out_busy; |
| 2921 | |
| 2922 | iocb_busy: |
| 2923 | pring->stats.iocb_cmd_delay++; |
| 2924 | |
| 2925 | out_busy: |
| 2926 | |
| 2927 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2928 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | return IOCB_SUCCESS; |
| 2930 | } |
| 2931 | |
| 2932 | return IOCB_BUSY; |
| 2933 | } |
| 2934 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2935 | |
| 2936 | int |
| 2937 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2938 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 2939 | { |
| 2940 | unsigned long iflags; |
| 2941 | int rc; |
| 2942 | |
| 2943 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 2944 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 2945 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 2946 | |
| 2947 | return rc; |
| 2948 | } |
| 2949 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 2950 | static int |
| 2951 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 2952 | { |
| 2953 | struct lpfc_sli *psli; |
| 2954 | struct lpfc_sli_ring *pring; |
| 2955 | |
| 2956 | psli = &phba->sli; |
| 2957 | |
| 2958 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2959 | |
| 2960 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 2961 | pring = &psli->ring[psli->fcp_ring]; |
| 2962 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 2963 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 2964 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 2965 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 2966 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2967 | /* and give them to the extra ring */ |
| 2968 | pring = &psli->ring[psli->extra_ring]; |
| 2969 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 2970 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 2971 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 2972 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 2973 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 2974 | |
| 2975 | /* Setup default profile for this ring */ |
| 2976 | pring->iotag_max = 4096; |
| 2977 | pring->num_mask = 1; |
| 2978 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2979 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 2980 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 2981 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 2982 | return 0; |
| 2983 | } |
| 2984 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | int |
| 2986 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 2987 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2988 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | struct lpfc_sli *psli = &phba->sli; |
| 2990 | struct lpfc_sli_ring *pring; |
| 2991 | |
| 2992 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 2993 | psli->sli_flag = 0; |
| 2994 | psli->fcp_ring = LPFC_FCP_RING; |
| 2995 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2996 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2998 | psli->iocbq_lookup = NULL; |
| 2999 | psli->iocbq_lookup_len = 0; |
| 3000 | psli->last_iotag = 0; |
| 3001 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | for (i = 0; i < psli->num_rings; i++) { |
| 3003 | pring = &psli->ring[i]; |
| 3004 | switch (i) { |
| 3005 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 3006 | /* numCiocb and numRiocb are used in config_port */ |
| 3007 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 3008 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 3009 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3010 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3011 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3012 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3013 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3014 | SLI3_IOCB_CMD_SIZE : |
| 3015 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3016 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3017 | SLI3_IOCB_RSP_SIZE : |
| 3018 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | pring->iotag_ctr = 0; |
| 3020 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3021 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | pring->fast_iotag = pring->iotag_max; |
| 3023 | pring->num_mask = 0; |
| 3024 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3025 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | /* numCiocb and numRiocb are used in config_port */ |
| 3027 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 3028 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3029 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3030 | SLI3_IOCB_CMD_SIZE : |
| 3031 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3032 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3033 | SLI3_IOCB_RSP_SIZE : |
| 3034 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | pring->num_mask = 0; |
| 3037 | break; |
| 3038 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 3039 | /* numCiocb and numRiocb are used in config_port */ |
| 3040 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 3041 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3042 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | SLI3_IOCB_CMD_SIZE : |
| 3044 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3045 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3046 | SLI3_IOCB_RSP_SIZE : |
| 3047 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3048 | pring->fast_iotag = 0; |
| 3049 | pring->iotag_ctr = 0; |
| 3050 | pring->iotag_max = 4096; |
| 3051 | pring->num_mask = 4; |
| 3052 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 3053 | pring->prt[0].rctl = FC_ELS_REQ; |
| 3054 | pring->prt[0].type = FC_ELS_DATA; |
| 3055 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3056 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3057 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 3058 | pring->prt[1].rctl = FC_ELS_RSP; |
| 3059 | pring->prt[1].type = FC_ELS_DATA; |
| 3060 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 3063 | /* NameServer Inquiry */ |
| 3064 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 3065 | /* NameServer */ |
| 3066 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 3067 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 3070 | /* NameServer response */ |
| 3071 | pring->prt[3].rctl = FC_SOL_CTL; |
| 3072 | /* NameServer */ |
| 3073 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 3074 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3075 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | break; |
| 3077 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3078 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3079 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3081 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
| 3083 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3084 | "%d:0462 Too many cmd / rsp ring entries in " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3085 | "SLI2 SLIM Data: x%x x%lx\n", |
| 3086 | phba->brd_no, totiocbsize, |
| 3087 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3089 | if (phba->cfg_multi_ring_support == 2) |
| 3090 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | |
| 3092 | return 0; |
| 3093 | } |
| 3094 | |
| 3095 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | { |
| 3098 | struct lpfc_sli *psli; |
| 3099 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3100 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3101 | |
| 3102 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3105 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 3107 | for (i = 0; i < psli->num_rings; i++) { |
| 3108 | pring = &psli->ring[i]; |
| 3109 | pring->ringno = i; |
| 3110 | pring->next_cmdidx = 0; |
| 3111 | pring->local_getidx = 0; |
| 3112 | pring->cmdidx = 0; |
| 3113 | INIT_LIST_HEAD(&pring->txq); |
| 3114 | INIT_LIST_HEAD(&pring->txcmplq); |
| 3115 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 3116 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3118 | spin_unlock_irq(&phba->hbalock); |
| 3119 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3123 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 3124 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3125 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3126 | struct lpfc_hba *phba = vport->phba; |
| 3127 | struct lpfc_sli *psli = &phba->sli; |
| 3128 | struct lpfc_sli_ring *pring; |
| 3129 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3130 | int i; |
| 3131 | unsigned long flags = 0; |
| 3132 | uint16_t prev_pring_flag; |
| 3133 | |
| 3134 | lpfc_cleanup_discovery_resources(vport); |
| 3135 | |
| 3136 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3137 | for (i = 0; i < psli->num_rings; i++) { |
| 3138 | pring = &psli->ring[i]; |
| 3139 | prev_pring_flag = pring->flag; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3140 | if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */ |
| 3141 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3142 | /* |
| 3143 | * Error everything on the txq since these iocbs have not been |
| 3144 | * given to the FW yet. |
| 3145 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3146 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 3147 | if (iocb->vport != vport) |
| 3148 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3149 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3150 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /* Next issue ABTS for everything on the txcmplq */ |
| 3154 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 3155 | list) { |
| 3156 | if (iocb->vport != vport) |
| 3157 | continue; |
| 3158 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3159 | } |
| 3160 | |
| 3161 | pring->flag = prev_pring_flag; |
| 3162 | } |
| 3163 | |
| 3164 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3165 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3166 | while (!list_empty(&completions)) { |
| 3167 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
| 3168 | |
| 3169 | if (!iocb->iocb_cmpl) |
| 3170 | lpfc_sli_release_iocbq(phba, iocb); |
| 3171 | else { |
| 3172 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3173 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; |
| 3174 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 3175 | } |
| 3176 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3177 | return 1; |
| 3178 | } |
| 3179 | |
| 3180 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3183 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3184 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | struct lpfc_sli_ring *pring; |
| 3186 | LPFC_MBOXQ_t *pmb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3187 | struct lpfc_iocbq *iocb; |
| 3188 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3189 | int i; |
| 3190 | unsigned long flags = 0; |
| 3191 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | lpfc_hba_down_prep(phba); |
| 3193 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3194 | lpfc_fabric_abort_hba(phba); |
| 3195 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3196 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | for (i = 0; i < psli->num_rings; i++) { |
| 3198 | pring = &psli->ring[i]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3199 | if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */ |
| 3200 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | |
| 3202 | /* |
| 3203 | * Error everything on the txq since these iocbs have not been |
| 3204 | * given to the FW yet. |
| 3205 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3206 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | pring->txq_cnt = 0; |
| 3208 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3212 | while (!list_empty(&completions)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3213 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3214 | cmd = &iocb->iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3215 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | if (!iocb->iocb_cmpl) |
| 3217 | lpfc_sli_release_iocbq(phba, iocb); |
| 3218 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3219 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3220 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 3221 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3222 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3223 | } |
| 3224 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | /* Return any active mbox cmds */ |
| 3226 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3227 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3228 | |
| 3229 | spin_lock(&phba->pport->work_port_lock); |
| 3230 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3231 | spin_unlock(&phba->pport->work_port_lock); |
| 3232 | |
| 3233 | if (psli->mbox_active) { |
| 3234 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3235 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3236 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3238 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3239 | /* Return any pending or completed mbox cmds */ |
| 3240 | list_splice_init(&phba->sli.mboxq, &completions); |
| 3241 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 3242 | INIT_LIST_HEAD(&psli->mboxq); |
| 3243 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 3244 | |
| 3245 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3246 | |
| 3247 | while (!list_empty(&completions)) { |
| 3248 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3250 | if (pmb->mbox_cmpl) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | } |
| 3253 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | return 1; |
| 3255 | } |
| 3256 | |
| 3257 | void |
| 3258 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 3259 | { |
| 3260 | uint32_t *src = srcp; |
| 3261 | uint32_t *dest = destp; |
| 3262 | uint32_t ldata; |
| 3263 | int i; |
| 3264 | |
| 3265 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 3266 | ldata = *src; |
| 3267 | ldata = le32_to_cpu(ldata); |
| 3268 | *dest = ldata; |
| 3269 | src++; |
| 3270 | dest++; |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3275 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3276 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | { |
| 3278 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 3279 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3280 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3281 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | return 0; |
| 3285 | } |
| 3286 | |
| 3287 | |
| 3288 | struct lpfc_dmabuf * |
| 3289 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3290 | dma_addr_t phys) |
| 3291 | { |
| 3292 | struct lpfc_dmabuf *mp, *next_mp; |
| 3293 | struct list_head *slp = &pring->postbufq; |
| 3294 | |
| 3295 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3296 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 3298 | if (mp->phys == phys) { |
| 3299 | list_del_init(&mp->list); |
| 3300 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3301 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | return mp; |
| 3303 | } |
| 3304 | } |
| 3305 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3306 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3308 | "%d:0410 Cannot find virtual addr for mapped buf on " |
| 3309 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3310 | phba->brd_no, pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3311 | slp->next, slp->prev, pring->postbufq_cnt); |
| 3312 | return NULL; |
| 3313 | } |
| 3314 | |
| 3315 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3316 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3317 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3319 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3320 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3321 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3322 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 3323 | |
| 3324 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3325 | |
| 3326 | if (irsp->ulpStatus) { |
| 3327 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 3328 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 3329 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3330 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3331 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 3332 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 3333 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3334 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
| 3335 | "%d:0327 Cannot abort els iocb %p " |
| 3336 | "with tag %x context %x, abort status %x, " |
| 3337 | "abort code %x\n", |
| 3338 | phba->brd_no, abort_iocb, abort_iotag, |
| 3339 | abort_context, irsp->ulpStatus, |
| 3340 | irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3341 | |
| 3342 | /* |
| 3343 | * make sure we have the right iocbq before taking it |
| 3344 | * off the txcmplq and try to call completion routine. |
| 3345 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3346 | if (!abort_iocb || |
| 3347 | abort_iocb->iocb.ulpContext != abort_context || |
| 3348 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 3349 | spin_unlock_irq(&phba->hbalock); |
| 3350 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3351 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3352 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3353 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3354 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3355 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3356 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3357 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 3358 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3362 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | return; |
| 3364 | } |
| 3365 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3366 | static void |
| 3367 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3368 | struct lpfc_iocbq *rspiocb) |
| 3369 | { |
| 3370 | IOCB_t *irsp = &rspiocb->iocb; |
| 3371 | |
| 3372 | /* ELS cmd tag <ulpIoTag> completes */ |
| 3373 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 3374 | "%d (X):0133 Ignoring ELS cmd tag x%x completion Data: " |
| 3375 | "x%x x%x x%x\n", |
| 3376 | phba->brd_no, irsp->ulpIoTag, irsp->ulpStatus, |
| 3377 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3378 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 3379 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 3380 | else |
| 3381 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3382 | return; |
| 3383 | } |
| 3384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3387 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3390 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | IOCB_t *icmd = NULL; |
| 3392 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3393 | int retval = IOCB_ERROR; |
| 3394 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3395 | /* |
| 3396 | * There are certain command types we don't want to abort. And we |
| 3397 | * don't want to abort commands that are already in the process of |
| 3398 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3399 | */ |
| 3400 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3402 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 3403 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3404 | return 0; |
| 3405 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3406 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 3407 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3408 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3409 | if ((vport->load_flag & FC_UNLOADING) && |
| 3410 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3411 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 3412 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 3413 | else |
| 3414 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3415 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3416 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
| 3418 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3419 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | if (abtsiocbp == NULL) |
| 3421 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3423 | /* This signals the response to set the correct status |
| 3424 | * before calling the completion handler. |
| 3425 | */ |
| 3426 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 3427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3429 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 3430 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 3431 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3432 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3433 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3435 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3436 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 3437 | else |
| 3438 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 3439 | |
| 3440 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3441 | |
| 3442 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3443 | "%d (%d):0339 Abort xri x%x, original iotag x%x, " |
| 3444 | "abort cmd iotag x%x\n", |
| 3445 | phba->brd_no, vport->vpi, |
| 3446 | iabt->un.acxri.abortContextTag, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3447 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3448 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3449 | |
| 3450 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3451 | /* |
| 3452 | * Caller to this routine should check for IOCB_ERROR |
| 3453 | * and handle it properly. This routine no longer removes |
| 3454 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3455 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | static int |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3460 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id, |
| 3461 | uint64_t lun_id, uint32_t ctx, |
| 3462 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3464 | struct lpfc_scsi_buf *lpfc_cmd; |
| 3465 | struct scsi_cmnd *cmnd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | int rc = 1; |
| 3467 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3468 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 3469 | return rc; |
| 3470 | |
| 3471 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 3472 | cmnd = lpfc_cmd->pCmd; |
| 3473 | |
| 3474 | if (cmnd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | return rc; |
| 3476 | |
| 3477 | switch (ctx_cmd) { |
| 3478 | case LPFC_CTX_LUN: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3479 | if ((cmnd->device->id == tgt_id) && |
| 3480 | (cmnd->device->lun == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | rc = 0; |
| 3482 | break; |
| 3483 | case LPFC_CTX_TGT: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3484 | if (cmnd->device->id == tgt_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | rc = 0; |
| 3486 | break; |
| 3487 | case LPFC_CTX_CTX: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3488 | if (iocbq->iocb.ulpContext == ctx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | rc = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3490 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | case LPFC_CTX_HOST: |
| 3492 | rc = 0; |
| 3493 | break; |
| 3494 | default: |
| 3495 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
| 3496 | __FUNCTION__, ctx_cmd); |
| 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | return rc; |
| 3501 | } |
| 3502 | |
| 3503 | int |
| 3504 | lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3505 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3507 | struct lpfc_iocbq *iocbq; |
| 3508 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3510 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 3511 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3513 | if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id, |
| 3514 | 0, ctx_cmd) == 0) |
| 3515 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3517 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | return sum; |
| 3519 | } |
| 3520 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 3521 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3523 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 3524 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3525 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 3526 | return; |
| 3527 | } |
| 3528 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | int |
| 3530 | lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3531 | uint16_t tgt_id, uint64_t lun_id, uint32_t ctx, |
| 3532 | lpfc_ctx_cmd abort_cmd) |
| 3533 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3534 | struct lpfc_iocbq *iocbq; |
| 3535 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3538 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3540 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 3541 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3543 | if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0, |
| 3544 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | continue; |
| 3546 | |
| 3547 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3548 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | if (abtsiocb == NULL) { |
| 3550 | errcnt++; |
| 3551 | continue; |
| 3552 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3553 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3554 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 3556 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 3557 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 3558 | abtsiocb->iocb.ulpLe = 1; |
| 3559 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3560 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3562 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 3564 | else |
| 3565 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 3566 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 3567 | /* Setup callback routine and issue the command. */ |
| 3568 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 3570 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3571 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | errcnt++; |
| 3573 | continue; |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | return errcnt; |
| 3578 | } |
| 3579 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3580 | static void |
| 3581 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 3582 | struct lpfc_iocbq *cmdiocbq, |
| 3583 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3585 | wait_queue_head_t *pdone_q; |
| 3586 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3588 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3589 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 3590 | if (cmdiocbq->context2 && rspiocbq) |
| 3591 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 3592 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 3593 | |
| 3594 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3595 | if (pdone_q) |
| 3596 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3597 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | return; |
| 3599 | } |
| 3600 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3601 | /* |
| 3602 | * Issue the caller's iocb and wait for its completion, but no longer than the |
| 3603 | * caller's timeout. Note that iocb_flags is cleared before the |
| 3604 | * lpfc_sli_issue_call since the wake routine sets a unique value and by |
| 3605 | * definition this is a wait function. |
| 3606 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3607 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3609 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 3610 | struct lpfc_sli_ring *pring, |
| 3611 | struct lpfc_iocbq *piocb, |
| 3612 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3613 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 3615 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3616 | long timeleft, timeout_req = 0; |
| 3617 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3618 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | |
| 3620 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3621 | * If the caller has provided a response iocbq buffer, then context2 |
| 3622 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3624 | if (prspiocbq) { |
| 3625 | if (piocb->context2) |
| 3626 | return IOCB_ERROR; |
| 3627 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | } |
| 3629 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3630 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 3631 | piocb->context_un.wait_queue = &done_q; |
| 3632 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3634 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 3635 | creg_val = readl(phba->HCregaddr); |
| 3636 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 3637 | writel(creg_val, phba->HCregaddr); |
| 3638 | readl(phba->HCregaddr); /* flush */ |
| 3639 | } |
| 3640 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3641 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 3642 | if (retval == IOCB_SUCCESS) { |
| 3643 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3644 | timeleft = wait_event_timeout(done_q, |
| 3645 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 3646 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3648 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 3649 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3650 | "%d:0331 IOCB wake signaled\n", |
| 3651 | phba->brd_no); |
| 3652 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3654 | "%d:0338 IOCB wait timeout error - no " |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3655 | "wake response Data x%x\n", |
| 3656 | phba->brd_no, timeout); |
| 3657 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3658 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3659 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3660 | "%d:0330 IOCB wake NOT set, " |
| 3661 | "Data x%x x%lx\n", phba->brd_no, |
| 3662 | timeout, (timeleft / jiffies)); |
| 3663 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3665 | } else { |
| 3666 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3667 | "%d:0332 IOCB wait issue failed, Data x%x\n", |
| 3668 | phba->brd_no, retval); |
| 3669 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | } |
| 3671 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3672 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 3673 | creg_val = readl(phba->HCregaddr); |
| 3674 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 3675 | writel(creg_val, phba->HCregaddr); |
| 3676 | readl(phba->HCregaddr); /* flush */ |
| 3677 | } |
| 3678 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3679 | if (prspiocbq) |
| 3680 | piocb->context2 = NULL; |
| 3681 | |
| 3682 | piocb->context_un.wait_queue = NULL; |
| 3683 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | return retval; |
| 3685 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3687 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3688 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | uint32_t timeout) |
| 3690 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 3691 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3693 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | |
| 3695 | /* The caller must leave context1 empty. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3696 | if (pmboxq->context1 != 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3697 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | |
| 3699 | /* setup wake call as IOCB callback */ |
| 3700 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 3701 | /* setup context field to pass wait_queue pointer to wake function */ |
| 3702 | pmboxq->context1 = &done_q; |
| 3703 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | /* now issue the command */ |
| 3705 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 3706 | |
| 3707 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3708 | wait_event_interruptible_timeout(done_q, |
| 3709 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 3710 | timeout * HZ); |
| 3711 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3712 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3714 | /* |
| 3715 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 3716 | * else do not free the resources. |
| 3717 | */ |
| 3718 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3720 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3721 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3722 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3723 | } |
| 3724 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
| 3726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | return retval; |
| 3728 | } |
| 3729 | |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 3730 | int |
| 3731 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 3732 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 3734 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3735 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 3736 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3737 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 3738 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 3739 | return 1; |
| 3740 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3741 | /* |
| 3742 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 3743 | * did finish. This way we won't get the misleading |
| 3744 | * "Stray Mailbox Interrupt" message. |
| 3745 | */ |
| 3746 | spin_lock_irq(&phba->hbalock); |
| 3747 | ha_copy = phba->work_ha; |
| 3748 | phba->work_ha &= ~HA_MBATT; |
| 3749 | spin_unlock_irq(&phba->hbalock); |
| 3750 | |
| 3751 | if (ha_copy & HA_MBATT) |
| 3752 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 3753 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 3754 | |
| 3755 | msleep(1); |
| 3756 | } |
| 3757 | |
| 3758 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 3759 | } |
| 3760 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3762 | lpfc_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3764 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | uint32_t ha_copy; |
| 3766 | uint32_t work_ha_copy; |
| 3767 | unsigned long status; |
| 3768 | int i; |
| 3769 | uint32_t control; |
| 3770 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3772 | struct lpfc_vport *vport; |
| 3773 | struct lpfc_nodelist *ndlp; |
| 3774 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3775 | LPFC_MBOXQ_t *pmb; |
| 3776 | int rc; |
| 3777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | /* |
| 3779 | * Get the driver's phba structure from the dev_id and |
| 3780 | * assume the HBA is not interrupting. |
| 3781 | */ |
| 3782 | phba = (struct lpfc_hba *) dev_id; |
| 3783 | |
| 3784 | if (unlikely(!phba)) |
| 3785 | return IRQ_NONE; |
| 3786 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3787 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 3788 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3789 | return IRQ_NONE; |
| 3790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | phba->sli.slistat.sli_intr++; |
| 3792 | |
| 3793 | /* |
| 3794 | * Call the HBA to see if it is interrupting. If not, don't claim |
| 3795 | * the interrupt |
| 3796 | */ |
| 3797 | |
| 3798 | /* Ignore all interrupts during initialization. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | return IRQ_NONE; |
| 3801 | |
| 3802 | /* |
| 3803 | * Read host attention register to determine interrupt source |
| 3804 | * Clear Attention Sources, except Error Attention (to |
| 3805 | * preserve status) and Link Attention |
| 3806 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3807 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | ha_copy = readl(phba->HAregaddr); |
James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 3809 | /* If somebody is waiting to handle an eratt don't process it |
| 3810 | * here. The brdkill function will do this. |
| 3811 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3812 | if (phba->link_flag & LS_IGNORE_ERATT) |
James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 3813 | ha_copy &= ~HA_ERATT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 3815 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3816 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | |
| 3818 | if (unlikely(!ha_copy)) |
| 3819 | return IRQ_NONE; |
| 3820 | |
| 3821 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 3822 | |
| 3823 | if (unlikely(work_ha_copy)) { |
| 3824 | if (work_ha_copy & HA_LATT) { |
| 3825 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 3826 | /* |
| 3827 | * Turn off Link Attention interrupts |
| 3828 | * until CLEAR_LA done |
| 3829 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3830 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 3832 | control = readl(phba->HCregaddr); |
| 3833 | control &= ~HC_LAINT_ENA; |
| 3834 | writel(control, phba->HCregaddr); |
| 3835 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3836 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | } |
| 3838 | else |
| 3839 | work_ha_copy &= ~HA_LATT; |
| 3840 | } |
| 3841 | |
| 3842 | if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3843 | /* |
| 3844 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 3845 | * the only slow ring. |
| 3846 | */ |
| 3847 | status = (work_ha_copy & |
| 3848 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 3849 | status >>= (4*LPFC_ELS_RING); |
| 3850 | if (status & HA_RXMASK) { |
| 3851 | spin_lock(&phba->hbalock); |
| 3852 | control = readl(phba->HCregaddr); |
| 3853 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
| 3854 | control &= |
| 3855 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | writel(control, phba->HCregaddr); |
| 3857 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3859 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | if (work_ha_copy & HA_ERATT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | /* |
| 3866 | * There was a link/board error. Read the |
| 3867 | * status register to retrieve the error event |
| 3868 | * and process it. |
| 3869 | */ |
| 3870 | phba->sli.slistat.err_attn_event++; |
| 3871 | /* Save status info */ |
| 3872 | phba->work_hs = readl(phba->HSregaddr); |
| 3873 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 3874 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 3875 | |
| 3876 | /* Clear Chip error bit */ |
| 3877 | writel(HA_ERATT, phba->HAregaddr); |
| 3878 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3879 | phba->pport->stopped = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | } |
| 3881 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3882 | if ((work_ha_copy & HA_MBATT) && |
| 3883 | (phba->sli.mbox_active)) { |
| 3884 | pmb = phba->sli.mbox_active; |
| 3885 | pmbox = &pmb->mb; |
| 3886 | mbox = &phba->slim2p->mbx; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3887 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3888 | |
| 3889 | /* First check out the status word */ |
| 3890 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 3891 | if (pmbox->mbxOwner != OWN_HOST) { |
| 3892 | /* |
| 3893 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 3894 | * mbxStatus <status> |
| 3895 | */ |
| 3896 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | |
| 3897 | LOG_SLI, |
| 3898 | "%d (%d):0304 Stray Mailbox " |
| 3899 | "Interrupt mbxCommand x%x " |
| 3900 | "mbxStatus x%x\n", |
| 3901 | phba->brd_no, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3902 | (vport |
| 3903 | ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3904 | pmbox->mbxCommand, |
| 3905 | pmbox->mbxStatus); |
| 3906 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3907 | phba->last_completion_time = jiffies; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3908 | del_timer_sync(&phba->sli.mbox_tmo); |
| 3909 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3910 | phba->sli.mbox_active = NULL; |
| 3911 | if (pmb->mbox_cmpl) { |
| 3912 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 3913 | MAILBOX_CMD_SIZE); |
| 3914 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3915 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 3916 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 3917 | |
| 3918 | lpfc_debugfs_disc_trc(vport, |
| 3919 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3920 | "MBOX dflt rpi: : status:x%x rpi:x%x", |
| 3921 | (uint32_t)pmbox->mbxStatus, |
| 3922 | pmbox->un.varWords[0], 0); |
| 3923 | |
| 3924 | if ( !pmbox->mbxStatus) { |
| 3925 | mp = (struct lpfc_dmabuf *) |
| 3926 | (pmb->context1); |
| 3927 | ndlp = (struct lpfc_nodelist *) |
| 3928 | pmb->context2; |
| 3929 | |
| 3930 | /* Reg_LOGIN of dflt RPI was successful. |
| 3931 | * new lets get rid of the RPI using the |
| 3932 | * same mbox buffer. |
| 3933 | */ |
| 3934 | lpfc_unreg_login(phba, vport->vpi, |
| 3935 | pmbox->un.varWords[0], pmb); |
| 3936 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3937 | pmb->context1 = mp; |
| 3938 | pmb->context2 = ndlp; |
| 3939 | pmb->vport = vport; |
| 3940 | spin_lock(&phba->hbalock); |
| 3941 | phba->sli.sli_flag &= |
| 3942 | ~LPFC_SLI_MBOX_ACTIVE; |
| 3943 | spin_unlock(&phba->hbalock); |
| 3944 | goto send_current_mbox; |
| 3945 | } |
| 3946 | } |
| 3947 | spin_lock(&phba->pport->work_port_lock); |
| 3948 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3949 | spin_unlock(&phba->pport->work_port_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3950 | lpfc_mbox_cmpl_put(phba, pmb); |
| 3951 | } |
| 3952 | if ((work_ha_copy & HA_MBATT) && |
| 3953 | (phba->sli.mbox_active == NULL)) { |
| 3954 | send_next_mbox: |
| 3955 | spin_lock(&phba->hbalock); |
| 3956 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3957 | pmb = lpfc_mbox_get(phba); |
| 3958 | spin_unlock(&phba->hbalock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3959 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3960 | /* Process next mailbox command if there is one */ |
| 3961 | if (pmb != NULL) { |
| 3962 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3963 | if (rc == MBX_NOT_FINISHED) { |
| 3964 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3965 | lpfc_mbox_cmpl_put(phba, pmb); |
| 3966 | goto send_next_mbox; |
| 3967 | } |
| 3968 | } else { |
| 3969 | /* Turn on IOCB processing */ |
| 3970 | for (i = 0; i < phba->sli.num_rings; i++) |
| 3971 | lpfc_sli_turn_on_ring(phba, i); |
| 3972 | } |
| 3973 | |
| 3974 | } |
| 3975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | phba->work_ha |= work_ha_copy; |
| 3978 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3979 | lpfc_worker_wake_up(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3980 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | ha_copy &= ~(phba->work_ha_mask); |
| 3984 | |
| 3985 | /* |
| 3986 | * Process all events on FCP ring. Take the optimized path for |
| 3987 | * FCP IO. Any other IO is slow path and is handled by |
| 3988 | * the worker thread. |
| 3989 | */ |
| 3990 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 3991 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 3992 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | lpfc_sli_handle_fast_ring_event(phba, |
| 3994 | &phba->sli.ring[LPFC_FCP_RING], |
| 3995 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3996 | |
| 3997 | if (phba->cfg_multi_ring_support == 2) { |
| 3998 | /* |
| 3999 | * Process all events on extra ring. Take the optimized path |
| 4000 | * for extra ring IO. Any other IO is slow path and is handled |
| 4001 | * by the worker thread. |
| 4002 | */ |
| 4003 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 4004 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame^] | 4005 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4006 | lpfc_sli_handle_fast_ring_event(phba, |
| 4007 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 4008 | status); |
| 4009 | } |
| 4010 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | return IRQ_HANDLED; |
| 4012 | |
| 4013 | } /* lpfc_intr_handler */ |