| 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 | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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 | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 69 | /** |
| 70 | * lpfc_cmd_iocb: Get next command iocb entry in the ring. |
| 71 | * @phba: Pointer to HBA context object. |
| 72 | * @pring: Pointer to driver SLI ring object. |
| 73 | * |
| 74 | * This function returns pointer to next command iocb entry |
| 75 | * in the command ring. The caller must hold hbalock to prevent |
| 76 | * other threads consume the next command iocb. |
| 77 | * SLI-2/SLI-3 provide different sized iocbs. |
| 78 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 79 | static inline IOCB_t * |
| 80 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 81 | { |
| 82 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 83 | pring->cmdidx * phba->iocb_cmd_size); |
| 84 | } |
| 85 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 86 | /** |
| 87 | * lpfc_resp_iocb: Get next response iocb entry in the ring. |
| 88 | * @phba: Pointer to HBA context object. |
| 89 | * @pring: Pointer to driver SLI ring object. |
| 90 | * |
| 91 | * This function returns pointer to next response iocb entry |
| 92 | * in the response ring. The caller must hold hbalock to make sure |
| 93 | * that no other thread consume the next response iocb. |
| 94 | * SLI-2/SLI-3 provide different sized iocbs. |
| 95 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 96 | static inline IOCB_t * |
| 97 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 98 | { |
| 99 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 100 | pring->rspidx * phba->iocb_rsp_size); |
| 101 | } |
| 102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 103 | /** |
| 104 | * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 105 | * @phba: Pointer to HBA context object. |
| 106 | * |
| 107 | * This function is called with hbalock held. This function |
| 108 | * allocates a new driver iocb object from the iocb pool. If the |
| 109 | * allocation is successful, it returns pointer to the newly |
| 110 | * allocated iocb object else it returns NULL. |
| 111 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 112 | static struct lpfc_iocbq * |
| 113 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 114 | { |
| 115 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 116 | struct lpfc_iocbq * iocbq = NULL; |
| 117 | |
| 118 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 119 | return iocbq; |
| 120 | } |
| 121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | /** |
| 123 | * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 124 | * @phba: Pointer to HBA context object. |
| 125 | * |
| 126 | * This function is called with no lock held. This function |
| 127 | * allocates a new driver iocb object from the iocb pool. If the |
| 128 | * allocation is successful, it returns pointer to the newly |
| 129 | * allocated iocb object else it returns NULL. |
| 130 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 131 | struct lpfc_iocbq * |
| 132 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 133 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 134 | struct lpfc_iocbq * iocbq = NULL; |
| 135 | unsigned long iflags; |
| 136 | |
| 137 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 138 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 139 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 140 | return iocbq; |
| 141 | } |
| 142 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 143 | /** |
| 144 | * __lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 145 | * @phba: Pointer to HBA context object. |
| 146 | * @iocbq: Pointer to driver iocb object. |
| 147 | * |
| 148 | * This function is called with hbalock held to release driver |
| 149 | * iocb object to the iocb pool. The iotag in the iocb object |
| 150 | * does not change for each use of the iocb object. This function |
| 151 | * clears all other fields of the iocb object when it is freed. |
| 152 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 153 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 155 | { |
| 156 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Clean all volatile data fields, preserve iotag and node struct. |
| 160 | */ |
| 161 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 162 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 163 | } |
| 164 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 165 | /** |
| 166 | * lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 167 | * @phba: Pointer to HBA context object. |
| 168 | * @iocbq: Pointer to driver iocb object. |
| 169 | * |
| 170 | * This function is called with no lock held to release the iocb to |
| 171 | * iocb pool. |
| 172 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 173 | void |
| 174 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 175 | { |
| 176 | unsigned long iflags; |
| 177 | |
| 178 | /* |
| 179 | * Clean all volatile data fields, preserve iotag and node struct. |
| 180 | */ |
| 181 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 182 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 183 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 184 | } |
| 185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 186 | /** |
| 187 | * lpfc_sli_iocb_cmd_type: Get the iocb type. |
| 188 | * @iocb_cmnd : iocb command code. |
| 189 | * |
| 190 | * This function is called by ring event handler function to get the iocb type. |
| 191 | * This function translates the iocb command to an iocb command type used to |
| 192 | * decide the final disposition of each completed IOCB. |
| 193 | * The function returns |
| 194 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 195 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 196 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 197 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 198 | * |
| 199 | * The caller is not required to hold any lock. |
| 200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | static lpfc_iocb_type |
| 202 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 203 | { |
| 204 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 205 | |
| 206 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 207 | return 0; |
| 208 | |
| 209 | switch (iocb_cmnd) { |
| 210 | case CMD_XMIT_SEQUENCE_CR: |
| 211 | case CMD_XMIT_SEQUENCE_CX: |
| 212 | case CMD_XMIT_BCAST_CN: |
| 213 | case CMD_XMIT_BCAST_CX: |
| 214 | case CMD_ELS_REQUEST_CR: |
| 215 | case CMD_ELS_REQUEST_CX: |
| 216 | case CMD_CREATE_XRI_CR: |
| 217 | case CMD_CREATE_XRI_CX: |
| 218 | case CMD_GET_RPI_CN: |
| 219 | case CMD_XMIT_ELS_RSP_CX: |
| 220 | case CMD_GET_RPI_CR: |
| 221 | case CMD_FCP_IWRITE_CR: |
| 222 | case CMD_FCP_IWRITE_CX: |
| 223 | case CMD_FCP_IREAD_CR: |
| 224 | case CMD_FCP_IREAD_CX: |
| 225 | case CMD_FCP_ICMND_CR: |
| 226 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 227 | case CMD_FCP_TSEND_CX: |
| 228 | case CMD_FCP_TRSP_CX: |
| 229 | case CMD_FCP_TRECEIVE_CX: |
| 230 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | case CMD_ADAPTER_MSG: |
| 232 | case CMD_ADAPTER_DUMP: |
| 233 | case CMD_XMIT_SEQUENCE64_CR: |
| 234 | case CMD_XMIT_SEQUENCE64_CX: |
| 235 | case CMD_XMIT_BCAST64_CN: |
| 236 | case CMD_XMIT_BCAST64_CX: |
| 237 | case CMD_ELS_REQUEST64_CR: |
| 238 | case CMD_ELS_REQUEST64_CX: |
| 239 | case CMD_FCP_IWRITE64_CR: |
| 240 | case CMD_FCP_IWRITE64_CX: |
| 241 | case CMD_FCP_IREAD64_CR: |
| 242 | case CMD_FCP_IREAD64_CX: |
| 243 | case CMD_FCP_ICMND64_CR: |
| 244 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 245 | case CMD_FCP_TSEND64_CX: |
| 246 | case CMD_FCP_TRSP64_CX: |
| 247 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | case CMD_GEN_REQUEST64_CR: |
| 249 | case CMD_GEN_REQUEST64_CX: |
| 250 | case CMD_XMIT_ELS_RSP64_CX: |
| 251 | type = LPFC_SOL_IOCB; |
| 252 | break; |
| 253 | case CMD_ABORT_XRI_CN: |
| 254 | case CMD_ABORT_XRI_CX: |
| 255 | case CMD_CLOSE_XRI_CN: |
| 256 | case CMD_CLOSE_XRI_CX: |
| 257 | case CMD_XRI_ABORTED_CX: |
| 258 | case CMD_ABORT_MXRI64_CN: |
| 259 | type = LPFC_ABORT_IOCB; |
| 260 | break; |
| 261 | case CMD_RCV_SEQUENCE_CX: |
| 262 | case CMD_RCV_ELS_REQ_CX: |
| 263 | case CMD_RCV_SEQUENCE64_CX: |
| 264 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 265 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 266 | case CMD_IOCB_RCV_SEQ64_CX: |
| 267 | case CMD_IOCB_RCV_ELS64_CX: |
| 268 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 269 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | type = LPFC_UNSOL_IOCB; |
| 271 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 272 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 273 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 274 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 275 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 276 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 277 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 278 | case CMD_IOCB_RET_HBQE64_CN: |
| 279 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 280 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 281 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 282 | case CMD_IOCB_LOGENTRY_CN: |
| 283 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 284 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 285 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 286 | type = LPFC_UNKNOWN_IOCB; |
| 287 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 288 | default: |
| 289 | type = LPFC_UNKNOWN_IOCB; |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | return type; |
| 294 | } |
| 295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 296 | /** |
| 297 | * lpfc_sli_ring_map: Issue config_ring mbox for all rings. |
| 298 | * @phba: Pointer to HBA context object. |
| 299 | * |
| 300 | * This function is called from SLI initialization code |
| 301 | * to configure every ring of the HBA's SLI interface. The |
| 302 | * caller is not required to hold any lock. This function issues |
| 303 | * a config_ring mailbox command for each ring. |
| 304 | * This function returns zero if successful else returns a negative |
| 305 | * error code. |
| 306 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 308 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 309 | { |
| 310 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 311 | LPFC_MBOXQ_t *pmb; |
| 312 | MAILBOX_t *pmbox; |
| 313 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 314 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 315 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 316 | if (!pmb) |
| 317 | return -ENOMEM; |
| 318 | pmbox = &pmb->mb; |
| 319 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | lpfc_config_ring(phba, i, pmb); |
| 322 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 323 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 325 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 326 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 327 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 328 | rc, pmbox->mbxCommand, |
| 329 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 330 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 331 | ret = -ENXIO; |
| 332 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | } |
| 334 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 335 | mempool_free(pmb, phba->mbox_mem_pool); |
| 336 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 337 | } |
| 338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 339 | /** |
| 340 | * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq. |
| 341 | * @phba: Pointer to HBA context object. |
| 342 | * @pring: Pointer to driver SLI ring object. |
| 343 | * @piocb: Pointer to the driver iocb object. |
| 344 | * |
| 345 | * This function is called with hbalock held. The function adds the |
| 346 | * new iocb to txcmplq of the given ring. This function always returns |
| 347 | * 0. If this function is called for ELS ring, this function checks if |
| 348 | * there is a vport associated with the ELS command. This function also |
| 349 | * starts els_tmofunc timer if this is an ELS command. |
| 350 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 351 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 352 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 353 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 356 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 358 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 359 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 360 | if (!piocb->vport) |
| 361 | BUG(); |
| 362 | else |
| 363 | mod_timer(&piocb->vport->els_tmofunc, |
| 364 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 365 | } |
| 366 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 367 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 368 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 369 | } |
| 370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 371 | /** |
| 372 | * lpfc_sli_ringtx_get: Get first element of the txq. |
| 373 | * @phba: Pointer to HBA context object. |
| 374 | * @pring: Pointer to driver SLI ring object. |
| 375 | * |
| 376 | * This function is called with hbalock held to get next |
| 377 | * iocb in txq of the given ring. If there is any iocb in |
| 378 | * the txq, the function returns first iocb in the list after |
| 379 | * removing the iocb from the list, else it returns NULL. |
| 380 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 381 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 382 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 383 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | struct lpfc_iocbq *cmd_iocb; |
| 385 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 386 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 387 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 389 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | } |
| 391 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 392 | /** |
| 393 | * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring. |
| 394 | * @phba: Pointer to HBA context object. |
| 395 | * @pring: Pointer to driver SLI ring object. |
| 396 | * |
| 397 | * This function is called with hbalock held and the caller must post the |
| 398 | * iocb without releasing the lock. If the caller releases the lock, |
| 399 | * iocb slot returned by the function is not guaranteed to be available. |
| 400 | * The function returns pointer to the next available iocb slot if there |
| 401 | * is available slot in the ring, else it returns NULL. |
| 402 | * If the get index of the ring is ahead of the put index, the function |
| 403 | * will post an error attention event to the worker thread to take the |
| 404 | * HBA to offline state. |
| 405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | static IOCB_t * |
| 407 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 408 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 409 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 412 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 413 | pring->next_cmdidx = 0; |
| 414 | |
| 415 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 416 | |
| 417 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 418 | |
| 419 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 420 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 421 | "0315 Ring %d issue: portCmdGet %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | "is bigger then cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 423 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | pring->local_getidx, max_cmd_idx); |
| 425 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 426 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | /* |
| 428 | * All error attention handlers are posted to |
| 429 | * worker thread |
| 430 | */ |
| 431 | phba->work_ha |= HA_ERATT; |
| 432 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 433 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 434 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | |
| 436 | return NULL; |
| 437 | } |
| 438 | |
| 439 | if (pring->local_getidx == pring->next_cmdidx) |
| 440 | return NULL; |
| 441 | } |
| 442 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 443 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | } |
| 445 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 446 | /** |
| 447 | * lpfc_sli_next_iotag: Get an iotag for the iocb. |
| 448 | * @phba: Pointer to HBA context object. |
| 449 | * @iocbq: Pointer to driver iocb object. |
| 450 | * |
| 451 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 452 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 453 | * array and assigns a new iotag. |
| 454 | * The function returns the allocated iotag if successful, else returns zero. |
| 455 | * Zero is not a valid iotag. |
| 456 | * The caller is not required to hold any lock. |
| 457 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 458 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | struct lpfc_iocbq **new_arr; |
| 462 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 463 | size_t new_len; |
| 464 | struct lpfc_sli *psli = &phba->sli; |
| 465 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 466 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 467 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 468 | iotag = psli->last_iotag; |
| 469 | if(++iotag < psli->iocbq_lookup_len) { |
| 470 | psli->last_iotag = iotag; |
| 471 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 472 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 473 | iocbq->iotag = iotag; |
| 474 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 475 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 476 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 477 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | spin_unlock_irq(&phba->hbalock); |
| 479 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 480 | GFP_KERNEL); |
| 481 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 482 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 483 | old_arr = psli->iocbq_lookup; |
| 484 | if (new_len <= psli->iocbq_lookup_len) { |
| 485 | /* highly unprobable case */ |
| 486 | kfree(new_arr); |
| 487 | iotag = psli->last_iotag; |
| 488 | if(++iotag < psli->iocbq_lookup_len) { |
| 489 | psli->last_iotag = iotag; |
| 490 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 491 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 492 | iocbq->iotag = iotag; |
| 493 | return iotag; |
| 494 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 495 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | if (psli->iocbq_lookup) |
| 499 | memcpy(new_arr, old_arr, |
| 500 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 501 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 502 | psli->iocbq_lookup = new_arr; |
| 503 | psli->iocbq_lookup_len = new_len; |
| 504 | psli->last_iotag = iotag; |
| 505 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 507 | iocbq->iotag = iotag; |
| 508 | kfree(old_arr); |
| 509 | return iotag; |
| 510 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 511 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 514 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 515 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 516 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 518 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | } |
| 520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 521 | /** |
| 522 | * lpfc_sli_submit_iocb: Submit an iocb to the firmware. |
| 523 | * @phba: Pointer to HBA context object. |
| 524 | * @pring: Pointer to driver SLI ring object. |
| 525 | * @iocb: Pointer to iocb slot in the ring. |
| 526 | * @nextiocb: Pointer to driver iocb object which need to be |
| 527 | * posted to firmware. |
| 528 | * |
| 529 | * This function is called with hbalock held to post a new iocb to |
| 530 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 531 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 532 | * a completion call back for this iocb else the function will free the |
| 533 | * iocb object. |
| 534 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | static void |
| 536 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 537 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 538 | { |
| 539 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 540 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 542 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 544 | if (pring->ringno == LPFC_ELS_RING) { |
| 545 | lpfc_debugfs_slow_ring_trc(phba, |
| 546 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 547 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 548 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 549 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 550 | } |
| 551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | /* |
| 553 | * Issue iocb command to adapter |
| 554 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 555 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | wmb(); |
| 557 | pring->stats.iocb_cmd++; |
| 558 | |
| 559 | /* |
| 560 | * If there is no completion routine to call, we can release the |
| 561 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 562 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 563 | */ |
| 564 | if (nextiocb->iocb_cmpl) |
| 565 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 566 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 567 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 568 | |
| 569 | /* |
| 570 | * Let the HBA know what IOCB slot will be the next one the |
| 571 | * driver will put a command into. |
| 572 | */ |
| 573 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 574 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 | } |
| 576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 577 | /** |
| 578 | * lpfc_sli_update_full_ring: Update the chip attention register. |
| 579 | * @phba: Pointer to HBA context object. |
| 580 | * @pring: Pointer to driver SLI ring object. |
| 581 | * |
| 582 | * The caller is not required to hold any lock for calling this function. |
| 583 | * This function updates the chip attention bits for the ring to inform firmware |
| 584 | * that there are pending work to be done for this ring and requests an |
| 585 | * interrupt when there is space available in the ring. This function is |
| 586 | * called when the driver is unable to post more iocbs to the ring due |
| 587 | * to unavailability of space in the ring. |
| 588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | { |
| 592 | int ringno = pring->ringno; |
| 593 | |
| 594 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 595 | |
| 596 | wmb(); |
| 597 | |
| 598 | /* |
| 599 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 600 | * The HBA will tell us when an IOCB entry is available. |
| 601 | */ |
| 602 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 603 | readl(phba->CAregaddr); /* flush */ |
| 604 | |
| 605 | pring->stats.iocb_cmd_full++; |
| 606 | } |
| 607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 608 | /** |
| 609 | * lpfc_sli_update_ring: Update chip attention register. |
| 610 | * @phba: Pointer to HBA context object. |
| 611 | * @pring: Pointer to driver SLI ring object. |
| 612 | * |
| 613 | * This function updates the chip attention register bit for the |
| 614 | * given ring to inform HBA that there is more work to be done |
| 615 | * in this ring. The caller is not required to hold any lock. |
| 616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | { |
| 620 | int ringno = pring->ringno; |
| 621 | |
| 622 | /* |
| 623 | * Tell the HBA that there is work to do in this ring. |
| 624 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 625 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 626 | wmb(); |
| 627 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 628 | readl(phba->CAregaddr); /* flush */ |
| 629 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 630 | } |
| 631 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 632 | /** |
| 633 | * lpfc_sli_resume_iocb: Process iocbs in the txq. |
| 634 | * @phba: Pointer to HBA context object. |
| 635 | * @pring: Pointer to driver SLI ring object. |
| 636 | * |
| 637 | * This function is called with hbalock held to post pending iocbs |
| 638 | * in the txq to the firmware. This function is called when driver |
| 639 | * detects space available in the ring. |
| 640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 642 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | { |
| 644 | IOCB_t *iocb; |
| 645 | struct lpfc_iocbq *nextiocb; |
| 646 | |
| 647 | /* |
| 648 | * Check to see if: |
| 649 | * (a) there is anything on the txq to send |
| 650 | * (b) link is up |
| 651 | * (c) link attention events can be processed (fcp ring only) |
| 652 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 653 | */ |
| 654 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 657 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
| 659 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 660 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 661 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 662 | |
| 663 | if (iocb) |
| 664 | lpfc_sli_update_ring(phba, pring); |
| 665 | else |
| 666 | lpfc_sli_update_full_ring(phba, pring); |
| 667 | } |
| 668 | |
| 669 | return; |
| 670 | } |
| 671 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 672 | /** |
| 673 | * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ. |
| 674 | * @phba: Pointer to HBA context object. |
| 675 | * @hbqno: HBQ number. |
| 676 | * |
| 677 | * This function is called with hbalock held to get the next |
| 678 | * available slot for the given HBQ. If there is free slot |
| 679 | * available for the HBQ it will return pointer to the next available |
| 680 | * HBQ entry else it will return NULL. |
| 681 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 682 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 683 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 684 | { |
| 685 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 686 | |
| 687 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 688 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 689 | hbqp->next_hbqPutIdx = 0; |
| 690 | |
| 691 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 692 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 693 | uint32_t getidx = le32_to_cpu(raw_index); |
| 694 | |
| 695 | hbqp->local_hbqGetIdx = getidx; |
| 696 | |
| 697 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 698 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 699 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 700 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 701 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 702 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 703 | hbqp->entry_count); |
| 704 | |
| 705 | phba->link_state = LPFC_HBA_ERROR; |
| 706 | return NULL; |
| 707 | } |
| 708 | |
| 709 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 710 | return NULL; |
| 711 | } |
| 712 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 713 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 714 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 715 | } |
| 716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 717 | /** |
| 718 | * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers. |
| 719 | * @phba: Pointer to HBA context object. |
| 720 | * |
| 721 | * This function is called with no lock held to free all the |
| 722 | * hbq buffers while uninitializing the SLI interface. It also |
| 723 | * frees the HBQ buffers returned by the firmware but not yet |
| 724 | * processed by the upper layers. |
| 725 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 726 | void |
| 727 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 728 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 729 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 730 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 731 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 732 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 733 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 734 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 735 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 736 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 737 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 738 | for (i = 0; i < hbq_count; ++i) { |
| 739 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 740 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 741 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 742 | list_del(&hbq_buf->dbuf.list); |
| 743 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 744 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 745 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 746 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 747 | /* Return all HBQ buffer that are in-fly */ |
| 748 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 749 | &phba->hbqbuf_in_list, list) { |
| 750 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 751 | list_del(&hbq_buf->dbuf.list); |
| 752 | if (hbq_buf->tag == -1) { |
| 753 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 754 | (phba, hbq_buf); |
| 755 | } else { |
| 756 | hbqno = hbq_buf->tag >> 16; |
| 757 | if (hbqno >= LPFC_MAX_HBQS) |
| 758 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 759 | (phba, hbq_buf); |
| 760 | else |
| 761 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 762 | hbq_buf); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* Mark the HBQs not in use */ |
| 767 | phba->hbq_in_use = 0; |
| 768 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 769 | } |
| 770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 771 | /** |
| 772 | * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware. |
| 773 | * @phba: Pointer to HBA context object. |
| 774 | * @hbqno: HBQ number. |
| 775 | * @hbq_buf: Pointer to HBQ buffer. |
| 776 | * |
| 777 | * This function is called with the hbalock held to post a |
| 778 | * hbq buffer to the firmware. If the function finds an empty |
| 779 | * slot in the HBQ, it will post the buffer. The function will return |
| 780 | * pointer to the hbq entry if it successfully post the buffer |
| 781 | * else it will return NULL. |
| 782 | **/ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 783 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 784 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 785 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | { |
| 787 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 789 | |
| 790 | /* Get next HBQ entry slot to use */ |
| 791 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 792 | if (hbqe) { |
| 793 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 794 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 795 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 796 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 797 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 798 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 799 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 800 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 801 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 802 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 803 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 804 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 805 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 806 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 807 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 808 | return hbqe; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 809 | } |
| 810 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 811 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 812 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 813 | .rn = 1, |
| 814 | .entry_count = 200, |
| 815 | .mask_count = 0, |
| 816 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 817 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | .buffer_count = 0, |
| 819 | .init_count = 20, |
| 820 | .add_count = 5, |
| 821 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 822 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 823 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 824 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 825 | .rn = 1, |
| 826 | .entry_count = 200, |
| 827 | .mask_count = 0, |
| 828 | .profile = 0, |
| 829 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 830 | .buffer_count = 0, |
| 831 | .init_count = 0, |
| 832 | .add_count = 5, |
| 833 | }; |
| 834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 835 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 836 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 838 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 839 | }; |
| 840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 841 | /** |
| 842 | * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ. |
| 843 | * @phba: Pointer to HBA context object. |
| 844 | * @hbqno: HBQ number. |
| 845 | * @count: Number of HBQ buffers to be posted. |
| 846 | * |
| 847 | * This function is called with no lock held to post more |
| 848 | * hbq buffers to the given HBQ. The function returns 0 |
| 849 | * when successful and returns 1 other wise. |
| 850 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 851 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 852 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 853 | { |
| 854 | uint32_t i, start, end; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 855 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 856 | struct hbq_dmabuf *hbq_buffer; |
| 857 | |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 858 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 859 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 860 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 861 | start = phba->hbqs[hbqno].buffer_count; |
| 862 | end = count + start; |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 863 | if (end > lpfc_hbq_defs[hbqno]->entry_count) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 864 | end = lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 865 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 866 | /* Check whether HBQ is still in use */ |
| 867 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 868 | if (!phba->hbq_in_use) |
| 869 | goto out; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 870 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 871 | /* Populate HBQ entries */ |
| 872 | for (i = start; i < end; i++) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 873 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 874 | if (!hbq_buffer) |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 875 | goto err; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 876 | hbq_buffer->tag = (i | (hbqno << 16)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 877 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 878 | phba->hbqs[hbqno].buffer_count++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 879 | else |
| 880 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 881 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 882 | |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 883 | out: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 884 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 885 | return 0; |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 886 | err: |
| 887 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 888 | return 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 889 | } |
| 890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 891 | /** |
| 892 | * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware. |
| 893 | * @phba: Pointer to HBA context object. |
| 894 | * @qno: HBQ number. |
| 895 | * |
| 896 | * This function posts more buffers to the HBQ. This function |
| 897 | * is called with no lock held. The function returns 0 when |
| 898 | * successful and returns 1 otherwise. |
| 899 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 900 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 901 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 902 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 903 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 904 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 905 | } |
| 906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 907 | /** |
| 908 | * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ. |
| 909 | * @phba: Pointer to HBA context object. |
| 910 | * @qno: HBQ queue number. |
| 911 | * |
| 912 | * This function is called from SLI initialization code path with |
| 913 | * no lock held to post initial HBQ buffers to firmware. The |
| 914 | * function returns 0 when successful and returns 1 otherwise. |
| 915 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 916 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 917 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 918 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 919 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 920 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 921 | } |
| 922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 923 | /** |
| 924 | * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag. |
| 925 | * @phba: Pointer to HBA context object. |
| 926 | * @tag: Tag of the hbq buffer. |
| 927 | * |
| 928 | * This function is called with hbalock held. This function searches |
| 929 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 930 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 931 | * it returns NULL. |
| 932 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 933 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 934 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 935 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 936 | struct lpfc_dmabuf *d_buf; |
| 937 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 938 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 939 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 940 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 941 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 942 | return NULL; |
| 943 | |
| 944 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 945 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 946 | if (hbq_buf->tag == tag) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 948 | } |
| 949 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 950 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 951 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 952 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 953 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 954 | } |
| 955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 956 | /** |
| 957 | * lpfc_sli_free_hbq: Give back the hbq buffer to firmware. |
| 958 | * @phba: Pointer to HBA context object. |
| 959 | * @hbq_buffer: Pointer to HBQ buffer. |
| 960 | * |
| 961 | * This function is called with hbalock. This function gives back |
| 962 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 963 | * post the buffer, it will free the buffer. |
| 964 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 965 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 966 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 967 | { |
| 968 | uint32_t hbqno; |
| 969 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 970 | if (hbq_buffer) { |
| 971 | hbqno = hbq_buffer->tag >> 16; |
| 972 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
| 973 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 974 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 978 | /** |
| 979 | * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox. |
| 980 | * @mbxCommand: mailbox command code. |
| 981 | * |
| 982 | * This function is called by the mailbox event handler function to verify |
| 983 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 984 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 985 | * and the mailbox event handler will take the HBA offline. |
| 986 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | static int |
| 988 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 989 | { |
| 990 | uint8_t ret; |
| 991 | |
| 992 | switch (mbxCommand) { |
| 993 | case MBX_LOAD_SM: |
| 994 | case MBX_READ_NV: |
| 995 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 996 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | case MBX_RUN_BIU_DIAG: |
| 998 | case MBX_INIT_LINK: |
| 999 | case MBX_DOWN_LINK: |
| 1000 | case MBX_CONFIG_LINK: |
| 1001 | case MBX_CONFIG_RING: |
| 1002 | case MBX_RESET_RING: |
| 1003 | case MBX_READ_CONFIG: |
| 1004 | case MBX_READ_RCONFIG: |
| 1005 | case MBX_READ_SPARM: |
| 1006 | case MBX_READ_STATUS: |
| 1007 | case MBX_READ_RPI: |
| 1008 | case MBX_READ_XRI: |
| 1009 | case MBX_READ_REV: |
| 1010 | case MBX_READ_LNK_STAT: |
| 1011 | case MBX_REG_LOGIN: |
| 1012 | case MBX_UNREG_LOGIN: |
| 1013 | case MBX_READ_LA: |
| 1014 | case MBX_CLEAR_LA: |
| 1015 | case MBX_DUMP_MEMORY: |
| 1016 | case MBX_DUMP_CONTEXT: |
| 1017 | case MBX_RUN_DIAGS: |
| 1018 | case MBX_RESTART: |
| 1019 | case MBX_UPDATE_CFG: |
| 1020 | case MBX_DOWN_LOAD: |
| 1021 | case MBX_DEL_LD_ENTRY: |
| 1022 | case MBX_RUN_PROGRAM: |
| 1023 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1024 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1026 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1027 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1028 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | case MBX_LOAD_AREA: |
| 1030 | case MBX_RUN_BIU_DIAG64: |
| 1031 | case MBX_CONFIG_PORT: |
| 1032 | case MBX_READ_SPARM64: |
| 1033 | case MBX_READ_RPI64: |
| 1034 | case MBX_REG_LOGIN64: |
| 1035 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1036 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | case MBX_SET_DEBUG: |
| 1038 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1039 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1040 | case MBX_REG_VPI: |
| 1041 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1042 | case MBX_HEARTBEAT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | ret = mbxCommand; |
| 1044 | break; |
| 1045 | default: |
| 1046 | ret = MBX_SHUTDOWN; |
| 1047 | break; |
| 1048 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1051 | |
| 1052 | /** |
| 1053 | * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from |
| 1054 | * lpfc_sli_issue_mbox_wait. |
| 1055 | * @phba: Pointer to HBA context object. |
| 1056 | * @pmboxq: Pointer to mailbox command. |
| 1057 | * |
| 1058 | * This is completion handler function for mailbox commands issued from |
| 1059 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1060 | * mailbox event handler function with no lock held. This function |
| 1061 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1062 | * of the mailbox. |
| 1063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1065 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | { |
| 1067 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1068 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | |
| 1070 | /* |
| 1071 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1072 | * continued running. |
| 1073 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1074 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1075 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1077 | if (pdone_q) |
| 1078 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1079 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | return; |
| 1081 | } |
| 1082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1083 | |
| 1084 | /** |
| 1085 | * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler. |
| 1086 | * @phba: Pointer to HBA context object. |
| 1087 | * @pmb: Pointer to mailbox object. |
| 1088 | * |
| 1089 | * This function is the default mailbox completion handler. It |
| 1090 | * frees the memory resources associated with the completed mailbox |
| 1091 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1092 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1093 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1095 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | { |
| 1097 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1098 | uint16_t rpi; |
| 1099 | int rc; |
| 1100 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1103 | if (mp) { |
| 1104 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1105 | kfree(mp); |
| 1106 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1107 | |
| 1108 | /* |
| 1109 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1110 | * is in re-discovery driver need to cleanup the RPI. |
| 1111 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1112 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1113 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1114 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1115 | |
| 1116 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1117 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1118 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1119 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1120 | if (rc != MBX_NOT_FINISHED) |
| 1121 | return; |
| 1122 | } |
| 1123 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1124 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | return; |
| 1126 | } |
| 1127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1128 | /** |
| 1129 | * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware. |
| 1130 | * @phba: Pointer to HBA context object. |
| 1131 | * |
| 1132 | * This function is called with no lock held. This function processes all |
| 1133 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1134 | * service routine processes mailbox completion interrupt and adds completed |
| 1135 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1136 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1137 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1138 | * function returns the mailbox commands to the upper layer by calling the |
| 1139 | * completion handler function of each mailbox. |
| 1140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1142 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1144 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1145 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1146 | int rc; |
| 1147 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1148 | |
| 1149 | phba->sli.slistat.mbox_event++; |
| 1150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1151 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1152 | spin_lock_irq(&phba->hbalock); |
| 1153 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1154 | spin_unlock_irq(&phba->hbalock); |
| 1155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1157 | do { |
| 1158 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1159 | if (pmb == NULL) |
| 1160 | break; |
| 1161 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1164 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1165 | if (pmb->vport) { |
| 1166 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1167 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1168 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1169 | (uint32_t)pmbox->mbxCommand, |
| 1170 | pmbox->un.varWords[0], |
| 1171 | pmbox->un.varWords[1]); |
| 1172 | } |
| 1173 | else { |
| 1174 | lpfc_debugfs_disc_trc(phba->pport, |
| 1175 | LPFC_DISC_TRC_MBOX, |
| 1176 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1177 | (uint32_t)pmbox->mbxCommand, |
| 1178 | pmbox->un.varWords[0], |
| 1179 | pmbox->un.varWords[1]); |
| 1180 | } |
| 1181 | } |
| 1182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | /* |
| 1184 | * It is a fatal error if unknown mbox command completion. |
| 1185 | */ |
| 1186 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1187 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1189 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1190 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1191 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1192 | pmb->vport ? pmb->vport->vpi : 0, |
| 1193 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1194 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | phba->work_hs = HS_FFER3; |
| 1196 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1197 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | } |
| 1199 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | if (pmbox->mbxStatus) { |
| 1201 | phba->sli.slistat.mbox_stat_err++; |
| 1202 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1203 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1204 | lpfc_printf_log(phba, KERN_INFO, |
| 1205 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1206 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1207 | "error - RETRYing Data: x%x " |
| 1208 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1209 | pmb->vport ? pmb->vport->vpi :0, |
| 1210 | pmbox->mbxCommand, |
| 1211 | pmbox->mbxStatus, |
| 1212 | pmbox->un.varWords[0], |
| 1213 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | pmbox->mbxStatus = 0; |
| 1215 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1218 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1220 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1221 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1226 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1227 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | "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] | 1229 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | pmbox->mbxCommand, |
| 1231 | pmb->mbox_cmpl, |
| 1232 | *((uint32_t *) pmbox), |
| 1233 | pmbox->un.varWords[0], |
| 1234 | pmbox->un.varWords[1], |
| 1235 | pmbox->un.varWords[2], |
| 1236 | pmbox->un.varWords[3], |
| 1237 | pmbox->un.varWords[4], |
| 1238 | pmbox->un.varWords[5], |
| 1239 | pmbox->un.varWords[6], |
| 1240 | pmbox->un.varWords[7]); |
| 1241 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1242 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1244 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1245 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1248 | /** |
| 1249 | * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer. |
| 1250 | * @phba: Pointer to HBA context object. |
| 1251 | * @tag: Tag for the HBQ buffer. |
| 1252 | * |
| 1253 | * This function is called from unsolicited event handler code path to get the |
| 1254 | * HBQ buffer associated with an unsolicited iocb. This function is called with |
| 1255 | * no lock held. It returns the buffer associated with the given tag and posts |
| 1256 | * another buffer to the firmware. |
| 1257 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1258 | static struct lpfc_dmabuf * |
| 1259 | lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) |
| 1260 | { |
| 1261 | struct hbq_dmabuf *hbq_entry, *new_hbq_entry; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1262 | uint32_t hbqno; |
| 1263 | void *virt; /* virtual address ptr */ |
| 1264 | dma_addr_t phys; /* mapped address */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1265 | unsigned long flags; |
| 1266 | |
| 1267 | /* Check whether HBQ is still in use */ |
| 1268 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1269 | if (!phba->hbq_in_use) { |
| 1270 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1271 | return NULL; |
| 1272 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1273 | |
| 1274 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1275 | if (hbq_entry == NULL) { |
| 1276 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1277 | return NULL; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1278 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1279 | list_del(&hbq_entry->dbuf.list); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1280 | |
| 1281 | hbqno = tag >> 16; |
| 1282 | new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1283 | if (new_hbq_entry == NULL) { |
| 1284 | list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1285 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1286 | return &hbq_entry->dbuf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1287 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1288 | new_hbq_entry->tag = -1; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1289 | phys = new_hbq_entry->dbuf.phys; |
| 1290 | virt = new_hbq_entry->dbuf.virt; |
| 1291 | new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys; |
| 1292 | new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt; |
| 1293 | hbq_entry->dbuf.phys = phys; |
| 1294 | hbq_entry->dbuf.virt = virt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1295 | lpfc_sli_free_hbq(phba, hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1296 | list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1297 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1298 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1299 | return &new_hbq_entry->dbuf; |
| 1300 | } |
| 1301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1302 | /** |
| 1303 | * lpfc_sli_get_buff: Get the buffer associated with the buffer tag. |
| 1304 | * @phba: Pointer to HBA context object. |
| 1305 | * @pring: Pointer to driver SLI ring object. |
| 1306 | * @tag: buffer tag. |
| 1307 | * |
| 1308 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1309 | * is set in the tag the buffer is posted for a particular exchange, |
| 1310 | * the function will return the buffer without replacing the buffer. |
| 1311 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1312 | * returns the buffer and also posts another buffer to the firmware. |
| 1313 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1314 | static struct lpfc_dmabuf * |
| 1315 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
| 1316 | struct lpfc_sli_ring *pring, |
| 1317 | uint32_t tag) |
| 1318 | { |
| 1319 | if (tag & QUE_BUFTAG_BIT) |
| 1320 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
| 1321 | else |
| 1322 | return lpfc_sli_replace_hbqbuff(phba, tag); |
| 1323 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1324 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1325 | |
| 1326 | /** |
| 1327 | * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler. |
| 1328 | * @phba: Pointer to HBA context object. |
| 1329 | * @pring: Pointer to driver SLI ring object. |
| 1330 | * @saveq: Pointer to the unsolicited iocb. |
| 1331 | * |
| 1332 | * This function is called with no lock held by the ring event handler |
| 1333 | * when there is an unsolicited iocb posted to the response ring by the |
| 1334 | * firmware. This function gets the buffer associated with the iocbs |
| 1335 | * and calls the event handler for the ring. This function handles both |
| 1336 | * qring buffers and hbq buffers. |
| 1337 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1338 | * upper layer functions will free the iocb objects. |
| 1339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | static int |
| 1341 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1342 | struct lpfc_iocbq *saveq) |
| 1343 | { |
| 1344 | IOCB_t * irsp; |
| 1345 | WORD5 * w5p; |
| 1346 | uint32_t Rctl, Type; |
| 1347 | uint32_t match, i; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1348 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1349 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1350 | |
| 1351 | match = 0; |
| 1352 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1353 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1354 | if (irsp->ulpStatus == IOSTAT_NEED_BUFFER) |
| 1355 | return 1; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1356 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1357 | if (pring->lpfc_sli_rcv_async_status) |
| 1358 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1359 | else |
| 1360 | lpfc_printf_log(phba, |
| 1361 | KERN_WARNING, |
| 1362 | LOG_SLI, |
| 1363 | "0316 Ring %d handler: unexpected " |
| 1364 | "ASYNC_STATUS iocb received evt_code " |
| 1365 | "0x%x\n", |
| 1366 | pring->ringno, |
| 1367 | irsp->un.asyncstat.evt_code); |
| 1368 | return 1; |
| 1369 | } |
| 1370 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1371 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1372 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1373 | if (irsp->ulpBdeCount > 0) { |
| 1374 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1375 | irsp->un.ulpWord[3]); |
| 1376 | lpfc_in_buf_free(phba, dmzbuf); |
| 1377 | } |
| 1378 | |
| 1379 | if (irsp->ulpBdeCount > 1) { |
| 1380 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1381 | irsp->unsli3.sli3Words[3]); |
| 1382 | lpfc_in_buf_free(phba, dmzbuf); |
| 1383 | } |
| 1384 | |
| 1385 | if (irsp->ulpBdeCount > 2) { |
| 1386 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1387 | irsp->unsli3.sli3Words[7]); |
| 1388 | lpfc_in_buf_free(phba, dmzbuf); |
| 1389 | } |
| 1390 | |
| 1391 | return 1; |
| 1392 | } |
| 1393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1394 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1395 | if (irsp->ulpBdeCount != 0) { |
| 1396 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1397 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1398 | if (!saveq->context2) |
| 1399 | lpfc_printf_log(phba, |
| 1400 | KERN_ERR, |
| 1401 | LOG_SLI, |
| 1402 | "0341 Ring %d Cannot find buffer for " |
| 1403 | "an unsolicited iocb. tag 0x%x\n", |
| 1404 | pring->ringno, |
| 1405 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1406 | } |
| 1407 | if (irsp->ulpBdeCount == 2) { |
| 1408 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1409 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1410 | if (!saveq->context3) |
| 1411 | lpfc_printf_log(phba, |
| 1412 | KERN_ERR, |
| 1413 | LOG_SLI, |
| 1414 | "0342 Ring %d Cannot find buffer for an" |
| 1415 | " unsolicited iocb. tag 0x%x\n", |
| 1416 | pring->ringno, |
| 1417 | irsp->unsli3.sli3Words[7]); |
| 1418 | } |
| 1419 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1420 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1421 | if (irsp->ulpBdeCount != 0) { |
| 1422 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1423 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1424 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1425 | lpfc_printf_log(phba, |
| 1426 | KERN_ERR, |
| 1427 | LOG_SLI, |
| 1428 | "0343 Ring %d Cannot find " |
| 1429 | "buffer for an unsolicited iocb" |
| 1430 | ". tag 0x%x\n", pring->ringno, |
| 1431 | irsp->un.ulpWord[3]); |
| 1432 | } |
| 1433 | if (irsp->ulpBdeCount == 2) { |
| 1434 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1435 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1436 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1437 | lpfc_printf_log(phba, |
| 1438 | KERN_ERR, |
| 1439 | LOG_SLI, |
| 1440 | "0344 Ring %d Cannot find " |
| 1441 | "buffer for an unsolicited " |
| 1442 | "iocb. tag 0x%x\n", |
| 1443 | pring->ringno, |
| 1444 | irsp->unsli3.sli3Words[7]); |
| 1445 | } |
| 1446 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1447 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1448 | if (irsp->ulpBdeCount != 0 && |
| 1449 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1450 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1451 | int found = 0; |
| 1452 | |
| 1453 | /* search continue save q for same XRI */ |
| 1454 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1455 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1456 | list_add_tail(&saveq->list, &iocbq->list); |
| 1457 | found = 1; |
| 1458 | break; |
| 1459 | } |
| 1460 | } |
| 1461 | if (!found) |
| 1462 | list_add_tail(&saveq->clist, |
| 1463 | &pring->iocb_continue_saveq); |
| 1464 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1465 | list_del_init(&iocbq->clist); |
| 1466 | saveq = iocbq; |
| 1467 | irsp = &(saveq->iocb); |
| 1468 | } else |
| 1469 | return 0; |
| 1470 | } |
| 1471 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1472 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1473 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1474 | Rctl = FC_ELS_REQ; |
| 1475 | Type = FC_ELS_DATA; |
| 1476 | } else { |
| 1477 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1478 | Rctl = w5p->hcsw.Rctl; |
| 1479 | Type = w5p->hcsw.Type; |
| 1480 | |
| 1481 | /* Firmware Workaround */ |
| 1482 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1483 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1484 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1485 | Rctl = FC_ELS_REQ; |
| 1486 | Type = FC_ELS_DATA; |
| 1487 | w5p->hcsw.Rctl = Rctl; |
| 1488 | w5p->hcsw.Type = Type; |
| 1489 | } |
| 1490 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | /* unSolicited Responses */ |
| 1493 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1494 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1495 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1496 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | match = 1; |
| 1498 | } else { |
| 1499 | /* We must search, based on rctl / type |
| 1500 | for the right routine */ |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1501 | for (i = 0; i < pring->num_mask; i++) { |
| 1502 | if ((pring->prt[i].rctl == Rctl) |
| 1503 | && (pring->prt[i].type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1504 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1505 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1506 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | match = 1; |
| 1508 | break; |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | if (match == 0) { |
| 1513 | /* Unexpected Rctl / Type received */ |
| 1514 | /* Ring <ringno> handler: unexpected |
| 1515 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1516 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1517 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1518 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1519 | pring->ringno, Rctl, Type); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | } |
| 1523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1524 | /** |
| 1525 | * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb. |
| 1526 | * @phba: Pointer to HBA context object. |
| 1527 | * @pring: Pointer to driver SLI ring object. |
| 1528 | * @prspiocb: Pointer to response iocb object. |
| 1529 | * |
| 1530 | * This function looks up the iocb_lookup table to get the command iocb |
| 1531 | * corresponding to the given response iocb using the iotag of the |
| 1532 | * response iocb. This function is called with the hbalock held. |
| 1533 | * This function returns the command iocb object if it finds the command |
| 1534 | * iocb else returns NULL. |
| 1535 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1538 | struct lpfc_sli_ring *pring, |
| 1539 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1542 | uint16_t iotag; |
| 1543 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1544 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1546 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1547 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1548 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1549 | pring->txcmplq_cnt--; |
| 1550 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | } |
| 1552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1554 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1555 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1556 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1557 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | return NULL; |
| 1559 | } |
| 1560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1561 | /** |
| 1562 | * lpfc_sli_process_sol_iocb: process solicited iocb completion. |
| 1563 | * @phba: Pointer to HBA context object. |
| 1564 | * @pring: Pointer to driver SLI ring object. |
| 1565 | * @saveq: Pointer to the response iocb to be processed. |
| 1566 | * |
| 1567 | * This function is called by the ring event handler for non-fcp |
| 1568 | * rings when there is a new response iocb in the response ring. |
| 1569 | * The caller is not required to hold any locks. This function |
| 1570 | * gets the command iocb associated with the response iocb and |
| 1571 | * calls the completion handler for the command iocb. If there |
| 1572 | * is no completion handler, the function will free the resources |
| 1573 | * associated with command iocb. If the response iocb is for |
| 1574 | * an already aborted command iocb, the status of the completion |
| 1575 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1576 | * This function always returns 1. |
| 1577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1579 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | struct lpfc_iocbq *saveq) |
| 1581 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1582 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | int rc = 1; |
| 1584 | unsigned long iflag; |
| 1585 | |
| 1586 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1588 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1589 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | if (cmdiocbp) { |
| 1592 | if (cmdiocbp->iocb_cmpl) { |
| 1593 | /* |
| 1594 | * Post all ELS completions to the worker thread. |
| 1595 | * All other are passed to the completion callback. |
| 1596 | */ |
| 1597 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1598 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1599 | cmdiocbp->iocb_flag &= |
| 1600 | ~LPFC_DRIVER_ABORTED; |
| 1601 | saveq->iocb.ulpStatus = |
| 1602 | IOSTAT_LOCAL_REJECT; |
| 1603 | saveq->iocb.un.ulpWord[4] = |
| 1604 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1605 | |
| 1606 | /* Firmware could still be in progress |
| 1607 | * of DMAing payload, so don't free data |
| 1608 | * buffer till after a hbeat. |
| 1609 | */ |
| 1610 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1611 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1613 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1614 | } else |
| 1615 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | } else { |
| 1617 | /* |
| 1618 | * Unknown initiating command based on the response iotag. |
| 1619 | * This could be the case on the ELS ring because of |
| 1620 | * lpfc_els_abort(). |
| 1621 | */ |
| 1622 | if (pring->ringno != LPFC_ELS_RING) { |
| 1623 | /* |
| 1624 | * Ring <ringno> handler: unexpected completion IoTag |
| 1625 | * <IoTag> |
| 1626 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1627 | lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI, |
| 1628 | "0322 Ring %d handler: " |
| 1629 | "unexpected completion IoTag x%x " |
| 1630 | "Data: x%x x%x x%x x%x\n", |
| 1631 | pring->ringno, |
| 1632 | saveq->iocb.ulpIoTag, |
| 1633 | saveq->iocb.ulpStatus, |
| 1634 | saveq->iocb.un.ulpWord[4], |
| 1635 | saveq->iocb.ulpCommand, |
| 1636 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | } |
| 1638 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | return rc; |
| 1641 | } |
| 1642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1643 | /** |
| 1644 | * lpfc_sli_rsp_pointers_error: Response ring pointer error handler. |
| 1645 | * @phba: Pointer to HBA context object. |
| 1646 | * @pring: Pointer to driver SLI ring object. |
| 1647 | * |
| 1648 | * This function is called from the iocb ring event handlers when |
| 1649 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1650 | * an error attention condition to the worker thread and the worker |
| 1651 | * thread will transition the HBA to offline state. |
| 1652 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1653 | static void |
| 1654 | 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] | 1655 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 1656 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1657 | /* |
| 1658 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 1659 | * rsp ring <portRspMax> |
| 1660 | */ |
| 1661 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1662 | "0312 Ring %d handler: portRspPut %d " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1663 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1664 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1665 | pring->numRiocb); |
| 1666 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1667 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1668 | |
| 1669 | /* |
| 1670 | * All error attention handlers are posted to |
| 1671 | * worker thread |
| 1672 | */ |
| 1673 | phba->work_ha |= HA_ERATT; |
| 1674 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1675 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1676 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1677 | |
| 1678 | return; |
| 1679 | } |
| 1680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1681 | /** |
| 1682 | * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode. |
| 1683 | * @phba: Pointer to HBA context object. |
| 1684 | * |
| 1685 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1686 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1687 | * is enabled. |
| 1688 | * |
| 1689 | * The caller does not hold any lock. |
| 1690 | * The function processes each response iocb in the response ring until it |
| 1691 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1692 | * LE bit set. The function will call the completion handler of the command iocb |
| 1693 | * if the response iocb indicates a completion for a command iocb or it is |
| 1694 | * an abort completion. |
| 1695 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1696 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1697 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | struct lpfc_sli *psli = &phba->sli; |
| 1699 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1700 | IOCB_t *irsp = NULL; |
| 1701 | IOCB_t *entry = NULL; |
| 1702 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1703 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 1704 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1705 | uint32_t status; |
| 1706 | uint32_t portRspPut, portRspMax; |
| 1707 | int type; |
| 1708 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1709 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1710 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1711 | |
| 1712 | pring->stats.iocb_event++; |
| 1713 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1714 | /* |
| 1715 | * The next available response entry should never exceed the maximum |
| 1716 | * entries. If it does, treat it as an adapter hardware error. |
| 1717 | */ |
| 1718 | portRspMax = pring->numRiocb; |
| 1719 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1720 | if (unlikely(portRspPut >= portRspMax)) { |
| 1721 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1722 | return; |
| 1723 | } |
| 1724 | |
| 1725 | rmb(); |
| 1726 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1727 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1728 | if (++pring->rspidx >= portRspMax) |
| 1729 | pring->rspidx = 0; |
| 1730 | |
| 1731 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1732 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1733 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1734 | irsp = &rspiocbq.iocb; |
| 1735 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1736 | pring->stats.iocb_rsp++; |
| 1737 | rsp_cmpl++; |
| 1738 | |
| 1739 | if (unlikely(irsp->ulpStatus)) { |
| 1740 | /* Rsp ring <ringno> error: IOCB */ |
| 1741 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1742 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1743 | "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] | 1744 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1745 | irsp->un.ulpWord[0], |
| 1746 | irsp->un.ulpWord[1], |
| 1747 | irsp->un.ulpWord[2], |
| 1748 | irsp->un.ulpWord[3], |
| 1749 | irsp->un.ulpWord[4], |
| 1750 | irsp->un.ulpWord[5], |
| 1751 | *(((uint32_t *) irsp) + 6), |
| 1752 | *(((uint32_t *) irsp) + 7)); |
| 1753 | } |
| 1754 | |
| 1755 | switch (type) { |
| 1756 | case LPFC_ABORT_IOCB: |
| 1757 | case LPFC_SOL_IOCB: |
| 1758 | /* |
| 1759 | * Idle exchange closed via ABTS from port. No iocb |
| 1760 | * resources need to be recovered. |
| 1761 | */ |
| 1762 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1763 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1764 | "0314 IOCB cmd 0x%x " |
| 1765 | "processed. Skipping " |
| 1766 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1767 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1768 | break; |
| 1769 | } |
| 1770 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1772 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1773 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1774 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1775 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1776 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1777 | &rspiocbq); |
| 1778 | } |
| 1779 | break; |
| 1780 | default: |
| 1781 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1782 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1783 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1784 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1785 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1786 | dev_warn(&((phba->pcidev)->dev), |
| 1787 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1788 | phba->brd_no, adaptermsg); |
| 1789 | } else { |
| 1790 | /* Unknown IOCB command */ |
| 1791 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1792 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1793 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1794 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1795 | irsp->ulpStatus, |
| 1796 | irsp->ulpIoTag, |
| 1797 | irsp->ulpContext); |
| 1798 | } |
| 1799 | break; |
| 1800 | } |
| 1801 | |
| 1802 | /* |
| 1803 | * The response IOCB has been processed. Update the ring |
| 1804 | * pointer in SLIM. If the port response put pointer has not |
| 1805 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1806 | * response put pointer. |
| 1807 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1808 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1809 | |
| 1810 | if (pring->rspidx == portRspPut) |
| 1811 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1812 | } |
| 1813 | |
| 1814 | ha_copy = readl(phba->HAregaddr); |
| 1815 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1816 | |
| 1817 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1818 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1819 | pring->stats.iocb_rsp_full++; |
| 1820 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1821 | writel(status, phba->CAregaddr); |
| 1822 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1823 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1824 | } |
| 1825 | if ((ha_copy & HA_R0CE_RSP) && |
| 1826 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1828 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1829 | pring->stats.iocb_cmd_empty++; |
| 1830 | |
| 1831 | /* Force update of the local copy of cmdGetInx */ |
| 1832 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1833 | lpfc_sli_resume_iocb(phba, pring); |
| 1834 | |
| 1835 | if ((pring->lpfc_sli_cmd_available)) |
| 1836 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1837 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1838 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | return; |
| 1842 | } |
| 1843 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1844 | /** |
| 1845 | * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring. |
| 1846 | * @phba: Pointer to HBA context object. |
| 1847 | * @pring: Pointer to driver SLI ring object. |
| 1848 | * @mask: Host attention register mask for this ring. |
| 1849 | * |
| 1850 | * This function is called from the interrupt context when there is a ring |
| 1851 | * event for the fcp ring. The caller does not hold any lock. |
| 1852 | * The function processes each response iocb in the response ring until it |
| 1853 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1854 | * LE bit set. The function will call the completion handler of the command iocb |
| 1855 | * if the response iocb indicates a completion for a command iocb or it is |
| 1856 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1857 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1859 | * to check it explicitly. This function always returns 1. |
| 1860 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1863 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 1865 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1867 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1869 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | uint32_t status; |
| 1871 | uint32_t portRspPut, portRspMax; |
| 1872 | int rc = 1; |
| 1873 | lpfc_iocb_type type; |
| 1874 | unsigned long iflag; |
| 1875 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | pring->stats.iocb_event++; |
| 1879 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | /* |
| 1881 | * The next available response entry should never exceed the maximum |
| 1882 | * entries. If it does, treat it as an adapter hardware error. |
| 1883 | */ |
| 1884 | portRspMax = pring->numRiocb; |
| 1885 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1886 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1887 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | return 1; |
| 1890 | } |
| 1891 | |
| 1892 | rmb(); |
| 1893 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1894 | /* |
| 1895 | * Fetch an entry off the ring and copy it into a local data |
| 1896 | * structure. The copy involves a byte-swap since the |
| 1897 | * network byte order and pci byte orders are different. |
| 1898 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1899 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1900 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1901 | |
| 1902 | if (++pring->rspidx >= portRspMax) |
| 1903 | pring->rspidx = 0; |
| 1904 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1905 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1906 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1907 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1908 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1909 | irsp = &rspiocbq.iocb; |
| 1910 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1912 | pring->stats.iocb_rsp++; |
| 1913 | rsp_cmpl++; |
| 1914 | |
| 1915 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1916 | /* |
| 1917 | * If resource errors reported from HBA, reduce |
| 1918 | * queuedepths of the SCSI device. |
| 1919 | */ |
| 1920 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1921 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1922 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1923 | lpfc_adjust_queue_depth(phba); |
| 1924 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1925 | } |
| 1926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | /* Rsp ring <ringno> error: IOCB */ |
| 1928 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1929 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | "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] | 1931 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | irsp->un.ulpWord[0], |
| 1933 | irsp->un.ulpWord[1], |
| 1934 | irsp->un.ulpWord[2], |
| 1935 | irsp->un.ulpWord[3], |
| 1936 | irsp->un.ulpWord[4], |
| 1937 | irsp->un.ulpWord[5], |
| 1938 | *(((uint32_t *) irsp) + 6), |
| 1939 | *(((uint32_t *) irsp) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | switch (type) { |
| 1943 | case LPFC_ABORT_IOCB: |
| 1944 | case LPFC_SOL_IOCB: |
| 1945 | /* |
| 1946 | * Idle exchange closed via ABTS from port. No iocb |
| 1947 | * resources need to be recovered. |
| 1948 | */ |
| 1949 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1950 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1951 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1952 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1954 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | break; |
| 1956 | } |
| 1957 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1958 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1959 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1961 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 1962 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1963 | &rspiocbq); |
| 1964 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | spin_unlock_irqrestore(&phba->hbalock, |
| 1966 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1967 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1968 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1970 | iflag); |
| 1971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | } |
| 1973 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1974 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1976 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1978 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | default: |
| 1980 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1981 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1982 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1983 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1984 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1985 | dev_warn(&((phba->pcidev)->dev), |
| 1986 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | phba->brd_no, adaptermsg); |
| 1988 | } else { |
| 1989 | /* Unknown IOCB command */ |
| 1990 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1991 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1993 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1994 | irsp->ulpStatus, |
| 1995 | irsp->ulpIoTag, |
| 1996 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | } |
| 1998 | break; |
| 1999 | } |
| 2000 | |
| 2001 | /* |
| 2002 | * The response IOCB has been processed. Update the ring |
| 2003 | * pointer in SLIM. If the port response put pointer has not |
| 2004 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2005 | * response put pointer. |
| 2006 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2007 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | |
| 2009 | if (pring->rspidx == portRspPut) |
| 2010 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2011 | } |
| 2012 | |
| 2013 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2014 | pring->stats.iocb_rsp_full++; |
| 2015 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2016 | writel(status, phba->CAregaddr); |
| 2017 | readl(phba->CAregaddr); |
| 2018 | } |
| 2019 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2020 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2021 | pring->stats.iocb_cmd_empty++; |
| 2022 | |
| 2023 | /* Force update of the local copy of cmdGetInx */ |
| 2024 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2025 | lpfc_sli_resume_iocb(phba, pring); |
| 2026 | |
| 2027 | if ((pring->lpfc_sli_cmd_available)) |
| 2028 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2029 | |
| 2030 | } |
| 2031 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | return rc; |
| 2034 | } |
| 2035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2036 | /** |
| 2037 | * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings. |
| 2038 | * @phba: Pointer to HBA context object. |
| 2039 | * @pring: Pointer to driver SLI ring object. |
| 2040 | * @mask: Host attention register mask for this ring. |
| 2041 | * |
| 2042 | * This function is called from the worker thread when there is a ring |
| 2043 | * event for non-fcp rings. The caller does not hold any lock . |
| 2044 | * The function processes each response iocb in the response ring until it |
| 2045 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2046 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the |
| 2047 | * response iocb indicates a completion of a command iocb. The function |
| 2048 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited |
| 2049 | * iocb. The function frees the resources or calls the completion handler if |
| 2050 | * this iocb is an abort completion. The function returns 0 when the allocated |
| 2051 | * iocbs are not freed, otherwise returns 1. |
| 2052 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2055 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 2057 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | IOCB_t *entry; |
| 2059 | IOCB_t *irsp = NULL; |
| 2060 | struct lpfc_iocbq *rspiocbp = NULL; |
| 2061 | struct lpfc_iocbq *next_iocb; |
| 2062 | struct lpfc_iocbq *cmdiocbp; |
| 2063 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | uint8_t iocb_cmd_type; |
| 2065 | lpfc_iocb_type type; |
| 2066 | uint32_t status, free_saveq; |
| 2067 | uint32_t portRspPut, portRspMax; |
| 2068 | int rc = 1; |
| 2069 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 2071 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2072 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | pring->stats.iocb_event++; |
| 2074 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | /* |
| 2076 | * The next available response entry should never exceed the maximum |
| 2077 | * entries. If it does, treat it as an adapter hardware error. |
| 2078 | */ |
| 2079 | portRspMax = pring->numRiocb; |
| 2080 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2081 | if (portRspPut >= portRspMax) { |
| 2082 | /* |
| 2083 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 2084 | * rsp ring <portRspMax> |
| 2085 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2086 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2087 | "0303 Ring %d handler: portRspPut %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2089 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2091 | phba->link_state = LPFC_HBA_ERROR; |
| 2092 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | |
| 2094 | phba->work_hs = HS_FFER3; |
| 2095 | lpfc_handle_eratt(phba); |
| 2096 | |
| 2097 | return 1; |
| 2098 | } |
| 2099 | |
| 2100 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | while (pring->rspidx != portRspPut) { |
| 2102 | /* |
| 2103 | * Build a completion list and call the appropriate handler. |
| 2104 | * The process is to get the next available response iocb, get |
| 2105 | * a free iocb from the list, copy the response data into the |
| 2106 | * free iocb, insert to the continuation list, and update the |
| 2107 | * next response index to slim. This process makes response |
| 2108 | * iocb's in the ring available to DMA as fast as possible but |
| 2109 | * pays a penalty for a copy operation. Since the iocb is |
| 2110 | * only 32 bytes, this penalty is considered small relative to |
| 2111 | * the PCI reads for register values and a slim write. When |
| 2112 | * the ulpLe field is set, the entire Command has been |
| 2113 | * received. |
| 2114 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2115 | entry = lpfc_resp_iocb(phba, pring); |
| 2116 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2117 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | if (rspiocbp == NULL) { |
| 2120 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2121 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | break; |
| 2123 | } |
| 2124 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2125 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2126 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | irsp = &rspiocbp->iocb; |
| 2128 | |
| 2129 | if (++pring->rspidx >= portRspMax) |
| 2130 | pring->rspidx = 0; |
| 2131 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2132 | if (pring->ringno == LPFC_ELS_RING) { |
| 2133 | lpfc_debugfs_slow_ring_trc(phba, |
| 2134 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2135 | *(((uint32_t *) irsp) + 4), |
| 2136 | *(((uint32_t *) irsp) + 6), |
| 2137 | *(((uint32_t *) irsp) + 7)); |
| 2138 | } |
| 2139 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2140 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2142 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | |
| 2144 | pring->iocb_continueq_cnt++; |
| 2145 | if (irsp->ulpLe) { |
| 2146 | /* |
| 2147 | * By default, the driver expects to free all resources |
| 2148 | * associated with this iocb completion. |
| 2149 | */ |
| 2150 | free_saveq = 1; |
| 2151 | saveq = list_get_first(&pring->iocb_continueq, |
| 2152 | struct lpfc_iocbq, list); |
| 2153 | irsp = &(saveq->iocb); |
| 2154 | list_del_init(&pring->iocb_continueq); |
| 2155 | pring->iocb_continueq_cnt = 0; |
| 2156 | |
| 2157 | pring->stats.iocb_rsp++; |
| 2158 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2159 | /* |
| 2160 | * If resource errors reported from HBA, reduce |
| 2161 | * queuedepths of the SCSI device. |
| 2162 | */ |
| 2163 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2164 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2165 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2166 | lpfc_adjust_queue_depth(phba); |
| 2167 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2168 | } |
| 2169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | if (irsp->ulpStatus) { |
| 2171 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2172 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2173 | "0328 Rsp Ring %d error: " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2174 | "IOCB Data: " |
| 2175 | "x%x x%x x%x x%x " |
| 2176 | "x%x x%x x%x x%x " |
| 2177 | "x%x x%x x%x x%x " |
| 2178 | "x%x x%x x%x x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2179 | pring->ringno, |
| 2180 | irsp->un.ulpWord[0], |
| 2181 | irsp->un.ulpWord[1], |
| 2182 | irsp->un.ulpWord[2], |
| 2183 | irsp->un.ulpWord[3], |
| 2184 | irsp->un.ulpWord[4], |
| 2185 | irsp->un.ulpWord[5], |
| 2186 | *(((uint32_t *) irsp) + 6), |
| 2187 | *(((uint32_t *) irsp) + 7), |
| 2188 | *(((uint32_t *) irsp) + 8), |
| 2189 | *(((uint32_t *) irsp) + 9), |
| 2190 | *(((uint32_t *) irsp) + 10), |
| 2191 | *(((uint32_t *) irsp) + 11), |
| 2192 | *(((uint32_t *) irsp) + 12), |
| 2193 | *(((uint32_t *) irsp) + 13), |
| 2194 | *(((uint32_t *) irsp) + 14), |
| 2195 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | /* |
| 2199 | * Fetch the IOCB command type and call the correct |
| 2200 | * completion routine. Solicited and Unsolicited |
| 2201 | * IOCBs on the ELS ring get freed back to the |
| 2202 | * lpfc_iocb_list by the discovery kernel thread. |
| 2203 | */ |
| 2204 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2205 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2206 | if (type == LPFC_SOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2207 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2209 | saveq); |
| 2210 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2212 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2214 | saveq); |
| 2215 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2216 | if (!rc) |
| 2217 | free_saveq = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | } else if (type == LPFC_ABORT_IOCB) { |
| 2219 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 2220 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2221 | lpfc_sli_iocbq_lookup(phba, pring, |
| 2222 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | /* Call the specified completion |
| 2224 | routine */ |
| 2225 | if (cmdiocbp->iocb_cmpl) { |
| 2226 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2227 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | iflag); |
| 2229 | (cmdiocbp->iocb_cmpl) (phba, |
| 2230 | cmdiocbp, saveq); |
| 2231 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2232 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2234 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2235 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2236 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | } |
| 2238 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 2239 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2240 | |
| 2241 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2242 | |
| 2243 | memset(adaptermsg, 0, |
| 2244 | LPFC_MAX_ADPTMSG); |
| 2245 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2246 | MAX_MSG_DATA); |
| 2247 | dev_warn(&((phba->pcidev)->dev), |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2248 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | phba->brd_no, adaptermsg); |
| 2250 | } else { |
| 2251 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2252 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2253 | "0335 Unknown IOCB " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2254 | "command Data: x%x " |
| 2255 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2256 | irsp->ulpCommand, |
| 2257 | irsp->ulpStatus, |
| 2258 | irsp->ulpIoTag, |
| 2259 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2265 | &saveq->list, list) { |
| 2266 | list_del(&rspiocbp->list); |
| 2267 | __lpfc_sli_release_iocbq(phba, |
| 2268 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2269 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2270 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2272 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /* |
| 2276 | * If the port response put pointer has not been updated, sync |
| 2277 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2278 | * response put pointer. |
| 2279 | */ |
| 2280 | if (pring->rspidx == portRspPut) { |
| 2281 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2282 | } |
| 2283 | } /* while (pring->rspidx != portRspPut) */ |
| 2284 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2285 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | /* At least one response entry has been freed */ |
| 2287 | pring->stats.iocb_rsp_full++; |
| 2288 | /* SET RxRE_RSP in Chip Att register */ |
| 2289 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2290 | writel(status, phba->CAregaddr); |
| 2291 | readl(phba->CAregaddr); /* flush */ |
| 2292 | } |
| 2293 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2294 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2295 | pring->stats.iocb_cmd_empty++; |
| 2296 | |
| 2297 | /* Force update of the local copy of cmdGetInx */ |
| 2298 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2299 | lpfc_sli_resume_iocb(phba, pring); |
| 2300 | |
| 2301 | if ((pring->lpfc_sli_cmd_available)) |
| 2302 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2303 | |
| 2304 | } |
| 2305 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | return rc; |
| 2308 | } |
| 2309 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2310 | /** |
| 2311 | * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring. |
| 2312 | * @phba: Pointer to HBA context object. |
| 2313 | * @pring: Pointer to driver SLI ring object. |
| 2314 | * |
| 2315 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2316 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2317 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2318 | * the return of this function. The caller is not required to hold any locks. |
| 2319 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2322 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2323 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2325 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2327 | if (pring->ringno == LPFC_ELS_RING) { |
| 2328 | lpfc_fabric_abort_hba(phba); |
| 2329 | } |
| 2330 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | /* Error everything on txq and txcmplq |
| 2332 | * First do the txq. |
| 2333 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2334 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2335 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | |
| 2338 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2339 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2340 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2343 | |
| 2344 | while (!list_empty(&completions)) { |
| 2345 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | cmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | list_del_init(&iocb->list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2349 | if (!iocb->iocb_cmpl) |
| 2350 | lpfc_sli_release_iocbq(phba, iocb); |
| 2351 | else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2353 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2355 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | } |
| 2358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2359 | /** |
| 2360 | * lpfc_sli_brdready: Check for host status bits. |
| 2361 | * @phba: Pointer to HBA context object. |
| 2362 | * @mask: Bit mask to be checked. |
| 2363 | * |
| 2364 | * This function reads the host status register and compares |
| 2365 | * with the provided bit mask to check if HBA completed |
| 2366 | * the restart. This function will wait in a loop for the |
| 2367 | * HBA to complete restart. If the HBA does not restart within |
| 2368 | * 15 iterations, the function will reset the HBA again. The |
| 2369 | * function returns 1 when HBA fail to restart otherwise returns |
| 2370 | * zero. |
| 2371 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2372 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2375 | uint32_t status; |
| 2376 | int i = 0; |
| 2377 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2379 | /* Read the HBA Host Status Register */ |
| 2380 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2382 | /* |
| 2383 | * Check status register every 100ms for 5 retries, then every |
| 2384 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2385 | * every 2.5 sec for 4. |
| 2386 | * Break our of the loop if errors occurred during init. |
| 2387 | */ |
| 2388 | while (((status & mask) != mask) && |
| 2389 | !(status & HS_FFERM) && |
| 2390 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2392 | if (i <= 5) |
| 2393 | msleep(10); |
| 2394 | else if (i <= 10) |
| 2395 | msleep(500); |
| 2396 | else |
| 2397 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2399 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2400 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2401 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2402 | lpfc_sli_brdrestart(phba); |
| 2403 | } |
| 2404 | /* Read the HBA Host Status Register */ |
| 2405 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2408 | /* Check to see if any errors occurred during init */ |
| 2409 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2410 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2411 | retval = 1; |
| 2412 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2414 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | } |
| 2416 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2417 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2419 | /** |
| 2420 | * lpfc_reset_barrier: Make HBA ready for HBA reset. |
| 2421 | * @phba: Pointer to HBA context object. |
| 2422 | * |
| 2423 | * This function is called before resetting an HBA. This |
| 2424 | * function requests HBA to quiesce DMAs before a reset. |
| 2425 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2426 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2427 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2428 | uint32_t __iomem *resp_buf; |
| 2429 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2430 | volatile uint32_t mbox; |
| 2431 | uint32_t hc_copy; |
| 2432 | int i; |
| 2433 | uint8_t hdrtype; |
| 2434 | |
| 2435 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2436 | if (hdrtype != 0x80 || |
| 2437 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2438 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2439 | return; |
| 2440 | |
| 2441 | /* |
| 2442 | * Tell the other part of the chip to suspend temporarily all |
| 2443 | * its DMA activity. |
| 2444 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2445 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2446 | |
| 2447 | /* Disable the error attention */ |
| 2448 | hc_copy = readl(phba->HCregaddr); |
| 2449 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2450 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2451 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2452 | |
| 2453 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2454 | /* Clear Chip error bit */ |
| 2455 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | mbox = 0; |
| 2460 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2461 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2462 | |
| 2463 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2464 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2465 | writel(mbox, mbox_buf); |
| 2466 | |
| 2467 | for (i = 0; |
| 2468 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2469 | mdelay(1); |
| 2470 | |
| 2471 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2472 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2474 | goto restore_hc; |
| 2475 | else |
| 2476 | goto clear_errat; |
| 2477 | } |
| 2478 | |
| 2479 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2480 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2481 | mdelay(1); |
| 2482 | |
| 2483 | clear_errat: |
| 2484 | |
| 2485 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2486 | mdelay(1); |
| 2487 | |
| 2488 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2489 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2490 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2495 | writel(hc_copy, phba->HCregaddr); |
| 2496 | readl(phba->HCregaddr); /* flush */ |
| 2497 | } |
| 2498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2499 | /** |
| 2500 | * lpfc_sli_brdkill: Issue a kill_board mailbox command. |
| 2501 | * @phba: Pointer to HBA context object. |
| 2502 | * |
| 2503 | * This function issues a kill_board mailbox command and waits for |
| 2504 | * the error attention interrupt. This function is called for stopping |
| 2505 | * the firmware processing. The caller is not required to hold any |
| 2506 | * locks. This function calls lpfc_hba_down_post function to free |
| 2507 | * any pending commands after the kill. The function will return 1 when it |
| 2508 | * fails to kill the board else will return 0. |
| 2509 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2510 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2511 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2513 | struct lpfc_sli *psli; |
| 2514 | LPFC_MBOXQ_t *pmb; |
| 2515 | uint32_t status; |
| 2516 | uint32_t ha_copy; |
| 2517 | int retval; |
| 2518 | int i = 0; |
| 2519 | |
| 2520 | psli = &phba->sli; |
| 2521 | |
| 2522 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2523 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2524 | "0329 Kill HBA Data: x%x x%x\n", |
| 2525 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2526 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2527 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2528 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2529 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2530 | |
| 2531 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2532 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2533 | status = readl(phba->HCregaddr); |
| 2534 | status &= ~HC_ERINT_ENA; |
| 2535 | writel(status, phba->HCregaddr); |
| 2536 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2538 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2539 | |
| 2540 | lpfc_kill_board(phba, pmb); |
| 2541 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2542 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2543 | |
| 2544 | if (retval != MBX_SUCCESS) { |
| 2545 | if (retval != MBX_BUSY) |
| 2546 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2547 | spin_lock_irq(&phba->hbalock); |
| 2548 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2549 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2550 | return 1; |
| 2551 | } |
| 2552 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2553 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2554 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2555 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2556 | |
| 2557 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2558 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2559 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2560 | * board is now undefined. |
| 2561 | */ |
| 2562 | ha_copy = readl(phba->HAregaddr); |
| 2563 | |
| 2564 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2565 | mdelay(100); |
| 2566 | ha_copy = readl(phba->HAregaddr); |
| 2567 | } |
| 2568 | |
| 2569 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2570 | if (ha_copy & HA_ERATT) { |
| 2571 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2572 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2573 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2575 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2576 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2577 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2578 | |
| 2579 | psli->mbox_active = NULL; |
| 2580 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2581 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2582 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2583 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2584 | } |
| 2585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2586 | /** |
| 2587 | * lpfc_sli_brdreset: Reset the HBA. |
| 2588 | * @phba: Pointer to HBA context object. |
| 2589 | * |
| 2590 | * This function resets the HBA by writing HC_INITFF to the control |
| 2591 | * register. After the HBA resets, this function resets all the iocb ring |
| 2592 | * indices. This function disables PCI layer parity checking during |
| 2593 | * the reset. |
| 2594 | * This function returns 0 always. |
| 2595 | * The caller is not required to hold any locks. |
| 2596 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2597 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2599 | { |
| 2600 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2602 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2605 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2607 | /* Reset HBA */ |
| 2608 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2609 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2610 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2611 | |
| 2612 | /* perform board reset */ |
| 2613 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2614 | phba->pport->fc_myDID = 0; |
| 2615 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2617 | /* Turn off parity checking and serr during the physical reset */ |
| 2618 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2619 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2620 | (cfg_value & |
| 2621 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2622 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2623 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2624 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2625 | writel(HC_INITFF, phba->HCregaddr); |
| 2626 | mdelay(1); |
| 2627 | readl(phba->HCregaddr); /* flush */ |
| 2628 | writel(0, phba->HCregaddr); |
| 2629 | readl(phba->HCregaddr); /* flush */ |
| 2630 | |
| 2631 | /* Restore PCI cmd register */ |
| 2632 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | |
| 2634 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2635 | for (i = 0; i < psli->num_rings; i++) { |
| 2636 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | pring->flag = 0; |
| 2638 | pring->rspidx = 0; |
| 2639 | pring->next_cmdidx = 0; |
| 2640 | pring->local_getidx = 0; |
| 2641 | pring->cmdidx = 0; |
| 2642 | pring->missbufcnt = 0; |
| 2643 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2645 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2646 | return 0; |
| 2647 | } |
| 2648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2649 | /** |
| 2650 | * lpfc_sli_brdrestart: Restart the HBA. |
| 2651 | * @phba: Pointer to HBA context object. |
| 2652 | * |
| 2653 | * This function is called in the SLI initialization code path to |
| 2654 | * restart the HBA. The caller is not required to hold any lock. |
| 2655 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2656 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2657 | * function to free any pending commands. The function enables |
| 2658 | * POST only during the first initialization. The function returns zero. |
| 2659 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2660 | * command before the return of this function. |
| 2661 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2662 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2664 | { |
| 2665 | MAILBOX_t *mb; |
| 2666 | struct lpfc_sli *psli; |
| 2667 | uint16_t skip_post; |
| 2668 | volatile uint32_t word0; |
| 2669 | void __iomem *to_slim; |
| 2670 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2672 | |
| 2673 | psli = &phba->sli; |
| 2674 | |
| 2675 | /* Restart HBA */ |
| 2676 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2677 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2678 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2679 | |
| 2680 | word0 = 0; |
| 2681 | mb = (MAILBOX_t *) &word0; |
| 2682 | mb->mbxCommand = MBX_RESTART; |
| 2683 | mb->mbxHc = 1; |
| 2684 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2685 | lpfc_reset_barrier(phba); |
| 2686 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2687 | to_slim = phba->MBslimaddr; |
| 2688 | writel(*(uint32_t *) mb, to_slim); |
| 2689 | readl(to_slim); /* flush */ |
| 2690 | |
| 2691 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2692 | if (phba->pport->port_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2693 | skip_post = 1; |
| 2694 | word0 = 1; /* This is really setting up word1 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | } else { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2696 | skip_post = 0; |
| 2697 | word0 = 0; /* This is really setting up word1 */ |
| 2698 | } |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2699 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2700 | writel(*(uint32_t *) mb, to_slim); |
| 2701 | readl(to_slim); /* flush */ |
| 2702 | |
| 2703 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | phba->pport->stopped = 0; |
| 2705 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2706 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2708 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2709 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2710 | psli->stats_start = get_seconds(); |
| 2711 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2712 | if (skip_post) |
| 2713 | mdelay(100); |
| 2714 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | mdelay(2000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2717 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | |
| 2719 | return 0; |
| 2720 | } |
| 2721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2722 | /** |
| 2723 | * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart. |
| 2724 | * @phba: Pointer to HBA context object. |
| 2725 | * |
| 2726 | * This function is called after a HBA restart to wait for successful |
| 2727 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2728 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2729 | * iteration, the function will restart the HBA again. The function returns |
| 2730 | * zero if HBA successfully restarted else returns negative error code. |
| 2731 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | static int |
| 2733 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2734 | { |
| 2735 | uint32_t status, i = 0; |
| 2736 | |
| 2737 | /* Read the HBA Host Status Register */ |
| 2738 | status = readl(phba->HSregaddr); |
| 2739 | |
| 2740 | /* Check status register to see what current state is */ |
| 2741 | i = 0; |
| 2742 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2743 | |
| 2744 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2745 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2746 | * 4. |
| 2747 | */ |
| 2748 | if (i++ >= 20) { |
| 2749 | /* Adapter failed to init, timeout, status reg |
| 2750 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2752 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2753 | "timeout, status reg x%x, " |
| 2754 | "FW Data: A8 x%x AC x%x\n", status, |
| 2755 | readl(phba->MBslimaddr + 0xa8), |
| 2756 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2757 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | return -ETIMEDOUT; |
| 2759 | } |
| 2760 | |
| 2761 | /* Check to see if any errors occurred during init */ |
| 2762 | if (status & HS_FFERM) { |
| 2763 | /* ERROR: During chipset initialization */ |
| 2764 | /* Adapter failed to init, chipset, status reg |
| 2765 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2766 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2767 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2768 | "chipset, status reg x%x, " |
| 2769 | "FW Data: A8 x%x AC x%x\n", status, |
| 2770 | readl(phba->MBslimaddr + 0xa8), |
| 2771 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | return -EIO; |
| 2774 | } |
| 2775 | |
| 2776 | if (i <= 5) { |
| 2777 | msleep(10); |
| 2778 | } else if (i <= 10) { |
| 2779 | msleep(500); |
| 2780 | } else { |
| 2781 | msleep(2500); |
| 2782 | } |
| 2783 | |
| 2784 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2785 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2786 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2787 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | } |
| 2789 | /* Read the HBA Host Status Register */ |
| 2790 | status = readl(phba->HSregaddr); |
| 2791 | } |
| 2792 | |
| 2793 | /* Check to see if any errors occurred during init */ |
| 2794 | if (status & HS_FFERM) { |
| 2795 | /* ERROR: During chipset initialization */ |
| 2796 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2798 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2799 | "status reg x%x, " |
| 2800 | "FW Data: A8 x%x AC x%x\n", status, |
| 2801 | readl(phba->MBslimaddr + 0xa8), |
| 2802 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2803 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | return -EIO; |
| 2805 | } |
| 2806 | |
| 2807 | /* Clear all interrupt enable conditions */ |
| 2808 | writel(0, phba->HCregaddr); |
| 2809 | readl(phba->HCregaddr); /* flush */ |
| 2810 | |
| 2811 | /* setup host attn register */ |
| 2812 | writel(0xffffffff, phba->HAregaddr); |
| 2813 | readl(phba->HAregaddr); /* flush */ |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2817 | /** |
| 2818 | * lpfc_sli_hbq_count: Get the number of HBQs to be configured. |
| 2819 | * |
| 2820 | * This function calculates and returns the number of HBQs required to be |
| 2821 | * configured. |
| 2822 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2823 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2824 | lpfc_sli_hbq_count(void) |
| 2825 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2826 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2827 | } |
| 2828 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2829 | /** |
| 2830 | * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries. |
| 2831 | * |
| 2832 | * This function adds the number of hbq entries in every HBQ to get |
| 2833 | * the total number of hbq entries required for the HBA and returns |
| 2834 | * the total count. |
| 2835 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2836 | static int |
| 2837 | lpfc_sli_hbq_entry_count(void) |
| 2838 | { |
| 2839 | int hbq_count = lpfc_sli_hbq_count(); |
| 2840 | int count = 0; |
| 2841 | int i; |
| 2842 | |
| 2843 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2844 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2845 | return count; |
| 2846 | } |
| 2847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2848 | /** |
| 2849 | * lpfc_sli_hbq_size: Calculate memory required for all hbq entries. |
| 2850 | * |
| 2851 | * This function calculates amount of memory required for all hbq entries |
| 2852 | * to be configured and returns the total memory required. |
| 2853 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2855 | lpfc_sli_hbq_size(void) |
| 2856 | { |
| 2857 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2858 | } |
| 2859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2860 | /** |
| 2861 | * lpfc_sli_hbq_setup: configure and initialize HBQs. |
| 2862 | * @phba: Pointer to HBA context object. |
| 2863 | * |
| 2864 | * This function is called during the SLI initialization to configure |
| 2865 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 2866 | * required to hold any locks. This function will return zero if successful |
| 2867 | * else it will return negative error code. |
| 2868 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2869 | static int |
| 2870 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2871 | { |
| 2872 | int hbq_count = lpfc_sli_hbq_count(); |
| 2873 | LPFC_MBOXQ_t *pmb; |
| 2874 | MAILBOX_t *pmbox; |
| 2875 | uint32_t hbqno; |
| 2876 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2877 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2878 | /* Get a Mailbox buffer to setup mailbox |
| 2879 | * commands for HBA initialization |
| 2880 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2881 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2882 | |
| 2883 | if (!pmb) |
| 2884 | return -ENOMEM; |
| 2885 | |
| 2886 | pmbox = &pmb->mb; |
| 2887 | |
| 2888 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 2889 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2890 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2891 | |
| 2892 | hbq_entry_index = 0; |
| 2893 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2894 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 2895 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 2896 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 2897 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2898 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2899 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 2900 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2901 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 2902 | |
| 2903 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 2904 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 2905 | mbxStatus <status>, ring <num> */ |
| 2906 | |
| 2907 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2908 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2909 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2910 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2911 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2912 | pmbox->mbxStatus, hbqno); |
| 2913 | |
| 2914 | phba->link_state = LPFC_HBA_ERROR; |
| 2915 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2916 | return ENXIO; |
| 2917 | } |
| 2918 | } |
| 2919 | phba->hbq_count = hbq_count; |
| 2920 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2921 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2922 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2923 | /* Initially populate or replenish the HBQs */ |
| 2924 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2925 | if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno)) |
| 2926 | return -ENOMEM; |
| 2927 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2928 | return 0; |
| 2929 | } |
| 2930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2931 | /** |
| 2932 | * lpfc_do_config_port: Issue config port mailbox command. |
| 2933 | * @phba: Pointer to HBA context object. |
| 2934 | * @sli_mode: sli mode - 2/3 |
| 2935 | * |
| 2936 | * This function is called by the sli intialization code path |
| 2937 | * to issue config_port mailbox command. This function restarts the |
| 2938 | * HBA firmware and issues a config_port mailbox command to configure |
| 2939 | * the SLI interface in the sli mode specified by sli_mode |
| 2940 | * variable. The caller is not required to hold any locks. |
| 2941 | * The function returns 0 if successful, else returns negative error |
| 2942 | * code. |
| 2943 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2944 | static int |
| 2945 | lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | { |
| 2947 | LPFC_MBOXQ_t *pmb; |
| 2948 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 2949 | |
| 2950 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2951 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2952 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | return -ENOMEM; |
| 2954 | } |
| 2955 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2956 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2958 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2959 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2960 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2961 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2962 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | msleep(2500); |
| 2964 | rc = lpfc_sli_chipset_init(phba); |
| 2965 | if (rc) |
| 2966 | break; |
| 2967 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2968 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2969 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2970 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | resetcount++; |
| 2972 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2973 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 2974 | * value of 0 means the call was successful. Any other |
| 2975 | * nonzero value is a failure, but if ERESTART is returned, |
| 2976 | * the driver may reset the HBA and try again. |
| 2977 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | rc = lpfc_config_port_prep(phba); |
| 2979 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2980 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 2982 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2984 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | lpfc_config_port(phba, pmb); |
| 2986 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 2987 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 2988 | LPFC_SLI3_HBQ_ENABLED | |
| 2989 | LPFC_SLI3_CRP_ENABLED | |
| 2990 | LPFC_SLI3_INB_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2991 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2993 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2994 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2995 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2996 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2998 | spin_unlock_irq(&phba->hbalock); |
| 2999 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3000 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3001 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3003 | if (!done) { |
| 3004 | rc = -EINVAL; |
| 3005 | goto do_prep_failed; |
| 3006 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3007 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3008 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3009 | rc = -ENXIO; |
| 3010 | goto do_prep_failed; |
| 3011 | } |
| 3012 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3013 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3014 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3015 | } else |
| 3016 | phba->max_vpi = 0; |
| 3017 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3018 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3019 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3020 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3021 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3022 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
| 3023 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3024 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3025 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3026 | phba->inb_last_counter = |
| 3027 | phba->mbox->us.s3_inb_pgp.counter; |
| 3028 | } else { |
| 3029 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3030 | phba->inb_ha_copy = NULL; |
| 3031 | phba->inb_counter = NULL; |
| 3032 | } |
| 3033 | } else { |
| 3034 | phba->port_gp = phba->mbox->us.s2.port; |
| 3035 | phba->inb_ha_copy = NULL; |
| 3036 | phba->inb_counter = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3037 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3038 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3039 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3040 | return rc; |
| 3041 | } |
| 3042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3043 | |
| 3044 | /** |
| 3045 | * lpfc_sli_hba_setup: SLI intialization function. |
| 3046 | * @phba: Pointer to HBA context object. |
| 3047 | * |
| 3048 | * This function is the main SLI intialization function. This function |
| 3049 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3050 | * error attention handler code. Caller is not required to hold any |
| 3051 | * locks. This function issues config_port mailbox command to configure |
| 3052 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3053 | * calls the config_port_post function to issue init_link mailbox |
| 3054 | * command and to start the discovery. The function will return zero |
| 3055 | * if successful, else it will return negative error code. |
| 3056 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3057 | int |
| 3058 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3059 | { |
| 3060 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3062 | |
| 3063 | switch (lpfc_sli_mode) { |
| 3064 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3065 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3067 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3069 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3070 | break; |
| 3071 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3072 | mode = 2; |
| 3073 | break; |
| 3074 | case 0: |
| 3075 | case 3: |
| 3076 | break; |
| 3077 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3079 | "1819 Unrecognized lpfc_sli_mode " |
| 3080 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3081 | |
| 3082 | break; |
| 3083 | } |
| 3084 | |
| 3085 | rc = lpfc_do_config_port(phba, mode); |
| 3086 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3088 | "1820 Unable to select SLI-3. " |
| 3089 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3090 | if (rc && mode != 2) |
| 3091 | rc = lpfc_do_config_port(phba, 2); |
| 3092 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | goto lpfc_sli_hba_setup_error; |
| 3094 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3095 | if (phba->sli_rev == 3) { |
| 3096 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3097 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3098 | } else { |
| 3099 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3100 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3101 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3105 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3106 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3107 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3108 | |
| 3109 | if (rc) |
| 3110 | goto lpfc_sli_hba_setup_error; |
| 3111 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3112 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3113 | |
| 3114 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3115 | rc = lpfc_sli_hbq_setup(phba); |
| 3116 | if (rc) |
| 3117 | goto lpfc_sli_hba_setup_error; |
| 3118 | } |
| 3119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3121 | |
| 3122 | rc = lpfc_config_port_post(phba); |
| 3123 | if (rc) |
| 3124 | goto lpfc_sli_hba_setup_error; |
| 3125 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3126 | return rc; |
| 3127 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3128 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3129 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3130 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3131 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | return rc; |
| 3133 | } |
| 3134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3135 | |
| 3136 | /** |
| 3137 | * lpfc_mbox_timeout: Timeout call back function for mbox timer. |
| 3138 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3140 | * This is the callback function for mailbox timer. The mailbox |
| 3141 | * timer is armed when a new mailbox command is issued and the timer |
| 3142 | * is deleted when the mailbox complete. The function is called by |
| 3143 | * the kernel timer code when a mailbox does not complete within |
| 3144 | * expected time. This function wakes up the worker thread to |
| 3145 | * process the mailbox timeout and returns. All the processing is |
| 3146 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | void |
| 3149 | lpfc_mbox_timeout(unsigned long ptr) |
| 3150 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3152 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3153 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3155 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3156 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3157 | if (!tmo_posted) |
| 3158 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3159 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3160 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3161 | if (!tmo_posted) |
| 3162 | lpfc_worker_wake_up(phba); |
| 3163 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | } |
| 3165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3166 | |
| 3167 | /** |
| 3168 | * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout. |
| 3169 | * @phba: Pointer to HBA context object. |
| 3170 | * |
| 3171 | * This function is called from worker thread when a mailbox command times out. |
| 3172 | * The caller is not required to hold any locks. This function will reset the |
| 3173 | * HBA and recover all the pending commands. |
| 3174 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | void |
| 3176 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3177 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3178 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3179 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3180 | struct lpfc_sli *psli = &phba->sli; |
| 3181 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3183 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3184 | return; |
| 3185 | } |
| 3186 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3188 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3189 | "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] | 3190 | mb->mbxCommand, |
| 3191 | phba->pport->port_state, |
| 3192 | phba->sli.sli_flag, |
| 3193 | phba->sli.mbox_active); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3195 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3196 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3197 | * it to fail all oustanding SCSI IO. |
| 3198 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3199 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3200 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3201 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3202 | spin_lock_irq(&phba->hbalock); |
| 3203 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3204 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3206 | |
| 3207 | pring = &psli->ring[psli->fcp_ring]; |
| 3208 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3209 | |
| 3210 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3211 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3212 | /* |
| 3213 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 3214 | * on oustanding mailbox commands. |
| 3215 | */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3216 | /* If resets are disabled then set error state and return. */ |
| 3217 | if (!phba->cfg_enable_hba_reset) { |
| 3218 | phba->link_state = LPFC_HBA_ERROR; |
| 3219 | return; |
| 3220 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3221 | lpfc_offline_prep(phba); |
| 3222 | lpfc_offline(phba); |
| 3223 | lpfc_sli_brdrestart(phba); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3224 | lpfc_online(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3225 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | return; |
| 3227 | } |
| 3228 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3229 | /** |
| 3230 | * lpfc_sli_issue_mbox: Issue a mailbox command to firmware. |
| 3231 | * @phba: Pointer to HBA context object. |
| 3232 | * @pmbox: Pointer to mailbox object. |
| 3233 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3234 | * |
| 3235 | * This function is called by discovery code and HBA management code |
| 3236 | * to submit a mailbox command to firmware. This function gets the |
| 3237 | * hbalock to protect the data structures. |
| 3238 | * The mailbox command can be submitted in polling mode, in which case |
| 3239 | * this function will wait in a polling loop for the completion of the |
| 3240 | * mailbox. |
| 3241 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3242 | * function will submit the command and returns immediately without waiting |
| 3243 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3244 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3245 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3246 | * mailbox is issued in polling mode and there is already a mailbox |
| 3247 | * pending, then the function will return an error. If the mailbox is issued |
| 3248 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3249 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3250 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3251 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3252 | * return codes the caller owns the mailbox command after the return of |
| 3253 | * the function. |
| 3254 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3256 | 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] | 3257 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | uint32_t status, evtctr; |
| 3261 | uint32_t ha_copy; |
| 3262 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3263 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3265 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3267 | int processing_queue = 0; |
| 3268 | |
| 3269 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3270 | if (!pmbox) { |
| 3271 | /* processing mbox queue from intr_handler */ |
| 3272 | processing_queue = 1; |
| 3273 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3274 | pmbox = lpfc_mbox_get(phba); |
| 3275 | if (!pmbox) { |
| 3276 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3277 | return MBX_SUCCESS; |
| 3278 | } |
| 3279 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3281 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3282 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3283 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3284 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3285 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3286 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3287 | "1806 Mbox x%x failed. No vport\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3288 | pmbox->mb.mbxCommand); |
| 3289 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3290 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3291 | } |
| 3292 | } |
| 3293 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3294 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3295 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3296 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3297 | goto out_not_finished; |
| 3298 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3299 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3301 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | mb = &pmbox->mb; |
| 3303 | status = MBX_SUCCESS; |
| 3304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3305 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3306 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3307 | |
| 3308 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3309 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3310 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3311 | } |
| 3312 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3313 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3314 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3315 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3316 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3317 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3318 | } |
| 3319 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3321 | /* Polling for a mbox command when another one is already active |
| 3322 | * is not allowed in SLI. Also, the driver must have established |
| 3323 | * SLI2 mode to queue and process multiple mbox commands. |
| 3324 | */ |
| 3325 | |
| 3326 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3327 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | |
| 3329 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3330 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3331 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3337 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3338 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | } |
| 3340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | /* Another mailbox command is still being processed, queue this |
| 3342 | * command to be processed later. |
| 3343 | */ |
| 3344 | lpfc_mbox_put(phba, pmbox); |
| 3345 | |
| 3346 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3347 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3348 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3349 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3350 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3351 | mb->mbxCommand, phba->pport->port_state, |
| 3352 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3353 | |
| 3354 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3355 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3357 | if (pmbox->vport) { |
| 3358 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3359 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3360 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3361 | (uint32_t)mb->mbxCommand, |
| 3362 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3363 | } |
| 3364 | else { |
| 3365 | lpfc_debugfs_disc_trc(phba->pport, |
| 3366 | LPFC_DISC_TRC_MBOX, |
| 3367 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3368 | (uint32_t)mb->mbxCommand, |
| 3369 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3370 | } |
| 3371 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | } |
| 3374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3376 | |
| 3377 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3378 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3379 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 3380 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3384 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3385 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | } |
| 3387 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3388 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3389 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3393 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3394 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3395 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3396 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3397 | mb->mbxCommand, phba->pport->port_state, |
| 3398 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3399 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3400 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3401 | if (pmbox->vport) { |
| 3402 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3403 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3404 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3405 | (uint32_t)mb->mbxCommand, |
| 3406 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3407 | } |
| 3408 | else { |
| 3409 | lpfc_debugfs_disc_trc(phba->pport, |
| 3410 | LPFC_DISC_TRC_MBOX, |
| 3411 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3412 | (uint32_t)mb->mbxCommand, |
| 3413 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3414 | } |
| 3415 | } |
| 3416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | psli->slistat.mbox_cmd++; |
| 3418 | evtctr = psli->slistat.mbox_event; |
| 3419 | |
| 3420 | /* next set own bit for the adapter and copy over command word */ |
| 3421 | mb->mbxOwner = OWN_CHIP; |
| 3422 | |
| 3423 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3425 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3427 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3429 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3433 | word */ |
| 3434 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3435 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3436 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3437 | |
| 3438 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3439 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | to_slim = phba->MBslimaddr; |
| 3441 | writel(ldata, to_slim); |
| 3442 | readl(to_slim); /* flush */ |
| 3443 | |
| 3444 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3445 | /* switch over to host mailbox */ |
| 3446 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 3447 | } |
| 3448 | } |
| 3449 | |
| 3450 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | |
| 3452 | switch (flag) { |
| 3453 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3454 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3456 | /* Interrupt board to do it */ |
| 3457 | writel(CA_MBATT, phba->CAregaddr); |
| 3458 | readl(phba->CAregaddr); /* flush */ |
| 3459 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | break; |
| 3461 | |
| 3462 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3463 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3464 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3465 | /* Interrupt board to do it */ |
| 3466 | writel(CA_MBATT, phba->CAregaddr); |
| 3467 | readl(phba->CAregaddr); /* flush */ |
| 3468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3470 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3471 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | word0 = le32_to_cpu(word0); |
| 3473 | } else { |
| 3474 | /* First read mbox status word */ |
| 3475 | word0 = readl(phba->MBslimaddr); |
| 3476 | } |
| 3477 | |
| 3478 | /* Read the HBA Host Attention Register */ |
| 3479 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3480 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3481 | mb->mbxCommand) * |
| 3482 | 1000) + jiffies; |
| 3483 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3485 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3486 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3487 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3488 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3490 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3492 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | /* Check if we took a mbox interrupt while we were |
| 3496 | polling */ |
| 3497 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3498 | && (evtctr != psli->slistat.mbox_event)) |
| 3499 | break; |
| 3500 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3501 | if (i++ > 10) { |
| 3502 | spin_unlock_irqrestore(&phba->hbalock, |
| 3503 | drvr_flag); |
| 3504 | msleep(1); |
| 3505 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | |
| 3508 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3509 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3510 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3511 | word0 = le32_to_cpu(word0); |
| 3512 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3513 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3514 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | /* Check real SLIM for any errors */ |
| 3516 | slimword0 = readl(phba->MBslimaddr); |
| 3517 | slimmb = (MAILBOX_t *) & slimword0; |
| 3518 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3519 | && slimmb->mbxStatus) { |
| 3520 | psli->sli_flag &= |
| 3521 | ~LPFC_SLI2_ACTIVE; |
| 3522 | word0 = slimword0; |
| 3523 | } |
| 3524 | } |
| 3525 | } else { |
| 3526 | /* First copy command data */ |
| 3527 | word0 = readl(phba->MBslimaddr); |
| 3528 | } |
| 3529 | /* Read the HBA Host Attention Register */ |
| 3530 | ha_copy = readl(phba->HAregaddr); |
| 3531 | } |
| 3532 | |
| 3533 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 3535 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | } else { |
| 3537 | /* First copy command data */ |
| 3538 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3539 | MAILBOX_CMD_SIZE); |
| 3540 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3541 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3542 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3544 | mb->un.varDmp.word_cnt); |
| 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | writel(HA_MBATT, phba->HAregaddr); |
| 3549 | readl(phba->HAregaddr); /* flush */ |
| 3550 | |
| 3551 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3552 | status = mb->mbxStatus; |
| 3553 | } |
| 3554 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3555 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3556 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3557 | |
| 3558 | out_not_finished: |
| 3559 | if (processing_queue) { |
| 3560 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3561 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3562 | } |
| 3563 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | } |
| 3565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3566 | /** |
| 3567 | * __lpfc_sli_ringtx_put: Add an iocb to the txq. |
| 3568 | * @phba: Pointer to HBA context object. |
| 3569 | * @pring: Pointer to driver SLI ring object. |
| 3570 | * @piocb: Pointer to address of newly added command iocb. |
| 3571 | * |
| 3572 | * This function is called with hbalock held to add a command |
| 3573 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3574 | * to the ring. |
| 3575 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3576 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3577 | __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] | 3578 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | { |
| 3580 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3581 | list_add_tail(&piocb->list, &pring->txq); |
| 3582 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | } |
| 3584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3585 | /** |
| 3586 | * lpfc_sli_next_iocb: Get the next iocb in the txq. |
| 3587 | * @phba: Pointer to HBA context object. |
| 3588 | * @pring: Pointer to driver SLI ring object. |
| 3589 | * @piocb: Pointer to address of newly added command iocb. |
| 3590 | * |
| 3591 | * This function is called with hbalock held before a new |
| 3592 | * iocb is submitted to the firmware. This function checks |
| 3593 | * txq to flush the iocbs in txq to Firmware before |
| 3594 | * submitting new iocbs to the Firmware. |
| 3595 | * If there are iocbs in the txq which need to be submitted |
| 3596 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3597 | * of the txq after dequeuing it from txq. |
| 3598 | * If there is no iocb in the txq then the function will return |
| 3599 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3600 | * *piocb to find if there are more commands in the txq. |
| 3601 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | static struct lpfc_iocbq * |
| 3603 | 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] | 3604 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | { |
| 3606 | struct lpfc_iocbq * nextiocb; |
| 3607 | |
| 3608 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3609 | if (!nextiocb) { |
| 3610 | nextiocb = *piocb; |
| 3611 | *piocb = NULL; |
| 3612 | } |
| 3613 | |
| 3614 | return nextiocb; |
| 3615 | } |
| 3616 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3617 | /** |
| 3618 | * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb. |
| 3619 | * @phba: Pointer to HBA context object. |
| 3620 | * @pring: Pointer to driver SLI ring object. |
| 3621 | * @piocb: Pointer to command iocb. |
| 3622 | * @flag: Flag indicating if this command can be put into txq. |
| 3623 | * |
| 3624 | * __lpfc_sli_issue_iocb is used by other functions in the driver |
| 3625 | * to issue an iocb command to the HBA. If the PCI slot is recovering |
| 3626 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3627 | * flag is turned on, the function returns IOCB_ERROR. |
| 3628 | * When the link is down, this function allows only iocbs for |
| 3629 | * posting buffers. |
| 3630 | * This function finds next available slot in the command ring and |
| 3631 | * posts the command to the available slot and writes the port |
| 3632 | * attention register to request HBA start processing new iocb. |
| 3633 | * If there is no slot available in the ring and |
| 3634 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the |
| 3635 | * txq, otherwise the function returns IOCB_BUSY. |
| 3636 | * |
| 3637 | * This function is called with hbalock held. |
| 3638 | * The function will return success after it successfully submit the |
| 3639 | * iocb to firmware or after adding to the txq. |
| 3640 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3641 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3642 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3644 | { |
| 3645 | struct lpfc_iocbq *nextiocb; |
| 3646 | IOCB_t *iocb; |
| 3647 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3648 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3649 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3650 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3651 | lpfc_printf_log(phba, KERN_ERR, |
| 3652 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3653 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3654 | piocb->iocb.ulpCommand); |
| 3655 | dump_stack(); |
| 3656 | return IOCB_ERROR; |
| 3657 | } |
| 3658 | |
| 3659 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3660 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3661 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3662 | return IOCB_ERROR; |
| 3663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | /* |
| 3665 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3666 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3667 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | return IOCB_ERROR; |
| 3669 | |
| 3670 | /* |
| 3671 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3672 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3674 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | goto iocb_busy; |
| 3676 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3677 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3679 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | * can be issued if the link is not up. |
| 3681 | */ |
| 3682 | switch (piocb->iocb.ulpCommand) { |
| 3683 | case CMD_QUE_RING_BUF_CN: |
| 3684 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | /* |
| 3686 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3687 | * completion, iocb_cmpl MUST be 0. |
| 3688 | */ |
| 3689 | if (piocb->iocb_cmpl) |
| 3690 | piocb->iocb_cmpl = NULL; |
| 3691 | /*FALLTHROUGH*/ |
| 3692 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3693 | case CMD_CLOSE_XRI_CN: |
| 3694 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | break; |
| 3696 | default: |
| 3697 | goto iocb_busy; |
| 3698 | } |
| 3699 | |
| 3700 | /* |
| 3701 | * For FCP commands, we must be in a state where we can process link |
| 3702 | * attention events. |
| 3703 | */ |
| 3704 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3705 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3707 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3710 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3711 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3712 | |
| 3713 | if (iocb) |
| 3714 | lpfc_sli_update_ring(phba, pring); |
| 3715 | else |
| 3716 | lpfc_sli_update_full_ring(phba, pring); |
| 3717 | |
| 3718 | if (!piocb) |
| 3719 | return IOCB_SUCCESS; |
| 3720 | |
| 3721 | goto out_busy; |
| 3722 | |
| 3723 | iocb_busy: |
| 3724 | pring->stats.iocb_cmd_delay++; |
| 3725 | |
| 3726 | out_busy: |
| 3727 | |
| 3728 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3729 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | return IOCB_SUCCESS; |
| 3731 | } |
| 3732 | |
| 3733 | return IOCB_BUSY; |
| 3734 | } |
| 3735 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3737 | /** |
| 3738 | * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb. |
| 3739 | * @phba: Pointer to HBA context object. |
| 3740 | * @pring: Pointer to driver SLI ring object. |
| 3741 | * @piocb: Pointer to command iocb. |
| 3742 | * @flag: Flag indicating if this command can be put into txq. |
| 3743 | * |
| 3744 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 3745 | * function. This function gets the hbalock and calls |
| 3746 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 3747 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 3748 | * functions which do not hold hbalock. |
| 3749 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3750 | int |
| 3751 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3752 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3753 | { |
| 3754 | unsigned long iflags; |
| 3755 | int rc; |
| 3756 | |
| 3757 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 3758 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 3759 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 3760 | |
| 3761 | return rc; |
| 3762 | } |
| 3763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3764 | /** |
| 3765 | * lpfc_extra_ring_setup: Extra ring setup function. |
| 3766 | * @phba: Pointer to HBA context object. |
| 3767 | * |
| 3768 | * This function is called while driver attaches with the |
| 3769 | * HBA to setup the extra ring. The extra ring is used |
| 3770 | * only when driver needs to support target mode functionality |
| 3771 | * or IP over FC functionalities. |
| 3772 | * |
| 3773 | * This function is called with no lock held. |
| 3774 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3775 | static int |
| 3776 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 3777 | { |
| 3778 | struct lpfc_sli *psli; |
| 3779 | struct lpfc_sli_ring *pring; |
| 3780 | |
| 3781 | psli = &phba->sli; |
| 3782 | |
| 3783 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3784 | |
| 3785 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3786 | pring = &psli->ring[psli->fcp_ring]; |
| 3787 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3788 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3789 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3790 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3791 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3792 | /* and give them to the extra ring */ |
| 3793 | pring = &psli->ring[psli->extra_ring]; |
| 3794 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3795 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3796 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3797 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3798 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3799 | |
| 3800 | /* Setup default profile for this ring */ |
| 3801 | pring->iotag_max = 4096; |
| 3802 | pring->num_mask = 1; |
| 3803 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3804 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 3805 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3806 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3810 | /** |
| 3811 | * lpfc_sli_async_event_handler: ASYNC iocb handler function. |
| 3812 | * @phba: Pointer to HBA context object. |
| 3813 | * @pring: Pointer to driver SLI ring object. |
| 3814 | * @iocbq: Pointer to iocb object. |
| 3815 | * |
| 3816 | * This function is called by the slow ring event handler |
| 3817 | * function when there is an ASYNC event iocb in the ring. |
| 3818 | * This function is called with no lock held. |
| 3819 | * Currently this function handles only temperature related |
| 3820 | * ASYNC events. The function decodes the temperature sensor |
| 3821 | * event message and posts events for the management applications. |
| 3822 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3823 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3824 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 3825 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 3826 | { |
| 3827 | IOCB_t *icmd; |
| 3828 | uint16_t evt_code; |
| 3829 | uint16_t temp; |
| 3830 | struct temp_event temp_event_data; |
| 3831 | struct Scsi_Host *shost; |
| 3832 | |
| 3833 | icmd = &iocbq->iocb; |
| 3834 | evt_code = icmd->un.asyncstat.evt_code; |
| 3835 | temp = icmd->ulpContext; |
| 3836 | |
| 3837 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 3838 | (evt_code != ASYNC_TEMP_SAFE)) { |
| 3839 | lpfc_printf_log(phba, |
| 3840 | KERN_ERR, |
| 3841 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3842 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3843 | " evt_code 0x%x\n", |
| 3844 | pring->ringno, |
| 3845 | icmd->un.asyncstat.evt_code); |
| 3846 | return; |
| 3847 | } |
| 3848 | temp_event_data.data = (uint32_t)temp; |
| 3849 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 3850 | if (evt_code == ASYNC_TEMP_WARN) { |
| 3851 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 3852 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3853 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3854 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3855 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3856 | "corrective action. temperature : %d Celsius\n", |
| 3857 | temp); |
| 3858 | } |
| 3859 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 3860 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 3861 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3862 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3863 | LOG_TEMP, |
| 3864 | "0340 Adapter temperature is OK now. " |
| 3865 | "temperature : %d Celsius\n", |
| 3866 | temp); |
| 3867 | } |
| 3868 | |
| 3869 | /* Send temperature change event to applications */ |
| 3870 | shost = lpfc_shost_from_vport(phba->pport); |
| 3871 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3872 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 3873 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 3874 | |
| 3875 | } |
| 3876 | |
| 3877 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3878 | /** |
| 3879 | * lpfc_sli_setup: SLI ring setup function. |
| 3880 | * @phba: Pointer to HBA context object. |
| 3881 | * |
| 3882 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 3883 | * number of iocbs per ring and iotags. This function is |
| 3884 | * called while driver attach to the HBA and before the |
| 3885 | * interrupts are enabled. So there is no need for locking. |
| 3886 | * |
| 3887 | * This function always returns 0. |
| 3888 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | int |
| 3890 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 3891 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3892 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | struct lpfc_sli *psli = &phba->sli; |
| 3894 | struct lpfc_sli_ring *pring; |
| 3895 | |
| 3896 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 3897 | psli->sli_flag = 0; |
| 3898 | psli->fcp_ring = LPFC_FCP_RING; |
| 3899 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3900 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3902 | psli->iocbq_lookup = NULL; |
| 3903 | psli->iocbq_lookup_len = 0; |
| 3904 | psli->last_iotag = 0; |
| 3905 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | for (i = 0; i < psli->num_rings; i++) { |
| 3907 | pring = &psli->ring[i]; |
| 3908 | switch (i) { |
| 3909 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 3910 | /* numCiocb and numRiocb are used in config_port */ |
| 3911 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 3912 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 3913 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3914 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3915 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3916 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3917 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3918 | SLI3_IOCB_CMD_SIZE : |
| 3919 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3920 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3921 | SLI3_IOCB_RSP_SIZE : |
| 3922 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | pring->iotag_ctr = 0; |
| 3924 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3925 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | pring->fast_iotag = pring->iotag_max; |
| 3927 | pring->num_mask = 0; |
| 3928 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3929 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | /* numCiocb and numRiocb are used in config_port */ |
| 3931 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 3932 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3933 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3934 | SLI3_IOCB_CMD_SIZE : |
| 3935 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3936 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3937 | SLI3_IOCB_RSP_SIZE : |
| 3938 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3939 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | pring->num_mask = 0; |
| 3941 | break; |
| 3942 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 3943 | /* numCiocb and numRiocb are used in config_port */ |
| 3944 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 3945 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3946 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3947 | SLI3_IOCB_CMD_SIZE : |
| 3948 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3949 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3950 | SLI3_IOCB_RSP_SIZE : |
| 3951 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | pring->fast_iotag = 0; |
| 3953 | pring->iotag_ctr = 0; |
| 3954 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3955 | pring->lpfc_sli_rcv_async_status = |
| 3956 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | pring->num_mask = 4; |
| 3958 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 3959 | pring->prt[0].rctl = FC_ELS_REQ; |
| 3960 | pring->prt[0].type = FC_ELS_DATA; |
| 3961 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3962 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3963 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 3964 | pring->prt[1].rctl = FC_ELS_RSP; |
| 3965 | pring->prt[1].type = FC_ELS_DATA; |
| 3966 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3967 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 3969 | /* NameServer Inquiry */ |
| 3970 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 3971 | /* NameServer */ |
| 3972 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 3973 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3974 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 3976 | /* NameServer response */ |
| 3977 | pring->prt[3].rctl = FC_SOL_CTL; |
| 3978 | /* NameServer */ |
| 3979 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 3980 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3981 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | break; |
| 3983 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3984 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3985 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3987 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3989 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 3990 | "SLI2 SLIM Data: x%x x%lx\n", |
| 3991 | phba->brd_no, totiocbsize, |
| 3992 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3994 | if (phba->cfg_multi_ring_support == 2) |
| 3995 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | |
| 3997 | return 0; |
| 3998 | } |
| 3999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4000 | /** |
| 4001 | * lpfc_sli_queue_setup: Queue initialization function. |
| 4002 | * @phba: Pointer to HBA context object. |
| 4003 | * |
| 4004 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4005 | * ring. This function also initializes ring indices of each ring. |
| 4006 | * This function is called during the initialization of the SLI |
| 4007 | * interface of an HBA. |
| 4008 | * This function is called with no lock held and always returns |
| 4009 | * 1. |
| 4010 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4012 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | { |
| 4014 | struct lpfc_sli *psli; |
| 4015 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4016 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | |
| 4018 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4019 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4021 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4023 | for (i = 0; i < psli->num_rings; i++) { |
| 4024 | pring = &psli->ring[i]; |
| 4025 | pring->ringno = i; |
| 4026 | pring->next_cmdidx = 0; |
| 4027 | pring->local_getidx = 0; |
| 4028 | pring->cmdidx = 0; |
| 4029 | INIT_LIST_HEAD(&pring->txq); |
| 4030 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4031 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4032 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4035 | spin_unlock_irq(&phba->hbalock); |
| 4036 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | } |
| 4038 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4039 | /** |
| 4040 | * lpfc_sli_host_down: Vport cleanup function. |
| 4041 | * @vport: Pointer to virtual port object. |
| 4042 | * |
| 4043 | * lpfc_sli_host_down is called to clean up the resources |
| 4044 | * associated with a vport before destroying virtual |
| 4045 | * port data structures. |
| 4046 | * This function does following operations: |
| 4047 | * - Free discovery resources associated with this virtual |
| 4048 | * port. |
| 4049 | * - Free iocbs associated with this virtual port in |
| 4050 | * the txq. |
| 4051 | * - Send abort for all iocb commands associated with this |
| 4052 | * vport in txcmplq. |
| 4053 | * |
| 4054 | * This function is called with no lock held and always returns 1. |
| 4055 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4057 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4058 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4059 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | struct lpfc_hba *phba = vport->phba; |
| 4061 | struct lpfc_sli *psli = &phba->sli; |
| 4062 | struct lpfc_sli_ring *pring; |
| 4063 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4064 | int i; |
| 4065 | unsigned long flags = 0; |
| 4066 | uint16_t prev_pring_flag; |
| 4067 | |
| 4068 | lpfc_cleanup_discovery_resources(vport); |
| 4069 | |
| 4070 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4071 | for (i = 0; i < psli->num_rings; i++) { |
| 4072 | pring = &psli->ring[i]; |
| 4073 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4074 | /* Only slow rings */ |
| 4075 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4076 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4077 | /* Set the lpfc data pending flag */ |
| 4078 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4079 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4080 | /* |
| 4081 | * Error everything on the txq since these iocbs have not been |
| 4082 | * given to the FW yet. |
| 4083 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4084 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4085 | if (iocb->vport != vport) |
| 4086 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4087 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4088 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | /* Next issue ABTS for everything on the txcmplq */ |
| 4092 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4093 | list) { |
| 4094 | if (iocb->vport != vport) |
| 4095 | continue; |
| 4096 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4097 | } |
| 4098 | |
| 4099 | pring->flag = prev_pring_flag; |
| 4100 | } |
| 4101 | |
| 4102 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4103 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4104 | while (!list_empty(&completions)) { |
| 4105 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
| 4106 | |
| 4107 | if (!iocb->iocb_cmpl) |
| 4108 | lpfc_sli_release_iocbq(phba, iocb); |
| 4109 | else { |
| 4110 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4111 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4112 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 4113 | } |
| 4114 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4115 | return 1; |
| 4116 | } |
| 4117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4118 | /** |
| 4119 | * lpfc_sli_hba_down: Resource cleanup function for the HBA. |
| 4120 | * @phba: Pointer to HBA context object. |
| 4121 | * |
| 4122 | * This function cleans up all iocb, buffers, mailbox commands |
| 4123 | * while shutting down the HBA. This function is called with no |
| 4124 | * lock held and always returns 1. |
| 4125 | * This function does the following to cleanup driver resources: |
| 4126 | * - Free discovery resources for each virtual port |
| 4127 | * - Cleanup any pending fabric iocbs |
| 4128 | * - Iterate through the iocb txq and free each entry |
| 4129 | * in the list. |
| 4130 | * - Free up any buffer posted to the HBA |
| 4131 | * - Free mailbox commands in the mailbox queue. |
| 4132 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4133 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4135 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4136 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4139 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | LPFC_MBOXQ_t *pmb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4141 | struct lpfc_iocbq *iocb; |
| 4142 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | int i; |
| 4144 | unsigned long flags = 0; |
| 4145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | lpfc_hba_down_prep(phba); |
| 4147 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4148 | lpfc_fabric_abort_hba(phba); |
| 4149 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | for (i = 0; i < psli->num_rings; i++) { |
| 4152 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4153 | /* Only slow rings */ |
| 4154 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4155 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4156 | /* Set the lpfc data pending flag */ |
| 4157 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 | |
| 4160 | /* |
| 4161 | * Error everything on the txq since these iocbs have not been |
| 4162 | * given to the FW yet. |
| 4163 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4164 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | pring->txq_cnt = 0; |
| 4166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4168 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4169 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4170 | while (!list_empty(&completions)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4171 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4172 | cmd = &iocb->iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4173 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | if (!iocb->iocb_cmpl) |
| 4175 | lpfc_sli_release_iocbq(phba, iocb); |
| 4176 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4177 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4178 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4179 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4181 | } |
| 4182 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4183 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4184 | list_splice_init(&phba->elsbuf, &completions); |
| 4185 | phba->elsbuf_cnt = 0; |
| 4186 | phba->elsbuf_prev_cnt = 0; |
| 4187 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4188 | |
| 4189 | while (!list_empty(&completions)) { |
| 4190 | list_remove_head(&completions, buf_ptr, |
| 4191 | struct lpfc_dmabuf, list); |
| 4192 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4193 | kfree(buf_ptr); |
| 4194 | } |
| 4195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | /* Return any active mbox cmds */ |
| 4197 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4198 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4199 | |
| 4200 | spin_lock(&phba->pport->work_port_lock); |
| 4201 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4202 | spin_unlock(&phba->pport->work_port_lock); |
| 4203 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4204 | /* Return any pending or completed mbox cmds */ |
| 4205 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4206 | if (psli->mbox_active) { |
| 4207 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4209 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4211 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4212 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4213 | |
| 4214 | while (!list_empty(&completions)) { |
| 4215 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4217 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | return 1; |
| 4221 | } |
| 4222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4223 | /** |
| 4224 | * lpfc_sli_pcimem_bcopy: SLI memory copy function. |
| 4225 | * @srcp: Source memory pointer. |
| 4226 | * @destp: Destination memory pointer. |
| 4227 | * @cnt: Number of words required to be copied. |
| 4228 | * |
| 4229 | * This function is used for copying data between driver memory |
| 4230 | * and the SLI memory. This function also changes the endianness |
| 4231 | * of each word if native endianness is different from SLI |
| 4232 | * endianness. This function can be called with or without |
| 4233 | * lock. |
| 4234 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 | void |
| 4236 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4237 | { |
| 4238 | uint32_t *src = srcp; |
| 4239 | uint32_t *dest = destp; |
| 4240 | uint32_t ldata; |
| 4241 | int i; |
| 4242 | |
| 4243 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4244 | ldata = *src; |
| 4245 | ldata = le32_to_cpu(ldata); |
| 4246 | *dest = ldata; |
| 4247 | src++; |
| 4248 | dest++; |
| 4249 | } |
| 4250 | } |
| 4251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4252 | |
| 4253 | /** |
| 4254 | * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq. |
| 4255 | * @phba: Pointer to HBA context object. |
| 4256 | * @pring: Pointer to driver SLI ring object. |
| 4257 | * @mp: Pointer to driver buffer object. |
| 4258 | * |
| 4259 | * This function is called with no lock held. |
| 4260 | * It always return zero after adding the buffer to the postbufq |
| 4261 | * buffer list. |
| 4262 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4263 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4264 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4265 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | { |
| 4267 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4268 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | return 0; |
| 4274 | } |
| 4275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4276 | /** |
| 4277 | * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted |
| 4278 | * using CMD_QUE_XRI64_CX iocb. |
| 4279 | * @phba: Pointer to HBA context object. |
| 4280 | * |
| 4281 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4282 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4283 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4284 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4285 | * The function returns the allocated tag. The function is called with |
| 4286 | * no locks held. |
| 4287 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4288 | uint32_t |
| 4289 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4290 | { |
| 4291 | spin_lock_irq(&phba->hbalock); |
| 4292 | phba->buffer_tag_count++; |
| 4293 | /* |
| 4294 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4295 | * a tag assigned by HBQ. |
| 4296 | */ |
| 4297 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4298 | spin_unlock_irq(&phba->hbalock); |
| 4299 | return phba->buffer_tag_count; |
| 4300 | } |
| 4301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4302 | /** |
| 4303 | * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with |
| 4304 | * posted using CMD_QUE_XRI64_CX iocb. |
| 4305 | * @phba: Pointer to HBA context object. |
| 4306 | * @pring: Pointer to driver SLI ring object. |
| 4307 | * @tag: Buffer tag. |
| 4308 | * |
| 4309 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4310 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4311 | * iocb is posted to the response ring with the tag of the buffer. |
| 4312 | * This function searches the pring->postbufq list using the tag |
| 4313 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4314 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4315 | * buffer is returned to the caller else NULL is returned. |
| 4316 | * This function is called with no lock held. |
| 4317 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4318 | struct lpfc_dmabuf * |
| 4319 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4320 | uint32_t tag) |
| 4321 | { |
| 4322 | struct lpfc_dmabuf *mp, *next_mp; |
| 4323 | struct list_head *slp = &pring->postbufq; |
| 4324 | |
| 4325 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4326 | spin_lock_irq(&phba->hbalock); |
| 4327 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4328 | if (mp->buffer_tag == tag) { |
| 4329 | list_del_init(&mp->list); |
| 4330 | pring->postbufq_cnt--; |
| 4331 | spin_unlock_irq(&phba->hbalock); |
| 4332 | return mp; |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | spin_unlock_irq(&phba->hbalock); |
| 4337 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4338 | "0410 Cannot find virtual addr for buffer tag on " |
| 4339 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4340 | pring->ringno, (unsigned long) tag, |
| 4341 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4342 | |
| 4343 | return NULL; |
| 4344 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4346 | /** |
| 4347 | * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for |
| 4348 | * unsolicited ct and els events. |
| 4349 | * @phba: Pointer to HBA context object. |
| 4350 | * @pring: Pointer to driver SLI ring object. |
| 4351 | * @phys: DMA address of the buffer. |
| 4352 | * |
| 4353 | * This function searches the buffer list using the dma_address |
| 4354 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4355 | * corresponding to the dma_address. The function returns the |
| 4356 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4357 | * This function is called by the ct and els unsolicited event |
| 4358 | * handlers to get the buffer associated with the unsolicited |
| 4359 | * event. |
| 4360 | * |
| 4361 | * This function is called with no lock held. |
| 4362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | struct lpfc_dmabuf * |
| 4364 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4365 | dma_addr_t phys) |
| 4366 | { |
| 4367 | struct lpfc_dmabuf *mp, *next_mp; |
| 4368 | struct list_head *slp = &pring->postbufq; |
| 4369 | |
| 4370 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4372 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4373 | if (mp->phys == phys) { |
| 4374 | list_del_init(&mp->list); |
| 4375 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4376 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | return mp; |
| 4378 | } |
| 4379 | } |
| 4380 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4383 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4384 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4385 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4387 | return NULL; |
| 4388 | } |
| 4389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4390 | /** |
| 4391 | * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs. |
| 4392 | * @phba: Pointer to HBA context object. |
| 4393 | * @cmdiocb: Pointer to driver command iocb object. |
| 4394 | * @rspiocb: Pointer to driver response iocb object. |
| 4395 | * |
| 4396 | * This function is the completion handler for the abort iocbs for |
| 4397 | * ELS commands. This function is called from the ELS ring event |
| 4398 | * handler with no lock held. This function frees memory resources |
| 4399 | * associated with the abort iocb. |
| 4400 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4402 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4403 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4405 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4406 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4407 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4408 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4409 | |
| 4410 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4411 | |
| 4412 | if (irsp->ulpStatus) { |
| 4413 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4414 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4415 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4416 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4417 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4418 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4419 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4420 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4421 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4422 | "with tag %x context %x, abort status %x, " |
| 4423 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4424 | abort_iocb, abort_iotag, abort_context, |
| 4425 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4426 | |
| 4427 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4428 | * If the iocb is not found in Firmware queue the iocb |
| 4429 | * might have completed already. Do not free it again. |
| 4430 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4431 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4432 | spin_unlock_irq(&phba->hbalock); |
| 4433 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4434 | return; |
| 4435 | } |
| 4436 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4437 | * make sure we have the right iocbq before taking it |
| 4438 | * off the txcmplq and try to call completion routine. |
| 4439 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4440 | if (!abort_iocb || |
| 4441 | abort_iocb->iocb.ulpContext != abort_context || |
| 4442 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4443 | spin_unlock_irq(&phba->hbalock); |
| 4444 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4445 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4446 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4447 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4448 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4449 | /* Firmware could still be in progress of DMAing |
| 4450 | * payload, so don't free data buffer till after |
| 4451 | * a hbeat. |
| 4452 | */ |
| 4453 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4454 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4455 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4456 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4457 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4458 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4462 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | return; |
| 4464 | } |
| 4465 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4466 | /** |
| 4467 | * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command. |
| 4468 | * @phba: Pointer to HBA context object. |
| 4469 | * @cmdiocb: Pointer to driver command iocb object. |
| 4470 | * @rspiocb: Pointer to driver response iocb object. |
| 4471 | * |
| 4472 | * The function is called from SLI ring event handler with no |
| 4473 | * lock held. This function is the completion handler for ELS commands |
| 4474 | * which are aborted. The function frees memory resources used for |
| 4475 | * the aborted ELS commands. |
| 4476 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4477 | static void |
| 4478 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4479 | struct lpfc_iocbq *rspiocb) |
| 4480 | { |
| 4481 | IOCB_t *irsp = &rspiocb->iocb; |
| 4482 | |
| 4483 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4484 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4485 | "0133 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4486 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4487 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4488 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4489 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4490 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4491 | else |
| 4492 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4493 | return; |
| 4494 | } |
| 4495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4496 | /** |
| 4497 | * lpfc_sli_issue_abort_iotag: Abort function for a command iocb. |
| 4498 | * @phba: Pointer to HBA context object. |
| 4499 | * @pring: Pointer to driver SLI ring object. |
| 4500 | * @cmdiocb: Pointer to driver command iocb object. |
| 4501 | * |
| 4502 | * This function issues an abort iocb for the provided command |
| 4503 | * iocb. This function is called with hbalock held. |
| 4504 | * The function returns 0 when it fails due to memory allocation |
| 4505 | * failure or when the command iocb is an abort request. |
| 4506 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4508 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4509 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4512 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | IOCB_t *icmd = NULL; |
| 4514 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4515 | int retval = IOCB_ERROR; |
| 4516 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4517 | /* |
| 4518 | * There are certain command types we don't want to abort. And we |
| 4519 | * don't want to abort commands that are already in the process of |
| 4520 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4521 | */ |
| 4522 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4524 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4525 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4526 | return 0; |
| 4527 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4528 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4529 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4530 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4531 | if ((vport->load_flag & FC_UNLOADING) && |
| 4532 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4534 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4535 | else |
| 4536 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4537 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4538 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | |
| 4540 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4541 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | if (abtsiocbp == NULL) |
| 4543 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4545 | /* This signals the response to set the correct status |
| 4546 | * before calling the completion handler. |
| 4547 | */ |
| 4548 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4549 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4551 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4552 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4553 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4555 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4557 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4558 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4559 | else |
| 4560 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4561 | |
| 4562 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4563 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4565 | "0339 Abort xri x%x, original iotag x%x, " |
| 4566 | "abort cmd iotag x%x\n", |
| 4567 | iabt->un.acxri.abortContextTag, |
| 4568 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4569 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4570 | |
| 4571 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | /* |
| 4573 | * Caller to this routine should check for IOCB_ERROR |
| 4574 | * and handle it properly. This routine no longer removes |
| 4575 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4576 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4577 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4578 | } |
| 4579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4580 | /** |
| 4581 | * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands |
| 4582 | * associated with a vport/SCSI target/lun. |
| 4583 | * @iocbq: Pointer to driver iocb object. |
| 4584 | * @vport: Pointer to driver virtual port object. |
| 4585 | * @tgt_id: SCSI ID of the target. |
| 4586 | * @lun_id: LUN ID of the scsi device. |
| 4587 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4588 | * |
| 4589 | * This function acts as iocb filter for functions which abort or count |
| 4590 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4591 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4592 | * 1 if the filtering criteria is not met. |
| 4593 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4594 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4595 | * lun_id parameter. |
| 4596 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4597 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4598 | * parameters. |
| 4599 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4600 | * given iocb is for the SCSI host associated with the given vport. |
| 4601 | * This function is called with no locks held. |
| 4602 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4603 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4604 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4605 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4606 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4607 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4608 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | int rc = 1; |
| 4610 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4611 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4612 | return rc; |
| 4613 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4614 | if (iocbq->vport != vport) |
| 4615 | return rc; |
| 4616 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4617 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4618 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4619 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4620 | return rc; |
| 4621 | |
| 4622 | switch (ctx_cmd) { |
| 4623 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4624 | if ((lpfc_cmd->rdata->pnode) && |
| 4625 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4626 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4627 | rc = 0; |
| 4628 | break; |
| 4629 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4630 | if ((lpfc_cmd->rdata->pnode) && |
| 4631 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 | rc = 0; |
| 4633 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | case LPFC_CTX_HOST: |
| 4635 | rc = 0; |
| 4636 | break; |
| 4637 | default: |
| 4638 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4639 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4640 | break; |
| 4641 | } |
| 4642 | |
| 4643 | return rc; |
| 4644 | } |
| 4645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4646 | /** |
| 4647 | * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending. |
| 4648 | * @vport: Pointer to virtual port. |
| 4649 | * @tgt_id: SCSI ID of the target. |
| 4650 | * @lun_id: LUN ID of the scsi device. |
| 4651 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4652 | * |
| 4653 | * This function returns number of FCP commands pending for the vport. |
| 4654 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4655 | * commands pending on the vport associated with SCSI device specified |
| 4656 | * by tgt_id and lun_id parameters. |
| 4657 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4658 | * commands pending on the vport associated with SCSI target specified |
| 4659 | * by tgt_id parameter. |
| 4660 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4661 | * commands pending on the vport. |
| 4662 | * This function returns the number of iocbs which satisfy the filter. |
| 4663 | * This function is called without any lock held. |
| 4664 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4666 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4667 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4669 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4670 | struct lpfc_iocbq *iocbq; |
| 4671 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4672 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4673 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4674 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4676 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4677 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4678 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4680 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | return sum; |
| 4682 | } |
| 4683 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4684 | /** |
| 4685 | * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted |
| 4686 | * FCP iocb. |
| 4687 | * @phba: Pointer to HBA context object |
| 4688 | * @cmdiocb: Pointer to command iocb object. |
| 4689 | * @rspiocb: Pointer to response iocb object. |
| 4690 | * |
| 4691 | * This function is called when an aborted FCP iocb completes. This |
| 4692 | * function is called by the ring event handler with no lock held. |
| 4693 | * This function frees the iocb. |
| 4694 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4695 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4696 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4697 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4698 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4699 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4700 | return; |
| 4701 | } |
| 4702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4703 | /** |
| 4704 | * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands |
| 4705 | * pending on a SCSI host(vport)/target/lun. |
| 4706 | * @vport: Pointer to virtual port. |
| 4707 | * @pring: Pointer to driver SLI ring object. |
| 4708 | * @tgt_id: SCSI ID of the target. |
| 4709 | * @lun_id: LUN ID of the scsi device. |
| 4710 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4711 | * |
| 4712 | * This function sends an abort command for every SCSI command |
| 4713 | * associated with the given virtual port pending on the ring |
| 4714 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 4715 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 4716 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 4717 | * parameters |
| 4718 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 4719 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 4720 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 4721 | * FCP iocbs associated with virtual port. |
| 4722 | * This function returns number of iocbs it failed to abort. |
| 4723 | * This function is called with no locks held. |
| 4724 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4725 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4726 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 4727 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4729 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4730 | struct lpfc_iocbq *iocbq; |
| 4731 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4734 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4736 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 4737 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4739 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | continue; |
| 4742 | |
| 4743 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4744 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | if (abtsiocb == NULL) { |
| 4746 | errcnt++; |
| 4747 | continue; |
| 4748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4750 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4752 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 4753 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 4754 | abtsiocb->iocb.ulpLe = 1; |
| 4755 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4756 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4757 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4758 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 4760 | else |
| 4761 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 4762 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4763 | /* Setup callback routine and issue the command. */ |
| 4764 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 4766 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4767 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | errcnt++; |
| 4769 | continue; |
| 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | return errcnt; |
| 4774 | } |
| 4775 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4776 | /** |
| 4777 | * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using |
| 4778 | * lpfc_sli_issue_iocb_wait. |
| 4779 | * @phba: Pointer to HBA context object. |
| 4780 | * @cmdiocbq: Pointer to command iocb. |
| 4781 | * @rspiocbq: Pointer to response iocb. |
| 4782 | * |
| 4783 | * This function is the completion handler for iocbs issued using |
| 4784 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 4785 | * ring event handler function without any lock held. This function |
| 4786 | * can be called from both worker thread context and interrupt |
| 4787 | * context. This function also can be called from other thread which |
| 4788 | * cleans up the SLI layer objects. |
| 4789 | * This function copy the contents of the response iocb to the |
| 4790 | * response iocb memory object provided by the caller of |
| 4791 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4792 | * sleeps for the iocb completion. |
| 4793 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4794 | static void |
| 4795 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 4796 | struct lpfc_iocbq *cmdiocbq, |
| 4797 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4798 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4799 | wait_queue_head_t *pdone_q; |
| 4800 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4802 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4803 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 4804 | if (cmdiocbq->context2 && rspiocbq) |
| 4805 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 4806 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 4807 | |
| 4808 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4809 | if (pdone_q) |
| 4810 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4811 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | return; |
| 4813 | } |
| 4814 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4815 | /** |
| 4816 | * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands. |
| 4817 | * @phba: Pointer to HBA context object.. |
| 4818 | * @pring: Pointer to sli ring. |
| 4819 | * @piocb: Pointer to command iocb. |
| 4820 | * @prspiocbq: Pointer to response iocb. |
| 4821 | * @timeout: Timeout in number of seconds. |
| 4822 | * |
| 4823 | * This function issues the iocb to firmware and waits for the |
| 4824 | * iocb to complete. If the iocb command is not |
| 4825 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 4826 | * Caller should not free the iocb resources if this function |
| 4827 | * returns IOCB_TIMEDOUT. |
| 4828 | * The function waits for the iocb completion using an |
| 4829 | * non-interruptible wait. |
| 4830 | * This function will sleep while waiting for iocb completion. |
| 4831 | * So, this function should not be called from any context which |
| 4832 | * does not allow sleeping. Due to the same reason, this function |
| 4833 | * cannot be called with interrupt disabled. |
| 4834 | * This function assumes that the iocb completions occur while |
| 4835 | * this function sleep. So, this function cannot be called from |
| 4836 | * the thread which process iocb completion for this ring. |
| 4837 | * This function clears the iocb_flag of the iocb object before |
| 4838 | * issuing the iocb and the iocb completion handler sets this |
| 4839 | * flag and wakes this thread when the iocb completes. |
| 4840 | * The contents of the response iocb will be copied to prspiocbq |
| 4841 | * by the completion handler when the command completes. |
| 4842 | * This function returns IOCB_SUCCESS when success. |
| 4843 | * This function is called with no lock held. |
| 4844 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4846 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 4847 | struct lpfc_sli_ring *pring, |
| 4848 | struct lpfc_iocbq *piocb, |
| 4849 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4850 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4851 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4852 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4853 | long timeleft, timeout_req = 0; |
| 4854 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4855 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | |
| 4857 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4858 | * If the caller has provided a response iocbq buffer, then context2 |
| 4859 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4861 | if (prspiocbq) { |
| 4862 | if (piocb->context2) |
| 4863 | return IOCB_ERROR; |
| 4864 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4865 | } |
| 4866 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4867 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 4868 | piocb->context_un.wait_queue = &done_q; |
| 4869 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4871 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4872 | creg_val = readl(phba->HCregaddr); |
| 4873 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 4874 | writel(creg_val, phba->HCregaddr); |
| 4875 | readl(phba->HCregaddr); /* flush */ |
| 4876 | } |
| 4877 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4878 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 4879 | if (retval == IOCB_SUCCESS) { |
| 4880 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4881 | timeleft = wait_event_timeout(done_q, |
| 4882 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 4883 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4885 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 4886 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4887 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4888 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4889 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4890 | "0338 IOCB wait timeout error - no " |
| 4891 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4892 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4893 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4895 | "0330 IOCB wake NOT set, " |
| 4896 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4897 | timeout, (timeleft / jiffies)); |
| 4898 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4900 | } else { |
| 4901 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4902 | ":0332 IOCB wait issue failed, Data x%x\n", |
| 4903 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4904 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4905 | } |
| 4906 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4907 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4908 | creg_val = readl(phba->HCregaddr); |
| 4909 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 4910 | writel(creg_val, phba->HCregaddr); |
| 4911 | readl(phba->HCregaddr); /* flush */ |
| 4912 | } |
| 4913 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4914 | if (prspiocbq) |
| 4915 | piocb->context2 = NULL; |
| 4916 | |
| 4917 | piocb->context_un.wait_queue = NULL; |
| 4918 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | return retval; |
| 4920 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4921 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4922 | /** |
| 4923 | * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox. |
| 4924 | * @phba: Pointer to HBA context object. |
| 4925 | * @pmboxq: Pointer to driver mailbox object. |
| 4926 | * @timeout: Timeout in number of seconds. |
| 4927 | * |
| 4928 | * This function issues the mailbox to firmware and waits for the |
| 4929 | * mailbox command to complete. If the mailbox command is not |
| 4930 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 4931 | * The function waits for the mailbox completion using an |
| 4932 | * interruptible wait. If the thread is woken up due to a |
| 4933 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 4934 | * should not free the mailbox resources, if this function returns |
| 4935 | * MBX_TIMEOUT. |
| 4936 | * This function will sleep while waiting for mailbox completion. |
| 4937 | * So, this function should not be called from any context which |
| 4938 | * does not allow sleeping. Due to the same reason, this function |
| 4939 | * cannot be called with interrupt disabled. |
| 4940 | * This function assumes that the mailbox completion occurs while |
| 4941 | * this function sleep. So, this function cannot be called from |
| 4942 | * the worker thread which processes mailbox completion. |
| 4943 | * This function is called in the context of HBA management |
| 4944 | * applications. |
| 4945 | * This function returns MBX_SUCCESS when successful. |
| 4946 | * This function is called with no lock held. |
| 4947 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4948 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4949 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4950 | uint32_t timeout) |
| 4951 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4952 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4954 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | |
| 4956 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4957 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4958 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4959 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4960 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | /* setup wake call as IOCB callback */ |
| 4962 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 4963 | /* setup context field to pass wait_queue pointer to wake function */ |
| 4964 | pmboxq->context1 = &done_q; |
| 4965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | /* now issue the command */ |
| 4967 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 4968 | |
| 4969 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4970 | wait_event_interruptible_timeout(done_q, |
| 4971 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 4972 | timeout * HZ); |
| 4973 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4974 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4975 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4976 | /* |
| 4977 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 4978 | * else do not free the resources. |
| 4979 | */ |
| 4980 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4981 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4982 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4983 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4984 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4985 | } |
| 4986 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | } |
| 4988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | return retval; |
| 4990 | } |
| 4991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4992 | /** |
| 4993 | * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function. |
| 4994 | * @phba: Pointer to HBA context. |
| 4995 | * |
| 4996 | * This function is called to cleanup any pending mailbox |
| 4997 | * objects in the driver queue before bringing the HBA offline. |
| 4998 | * This function is called while resetting the HBA. |
| 4999 | * The function is called without any lock held. The function |
| 5000 | * takes hbalock to update SLI data structure. |
| 5001 | * This function returns 1 when there is an active mailbox |
| 5002 | * command pending else returns 0. |
| 5003 | **/ |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5004 | int |
| 5005 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 5006 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5008 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5009 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5010 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5011 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5012 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 5013 | return 1; |
| 5014 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5015 | /* |
| 5016 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 5017 | * did finish. This way we won't get the misleading |
| 5018 | * "Stray Mailbox Interrupt" message. |
| 5019 | */ |
| 5020 | spin_lock_irq(&phba->hbalock); |
| 5021 | ha_copy = phba->work_ha; |
| 5022 | phba->work_ha &= ~HA_MBATT; |
| 5023 | spin_unlock_irq(&phba->hbalock); |
| 5024 | |
| 5025 | if (ha_copy & HA_MBATT) |
| 5026 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 5027 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5028 | |
| 5029 | msleep(1); |
| 5030 | } |
| 5031 | |
| 5032 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 5033 | } |
| 5034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5035 | /** |
| 5036 | * lpfc_intr_handler: The interrupt handler of lpfc driver. |
| 5037 | * @irq: Interrupt number. |
| 5038 | * @dev_id: The device context pointer. |
| 5039 | * |
| 5040 | * This function is called from the PCI layer when there is |
| 5041 | * an event in the HBA which requires driver attention. When |
| 5042 | * the PCI slot is in error recovery or the HBA is undergoing |
| 5043 | * initialization the interrupt handler will not process the |
| 5044 | * interrupt. |
| 5045 | * The error attention, link attention and els ring attention |
| 5046 | * events are handled by the worker thread. The interrupt |
| 5047 | * handler signals the worker thread and returns for these |
| 5048 | * events. |
| 5049 | * The SCSI ring event and mailbox events are handled in the |
| 5050 | * interrupt context. |
| 5051 | * This function is called without any lock held. It gets the |
| 5052 | * hbalock to access and update SLI data structures. |
| 5053 | * This function returns IRQ_HANDLED when interrupt is handled |
| 5054 | * else it returns IRQ_NONE. |
| 5055 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5057 | lpfc_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5058 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5059 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5060 | uint32_t ha_copy; |
| 5061 | uint32_t work_ha_copy; |
| 5062 | unsigned long status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5063 | uint32_t control; |
| 5064 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5065 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5066 | struct lpfc_vport *vport; |
| 5067 | struct lpfc_nodelist *ndlp; |
| 5068 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5069 | LPFC_MBOXQ_t *pmb; |
| 5070 | int rc; |
| 5071 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5072 | /* |
| 5073 | * Get the driver's phba structure from the dev_id and |
| 5074 | * assume the HBA is not interrupting. |
| 5075 | */ |
| 5076 | phba = (struct lpfc_hba *) dev_id; |
| 5077 | |
| 5078 | if (unlikely(!phba)) |
| 5079 | return IRQ_NONE; |
| 5080 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 5081 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 5082 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5083 | return IRQ_NONE; |
| 5084 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5085 | phba->sli.slistat.sli_intr++; |
| 5086 | |
| 5087 | /* |
| 5088 | * Call the HBA to see if it is interrupting. If not, don't claim |
| 5089 | * the interrupt |
| 5090 | */ |
| 5091 | |
| 5092 | /* Ignore all interrupts during initialization. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5093 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5094 | return IRQ_NONE; |
| 5095 | |
| 5096 | /* |
| 5097 | * Read host attention register to determine interrupt source |
| 5098 | * Clear Attention Sources, except Error Attention (to |
| 5099 | * preserve status) and Link Attention |
| 5100 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5101 | spin_lock(&phba->hbalock); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 5102 | if (phba->sli3_options & LPFC_SLI3_INB_ENABLED && |
| 5103 | (phba->inb_last_counter != *phba->inb_counter)) { |
| 5104 | phba->inb_last_counter = *phba->inb_counter; |
| 5105 | ha_copy = le32_to_cpu(*phba->inb_ha_copy); |
| 5106 | } else |
| 5107 | ha_copy = readl(phba->HAregaddr); |
| 5108 | if (unlikely(!ha_copy)) { |
| 5109 | spin_unlock(&phba->hbalock); |
| 5110 | return IRQ_NONE; |
| 5111 | } |
James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 5112 | /* If somebody is waiting to handle an eratt don't process it |
| 5113 | * here. The brdkill function will do this. |
| 5114 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5115 | if (phba->link_flag & LS_IGNORE_ERATT) |
James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 5116 | ha_copy &= ~HA_ERATT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5118 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5119 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5121 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5122 | |
| 5123 | if (unlikely(work_ha_copy)) { |
| 5124 | if (work_ha_copy & HA_LATT) { |
| 5125 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5126 | /* |
| 5127 | * Turn off Link Attention interrupts |
| 5128 | * until CLEAR_LA done |
| 5129 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5130 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5132 | control = readl(phba->HCregaddr); |
| 5133 | control &= ~HC_LAINT_ENA; |
| 5134 | writel(control, phba->HCregaddr); |
| 5135 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5136 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5137 | } |
| 5138 | else |
| 5139 | work_ha_copy &= ~HA_LATT; |
| 5140 | } |
| 5141 | |
| 5142 | if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5143 | /* |
| 5144 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5145 | * the only slow ring. |
| 5146 | */ |
| 5147 | status = (work_ha_copy & |
| 5148 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5149 | status >>= (4*LPFC_ELS_RING); |
| 5150 | if (status & HA_RXMASK) { |
| 5151 | spin_lock(&phba->hbalock); |
| 5152 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5153 | |
| 5154 | lpfc_debugfs_slow_ring_trc(phba, |
| 5155 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5156 | control, status, |
| 5157 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5158 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5159 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5160 | lpfc_debugfs_slow_ring_trc(phba, |
| 5161 | "ISR Disable ring:" |
| 5162 | "pwork:x%x hawork:x%x wait:x%x", |
| 5163 | phba->work_ha, work_ha_copy, |
| 5164 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5165 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5166 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5167 | control &= |
| 5168 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5169 | writel(control, phba->HCregaddr); |
| 5170 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5171 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5172 | else { |
| 5173 | lpfc_debugfs_slow_ring_trc(phba, |
| 5174 | "ISR slow ring: pwork:" |
| 5175 | "x%x hawork:x%x wait:x%x", |
| 5176 | phba->work_ha, work_ha_copy, |
| 5177 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5178 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5179 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5180 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | } |
| 5182 | } |
| 5183 | |
| 5184 | if (work_ha_copy & HA_ERATT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | /* |
| 5186 | * There was a link/board error. Read the |
| 5187 | * status register to retrieve the error event |
| 5188 | * and process it. |
| 5189 | */ |
| 5190 | phba->sli.slistat.err_attn_event++; |
| 5191 | /* Save status info */ |
| 5192 | phba->work_hs = readl(phba->HSregaddr); |
| 5193 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 5194 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 5195 | |
| 5196 | /* Clear Chip error bit */ |
| 5197 | writel(HA_ERATT, phba->HAregaddr); |
| 5198 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5199 | phba->pport->stopped = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5200 | } |
| 5201 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5202 | spin_lock(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5203 | if ((work_ha_copy & HA_MBATT) && |
| 5204 | (phba->sli.mbox_active)) { |
| 5205 | pmb = phba->sli.mbox_active; |
| 5206 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame^] | 5207 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5208 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5209 | |
| 5210 | /* First check out the status word */ |
| 5211 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5212 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5213 | spin_unlock(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5214 | /* |
| 5215 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5216 | * mbxStatus <status> |
| 5217 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5218 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5219 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5220 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5221 | "Interrupt mbxCommand x%x " |
| 5222 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5223 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5224 | pmbox->mbxCommand, |
| 5225 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5226 | /* clear mailbox attention bit */ |
| 5227 | work_ha_copy &= ~HA_MBATT; |
| 5228 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5229 | phba->sli.mbox_active = NULL; |
| 5230 | spin_unlock(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5231 | phba->last_completion_time = jiffies; |
| 5232 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5233 | if (pmb->mbox_cmpl) { |
| 5234 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5235 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5236 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5237 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5238 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5239 | |
| 5240 | lpfc_debugfs_disc_trc(vport, |
| 5241 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5242 | "MBOX dflt rpi: : " |
| 5243 | "status:x%x rpi:x%x", |
| 5244 | (uint32_t)pmbox->mbxStatus, |
| 5245 | pmbox->un.varWords[0], 0); |
| 5246 | |
| 5247 | if (!pmbox->mbxStatus) { |
| 5248 | mp = (struct lpfc_dmabuf *) |
| 5249 | (pmb->context1); |
| 5250 | ndlp = (struct lpfc_nodelist *) |
| 5251 | pmb->context2; |
| 5252 | |
| 5253 | /* Reg_LOGIN of dflt RPI was |
| 5254 | * successful. new lets get |
| 5255 | * rid of the RPI using the |
| 5256 | * same mbox buffer. |
| 5257 | */ |
| 5258 | lpfc_unreg_login(phba, |
| 5259 | vport->vpi, |
| 5260 | pmbox->un.varWords[0], |
| 5261 | pmb); |
| 5262 | pmb->mbox_cmpl = |
| 5263 | lpfc_mbx_cmpl_dflt_rpi; |
| 5264 | pmb->context1 = mp; |
| 5265 | pmb->context2 = ndlp; |
| 5266 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5267 | rc = lpfc_sli_issue_mbox(phba, |
| 5268 | pmb, |
| 5269 | MBX_NOWAIT); |
| 5270 | if (rc != MBX_BUSY) |
| 5271 | lpfc_printf_log(phba, |
| 5272 | KERN_ERR, |
| 5273 | LOG_MBOX | LOG_SLI, |
| 5274 | "0306 rc should have" |
| 5275 | "been MBX_BUSY"); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5276 | goto send_current_mbox; |
| 5277 | } |
| 5278 | } |
| 5279 | spin_lock(&phba->pport->work_port_lock); |
| 5280 | phba->pport->work_port_events &= |
| 5281 | ~WORKER_MBOX_TMO; |
| 5282 | spin_unlock(&phba->pport->work_port_lock); |
| 5283 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5284 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5285 | } else |
| 5286 | spin_unlock(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5287 | if ((work_ha_copy & HA_MBATT) && |
| 5288 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5289 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5290 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5291 | do { |
| 5292 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5293 | MBX_NOWAIT); |
| 5294 | } while (rc == MBX_NOT_FINISHED); |
| 5295 | if (rc != MBX_SUCCESS) |
| 5296 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5297 | LOG_SLI, "0349 rc should be " |
| 5298 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5299 | } |
| 5300 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5301 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | phba->work_ha |= work_ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5303 | spin_unlock(&phba->hbalock); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5304 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | ha_copy &= ~(phba->work_ha_mask); |
| 5308 | |
| 5309 | /* |
| 5310 | * Process all events on FCP ring. Take the optimized path for |
| 5311 | * FCP IO. Any other IO is slow path and is handled by |
| 5312 | * the worker thread. |
| 5313 | */ |
| 5314 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5315 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5316 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5317 | lpfc_sli_handle_fast_ring_event(phba, |
| 5318 | &phba->sli.ring[LPFC_FCP_RING], |
| 5319 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5320 | |
| 5321 | if (phba->cfg_multi_ring_support == 2) { |
| 5322 | /* |
| 5323 | * Process all events on extra ring. Take the optimized path |
| 5324 | * for extra ring IO. Any other IO is slow path and is handled |
| 5325 | * by the worker thread. |
| 5326 | */ |
| 5327 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5328 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5329 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5330 | lpfc_sli_handle_fast_ring_event(phba, |
| 5331 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5332 | status); |
| 5333 | } |
| 5334 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5335 | return IRQ_HANDLED; |
| 5336 | |
| 5337 | } /* lpfc_intr_handler */ |