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