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