| 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" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_scsi.h" |
| 38 | #include "lpfc.h" |
| 39 | #include "lpfc_crtn.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 42 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 46 | * This allows multiple uses of lpfc_msgBlk0311 |
| 47 | * w/o perturbing log msg utility. |
| 48 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | lpfc_printf_log(phba, \ |
| 51 | KERN_INFO, \ |
| 52 | LOG_MBOX | LOG_SLI, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 53 | "(%d):0311 Mailbox command x%x cannot " \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | "issue Data: x%x x%x x%x\n", \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 55 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 56 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | |
| 62 | /* There are only four IOCB completion types. */ |
| 63 | typedef enum _lpfc_iocb_type { |
| 64 | LPFC_UNKNOWN_IOCB, |
| 65 | LPFC_UNSOL_IOCB, |
| 66 | LPFC_SOL_IOCB, |
| 67 | LPFC_ABORT_IOCB |
| 68 | } lpfc_iocb_type; |
| 69 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 70 | /** |
| 71 | * lpfc_cmd_iocb: Get next command iocb entry in the ring. |
| 72 | * @phba: Pointer to HBA context object. |
| 73 | * @pring: Pointer to driver SLI ring object. |
| 74 | * |
| 75 | * This function returns pointer to next command iocb entry |
| 76 | * in the command ring. The caller must hold hbalock to prevent |
| 77 | * other threads consume the next command iocb. |
| 78 | * SLI-2/SLI-3 provide different sized iocbs. |
| 79 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 80 | static inline IOCB_t * |
| 81 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 82 | { |
| 83 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 84 | pring->cmdidx * phba->iocb_cmd_size); |
| 85 | } |
| 86 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 87 | /** |
| 88 | * lpfc_resp_iocb: Get next response iocb entry in the ring. |
| 89 | * @phba: Pointer to HBA context object. |
| 90 | * @pring: Pointer to driver SLI ring object. |
| 91 | * |
| 92 | * This function returns pointer to next response iocb entry |
| 93 | * in the response ring. The caller must hold hbalock to make sure |
| 94 | * that no other thread consume the next response iocb. |
| 95 | * SLI-2/SLI-3 provide different sized iocbs. |
| 96 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 97 | static inline IOCB_t * |
| 98 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 99 | { |
| 100 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 101 | pring->rspidx * phba->iocb_rsp_size); |
| 102 | } |
| 103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | /** |
| 105 | * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 106 | * @phba: Pointer to HBA context object. |
| 107 | * |
| 108 | * This function is called with hbalock held. This function |
| 109 | * allocates a new driver iocb object from the iocb pool. If the |
| 110 | * allocation is successful, it returns pointer to the newly |
| 111 | * allocated iocb object else it returns NULL. |
| 112 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 113 | static struct lpfc_iocbq * |
| 114 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 115 | { |
| 116 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 117 | struct lpfc_iocbq * iocbq = NULL; |
| 118 | |
| 119 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 120 | return iocbq; |
| 121 | } |
| 122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 123 | /** |
| 124 | * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 125 | * @phba: Pointer to HBA context object. |
| 126 | * |
| 127 | * This function is called with no lock held. This function |
| 128 | * allocates a new driver iocb object from the iocb pool. If the |
| 129 | * allocation is successful, it returns pointer to the newly |
| 130 | * allocated iocb object else it returns NULL. |
| 131 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 132 | struct lpfc_iocbq * |
| 133 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 135 | struct lpfc_iocbq * iocbq = NULL; |
| 136 | unsigned long iflags; |
| 137 | |
| 138 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 139 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 140 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 141 | return iocbq; |
| 142 | } |
| 143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 144 | /** |
| 145 | * __lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 146 | * @phba: Pointer to HBA context object. |
| 147 | * @iocbq: Pointer to driver iocb object. |
| 148 | * |
| 149 | * This function is called with hbalock held to release driver |
| 150 | * iocb object to the iocb pool. The iotag in the iocb object |
| 151 | * does not change for each use of the iocb object. This function |
| 152 | * clears all other fields of the iocb object when it is freed. |
| 153 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 154 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 155 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 156 | { |
| 157 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * Clean all volatile data fields, preserve iotag and node struct. |
| 161 | */ |
| 162 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 163 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 164 | } |
| 165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 166 | /** |
| 167 | * lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 168 | * @phba: Pointer to HBA context object. |
| 169 | * @iocbq: Pointer to driver iocb object. |
| 170 | * |
| 171 | * This function is called with no lock held to release the iocb to |
| 172 | * iocb pool. |
| 173 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 174 | void |
| 175 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 176 | { |
| 177 | unsigned long iflags; |
| 178 | |
| 179 | /* |
| 180 | * Clean all volatile data fields, preserve iotag and node struct. |
| 181 | */ |
| 182 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 183 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 185 | } |
| 186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 187 | /** |
| 188 | * lpfc_sli_iocb_cmd_type: Get the iocb type. |
| 189 | * @iocb_cmnd : iocb command code. |
| 190 | * |
| 191 | * This function is called by ring event handler function to get the iocb type. |
| 192 | * This function translates the iocb command to an iocb command type used to |
| 193 | * decide the final disposition of each completed IOCB. |
| 194 | * The function returns |
| 195 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 196 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 197 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 198 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 199 | * |
| 200 | * The caller is not required to hold any lock. |
| 201 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | static lpfc_iocb_type |
| 203 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 204 | { |
| 205 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 206 | |
| 207 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 208 | return 0; |
| 209 | |
| 210 | switch (iocb_cmnd) { |
| 211 | case CMD_XMIT_SEQUENCE_CR: |
| 212 | case CMD_XMIT_SEQUENCE_CX: |
| 213 | case CMD_XMIT_BCAST_CN: |
| 214 | case CMD_XMIT_BCAST_CX: |
| 215 | case CMD_ELS_REQUEST_CR: |
| 216 | case CMD_ELS_REQUEST_CX: |
| 217 | case CMD_CREATE_XRI_CR: |
| 218 | case CMD_CREATE_XRI_CX: |
| 219 | case CMD_GET_RPI_CN: |
| 220 | case CMD_XMIT_ELS_RSP_CX: |
| 221 | case CMD_GET_RPI_CR: |
| 222 | case CMD_FCP_IWRITE_CR: |
| 223 | case CMD_FCP_IWRITE_CX: |
| 224 | case CMD_FCP_IREAD_CR: |
| 225 | case CMD_FCP_IREAD_CX: |
| 226 | case CMD_FCP_ICMND_CR: |
| 227 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 228 | case CMD_FCP_TSEND_CX: |
| 229 | case CMD_FCP_TRSP_CX: |
| 230 | case CMD_FCP_TRECEIVE_CX: |
| 231 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | case CMD_ADAPTER_MSG: |
| 233 | case CMD_ADAPTER_DUMP: |
| 234 | case CMD_XMIT_SEQUENCE64_CR: |
| 235 | case CMD_XMIT_SEQUENCE64_CX: |
| 236 | case CMD_XMIT_BCAST64_CN: |
| 237 | case CMD_XMIT_BCAST64_CX: |
| 238 | case CMD_ELS_REQUEST64_CR: |
| 239 | case CMD_ELS_REQUEST64_CX: |
| 240 | case CMD_FCP_IWRITE64_CR: |
| 241 | case CMD_FCP_IWRITE64_CX: |
| 242 | case CMD_FCP_IREAD64_CR: |
| 243 | case CMD_FCP_IREAD64_CX: |
| 244 | case CMD_FCP_ICMND64_CR: |
| 245 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 246 | case CMD_FCP_TSEND64_CX: |
| 247 | case CMD_FCP_TRSP64_CX: |
| 248 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | case CMD_GEN_REQUEST64_CR: |
| 250 | case CMD_GEN_REQUEST64_CX: |
| 251 | case CMD_XMIT_ELS_RSP64_CX: |
| 252 | type = LPFC_SOL_IOCB; |
| 253 | break; |
| 254 | case CMD_ABORT_XRI_CN: |
| 255 | case CMD_ABORT_XRI_CX: |
| 256 | case CMD_CLOSE_XRI_CN: |
| 257 | case CMD_CLOSE_XRI_CX: |
| 258 | case CMD_XRI_ABORTED_CX: |
| 259 | case CMD_ABORT_MXRI64_CN: |
| 260 | type = LPFC_ABORT_IOCB; |
| 261 | break; |
| 262 | case CMD_RCV_SEQUENCE_CX: |
| 263 | case CMD_RCV_ELS_REQ_CX: |
| 264 | case CMD_RCV_SEQUENCE64_CX: |
| 265 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 266 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 267 | case CMD_IOCB_RCV_SEQ64_CX: |
| 268 | case CMD_IOCB_RCV_ELS64_CX: |
| 269 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 270 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | type = LPFC_UNSOL_IOCB; |
| 272 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 273 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 274 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 275 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 276 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 277 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 278 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 279 | case CMD_IOCB_RET_HBQE64_CN: |
| 280 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 281 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 282 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 283 | case CMD_IOCB_LOGENTRY_CN: |
| 284 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 285 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 286 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 287 | type = LPFC_UNKNOWN_IOCB; |
| 288 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | default: |
| 290 | type = LPFC_UNKNOWN_IOCB; |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | return type; |
| 295 | } |
| 296 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 297 | /** |
| 298 | * lpfc_sli_ring_map: Issue config_ring mbox for all rings. |
| 299 | * @phba: Pointer to HBA context object. |
| 300 | * |
| 301 | * This function is called from SLI initialization code |
| 302 | * to configure every ring of the HBA's SLI interface. The |
| 303 | * caller is not required to hold any lock. This function issues |
| 304 | * a config_ring mailbox command for each ring. |
| 305 | * This function returns zero if successful else returns a negative |
| 306 | * error code. |
| 307 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 309 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 310 | { |
| 311 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 312 | LPFC_MBOXQ_t *pmb; |
| 313 | MAILBOX_t *pmbox; |
| 314 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 316 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 317 | if (!pmb) |
| 318 | return -ENOMEM; |
| 319 | pmbox = &pmb->mb; |
| 320 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 | lpfc_config_ring(phba, i, pmb); |
| 323 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 324 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 326 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 328 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 329 | rc, pmbox->mbxCommand, |
| 330 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 331 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 332 | ret = -ENXIO; |
| 333 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | } |
| 335 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 336 | mempool_free(pmb, phba->mbox_mem_pool); |
| 337 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 338 | } |
| 339 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 340 | /** |
| 341 | * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq. |
| 342 | * @phba: Pointer to HBA context object. |
| 343 | * @pring: Pointer to driver SLI ring object. |
| 344 | * @piocb: Pointer to the driver iocb object. |
| 345 | * |
| 346 | * This function is called with hbalock held. The function adds the |
| 347 | * new iocb to txcmplq of the given ring. This function always returns |
| 348 | * 0. If this function is called for ELS ring, this function checks if |
| 349 | * there is a vport associated with the ELS command. This function also |
| 350 | * starts els_tmofunc timer if this is an ELS command. |
| 351 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 353 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 354 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 356 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 357 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 359 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 360 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 361 | if (!piocb->vport) |
| 362 | BUG(); |
| 363 | else |
| 364 | mod_timer(&piocb->vport->els_tmofunc, |
| 365 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 366 | } |
| 367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 368 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 369 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | } |
| 371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 372 | /** |
| 373 | * lpfc_sli_ringtx_get: Get first element of the txq. |
| 374 | * @phba: Pointer to HBA context object. |
| 375 | * @pring: Pointer to driver SLI ring object. |
| 376 | * |
| 377 | * This function is called with hbalock held to get next |
| 378 | * iocb in txq of the given ring. If there is any iocb in |
| 379 | * the txq, the function returns first iocb in the list after |
| 380 | * removing the iocb from the list, else it returns NULL. |
| 381 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 383 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | struct lpfc_iocbq *cmd_iocb; |
| 386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 387 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 388 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 389 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 390 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 391 | } |
| 392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 393 | /** |
| 394 | * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring. |
| 395 | * @phba: Pointer to HBA context object. |
| 396 | * @pring: Pointer to driver SLI ring object. |
| 397 | * |
| 398 | * This function is called with hbalock held and the caller must post the |
| 399 | * iocb without releasing the lock. If the caller releases the lock, |
| 400 | * iocb slot returned by the function is not guaranteed to be available. |
| 401 | * The function returns pointer to the next available iocb slot if there |
| 402 | * is available slot in the ring, else it returns NULL. |
| 403 | * If the get index of the ring is ahead of the put index, the function |
| 404 | * will post an error attention event to the worker thread to take the |
| 405 | * HBA to offline state. |
| 406 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | static IOCB_t * |
| 408 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 409 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 410 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 413 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 414 | pring->next_cmdidx = 0; |
| 415 | |
| 416 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 417 | |
| 418 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 419 | |
| 420 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 421 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 422 | "0315 Ring %d issue: portCmdGet %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | "is bigger then cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 424 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | pring->local_getidx, max_cmd_idx); |
| 426 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 427 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | /* |
| 429 | * All error attention handlers are posted to |
| 430 | * worker thread |
| 431 | */ |
| 432 | phba->work_ha |= HA_ERATT; |
| 433 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 434 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 435 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | |
| 437 | return NULL; |
| 438 | } |
| 439 | |
| 440 | if (pring->local_getidx == pring->next_cmdidx) |
| 441 | return NULL; |
| 442 | } |
| 443 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 444 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | } |
| 446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 447 | /** |
| 448 | * lpfc_sli_next_iotag: Get an iotag for the iocb. |
| 449 | * @phba: Pointer to HBA context object. |
| 450 | * @iocbq: Pointer to driver iocb object. |
| 451 | * |
| 452 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 453 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 454 | * array and assigns a new iotag. |
| 455 | * The function returns the allocated iotag if successful, else returns zero. |
| 456 | * Zero is not a valid iotag. |
| 457 | * The caller is not required to hold any lock. |
| 458 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 459 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 460 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 462 | struct lpfc_iocbq **new_arr; |
| 463 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 464 | size_t new_len; |
| 465 | struct lpfc_sli *psli = &phba->sli; |
| 466 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 468 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 469 | iotag = psli->last_iotag; |
| 470 | if(++iotag < psli->iocbq_lookup_len) { |
| 471 | psli->last_iotag = iotag; |
| 472 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 473 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 474 | iocbq->iotag = iotag; |
| 475 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 476 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 477 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 478 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 479 | spin_unlock_irq(&phba->hbalock); |
| 480 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 481 | GFP_KERNEL); |
| 482 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 483 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 484 | old_arr = psli->iocbq_lookup; |
| 485 | if (new_len <= psli->iocbq_lookup_len) { |
| 486 | /* highly unprobable case */ |
| 487 | kfree(new_arr); |
| 488 | iotag = psli->last_iotag; |
| 489 | if(++iotag < psli->iocbq_lookup_len) { |
| 490 | psli->last_iotag = iotag; |
| 491 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 492 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 493 | iocbq->iotag = iotag; |
| 494 | return iotag; |
| 495 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 496 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | if (psli->iocbq_lookup) |
| 500 | memcpy(new_arr, old_arr, |
| 501 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 502 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 503 | psli->iocbq_lookup = new_arr; |
| 504 | psli->iocbq_lookup_len = new_len; |
| 505 | psli->last_iotag = iotag; |
| 506 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 508 | iocbq->iotag = iotag; |
| 509 | kfree(old_arr); |
| 510 | return iotag; |
| 511 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 512 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 513 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 515 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 516 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 517 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 519 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 520 | } |
| 521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 522 | /** |
| 523 | * lpfc_sli_submit_iocb: Submit an iocb to the firmware. |
| 524 | * @phba: Pointer to HBA context object. |
| 525 | * @pring: Pointer to driver SLI ring object. |
| 526 | * @iocb: Pointer to iocb slot in the ring. |
| 527 | * @nextiocb: Pointer to driver iocb object which need to be |
| 528 | * posted to firmware. |
| 529 | * |
| 530 | * This function is called with hbalock held to post a new iocb to |
| 531 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 532 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 533 | * a completion call back for this iocb else the function will free the |
| 534 | * iocb object. |
| 535 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | static void |
| 537 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 538 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 539 | { |
| 540 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 541 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 543 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 544 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 545 | if (pring->ringno == LPFC_ELS_RING) { |
| 546 | lpfc_debugfs_slow_ring_trc(phba, |
| 547 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 548 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 549 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 550 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 551 | } |
| 552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 | /* |
| 554 | * Issue iocb command to adapter |
| 555 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 556 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 557 | wmb(); |
| 558 | pring->stats.iocb_cmd++; |
| 559 | |
| 560 | /* |
| 561 | * If there is no completion routine to call, we can release the |
| 562 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 563 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 564 | */ |
| 565 | if (nextiocb->iocb_cmpl) |
| 566 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 567 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 568 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * Let the HBA know what IOCB slot will be the next one the |
| 572 | * driver will put a command into. |
| 573 | */ |
| 574 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 575 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 576 | } |
| 577 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 578 | /** |
| 579 | * lpfc_sli_update_full_ring: Update the chip attention register. |
| 580 | * @phba: Pointer to HBA context object. |
| 581 | * @pring: Pointer to driver SLI ring object. |
| 582 | * |
| 583 | * The caller is not required to hold any lock for calling this function. |
| 584 | * This function updates the chip attention bits for the ring to inform firmware |
| 585 | * that there are pending work to be done for this ring and requests an |
| 586 | * interrupt when there is space available in the ring. This function is |
| 587 | * called when the driver is unable to post more iocbs to the ring due |
| 588 | * to unavailability of space in the ring. |
| 589 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 590 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 591 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | { |
| 593 | int ringno = pring->ringno; |
| 594 | |
| 595 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 596 | |
| 597 | wmb(); |
| 598 | |
| 599 | /* |
| 600 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 601 | * The HBA will tell us when an IOCB entry is available. |
| 602 | */ |
| 603 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 604 | readl(phba->CAregaddr); /* flush */ |
| 605 | |
| 606 | pring->stats.iocb_cmd_full++; |
| 607 | } |
| 608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 609 | /** |
| 610 | * lpfc_sli_update_ring: Update chip attention register. |
| 611 | * @phba: Pointer to HBA context object. |
| 612 | * @pring: Pointer to driver SLI ring object. |
| 613 | * |
| 614 | * This function updates the chip attention register bit for the |
| 615 | * given ring to inform HBA that there is more work to be done |
| 616 | * in this ring. The caller is not required to hold any lock. |
| 617 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 618 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 619 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | { |
| 621 | int ringno = pring->ringno; |
| 622 | |
| 623 | /* |
| 624 | * Tell the HBA that there is work to do in this ring. |
| 625 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 626 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 627 | wmb(); |
| 628 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 629 | readl(phba->CAregaddr); /* flush */ |
| 630 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | } |
| 632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 633 | /** |
| 634 | * lpfc_sli_resume_iocb: Process iocbs in the txq. |
| 635 | * @phba: Pointer to HBA context object. |
| 636 | * @pring: Pointer to driver SLI ring object. |
| 637 | * |
| 638 | * This function is called with hbalock held to post pending iocbs |
| 639 | * in the txq to the firmware. This function is called when driver |
| 640 | * detects space available in the ring. |
| 641 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 643 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | { |
| 645 | IOCB_t *iocb; |
| 646 | struct lpfc_iocbq *nextiocb; |
| 647 | |
| 648 | /* |
| 649 | * Check to see if: |
| 650 | * (a) there is anything on the txq to send |
| 651 | * (b) link is up |
| 652 | * (c) link attention events can be processed (fcp ring only) |
| 653 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 654 | */ |
| 655 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 656 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 658 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | |
| 660 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 661 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 662 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 663 | |
| 664 | if (iocb) |
| 665 | lpfc_sli_update_ring(phba, pring); |
| 666 | else |
| 667 | lpfc_sli_update_full_ring(phba, pring); |
| 668 | } |
| 669 | |
| 670 | return; |
| 671 | } |
| 672 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 673 | /** |
| 674 | * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ. |
| 675 | * @phba: Pointer to HBA context object. |
| 676 | * @hbqno: HBQ number. |
| 677 | * |
| 678 | * This function is called with hbalock held to get the next |
| 679 | * available slot for the given HBQ. If there is free slot |
| 680 | * available for the HBQ it will return pointer to the next available |
| 681 | * HBQ entry else it will return NULL. |
| 682 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 683 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 684 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 685 | { |
| 686 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 687 | |
| 688 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 689 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 690 | hbqp->next_hbqPutIdx = 0; |
| 691 | |
| 692 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 693 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 694 | uint32_t getidx = le32_to_cpu(raw_index); |
| 695 | |
| 696 | hbqp->local_hbqGetIdx = getidx; |
| 697 | |
| 698 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 699 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 700 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 701 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 702 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 703 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 704 | hbqp->entry_count); |
| 705 | |
| 706 | phba->link_state = LPFC_HBA_ERROR; |
| 707 | return NULL; |
| 708 | } |
| 709 | |
| 710 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 711 | return NULL; |
| 712 | } |
| 713 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 714 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 715 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 716 | } |
| 717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 718 | /** |
| 719 | * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers. |
| 720 | * @phba: Pointer to HBA context object. |
| 721 | * |
| 722 | * This function is called with no lock held to free all the |
| 723 | * hbq buffers while uninitializing the SLI interface. It also |
| 724 | * frees the HBQ buffers returned by the firmware but not yet |
| 725 | * processed by the upper layers. |
| 726 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 727 | void |
| 728 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 729 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 730 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 731 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 732 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 733 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 734 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 735 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 736 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 737 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 738 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 739 | for (i = 0; i < hbq_count; ++i) { |
| 740 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 741 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 742 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 743 | list_del(&hbq_buf->dbuf.list); |
| 744 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 745 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 746 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 747 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 748 | /* Return all HBQ buffer that are in-fly */ |
| 749 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 750 | &phba->hbqbuf_in_list, list) { |
| 751 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 752 | list_del(&hbq_buf->dbuf.list); |
| 753 | if (hbq_buf->tag == -1) { |
| 754 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 755 | (phba, hbq_buf); |
| 756 | } else { |
| 757 | hbqno = hbq_buf->tag >> 16; |
| 758 | if (hbqno >= LPFC_MAX_HBQS) |
| 759 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 760 | (phba, hbq_buf); |
| 761 | else |
| 762 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 763 | hbq_buf); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /* Mark the HBQs not in use */ |
| 768 | phba->hbq_in_use = 0; |
| 769 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 770 | } |
| 771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 772 | /** |
| 773 | * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware. |
| 774 | * @phba: Pointer to HBA context object. |
| 775 | * @hbqno: HBQ number. |
| 776 | * @hbq_buf: Pointer to HBQ buffer. |
| 777 | * |
| 778 | * This function is called with the hbalock held to post a |
| 779 | * hbq buffer to the firmware. If the function finds an empty |
| 780 | * slot in the HBQ, it will post the buffer. The function will return |
| 781 | * pointer to the hbq entry if it successfully post the buffer |
| 782 | * else it will return NULL. |
| 783 | **/ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 784 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 785 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 786 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 787 | { |
| 788 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 789 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 790 | |
| 791 | /* Get next HBQ entry slot to use */ |
| 792 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 793 | if (hbqe) { |
| 794 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 795 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 797 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 798 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 799 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 800 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 801 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 802 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 803 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 804 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 806 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 807 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 808 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 809 | return hbqe; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 810 | } |
| 811 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 812 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 814 | .rn = 1, |
| 815 | .entry_count = 200, |
| 816 | .mask_count = 0, |
| 817 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 818 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | .buffer_count = 0, |
| 820 | .init_count = 20, |
| 821 | .add_count = 5, |
| 822 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 824 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 825 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 826 | .rn = 1, |
| 827 | .entry_count = 200, |
| 828 | .mask_count = 0, |
| 829 | .profile = 0, |
| 830 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 831 | .buffer_count = 0, |
| 832 | .init_count = 0, |
| 833 | .add_count = 5, |
| 834 | }; |
| 835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 836 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 837 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 839 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 840 | }; |
| 841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 842 | /** |
| 843 | * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ. |
| 844 | * @phba: Pointer to HBA context object. |
| 845 | * @hbqno: HBQ number. |
| 846 | * @count: Number of HBQ buffers to be posted. |
| 847 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 848 | * This function is called with no lock held to post more hbq buffers to the |
| 849 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 850 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 851 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 852 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 853 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 854 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 855 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 856 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 857 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 858 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 859 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 860 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 861 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 862 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 863 | lpfc_hbq_defs[hbqno]->entry_count) |
| 864 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 865 | phba->hbqs[hbqno].buffer_count; |
| 866 | if (!count) |
| 867 | return 0; |
| 868 | /* Allocate HBQ entries */ |
| 869 | for (i = 0; i < count; i++) { |
| 870 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 871 | if (!hbq_buffer) |
| 872 | break; |
| 873 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 874 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 875 | /* Check whether HBQ is still in use */ |
| 876 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 877 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 878 | goto err; |
| 879 | while (!list_empty(&hbq_buf_list)) { |
| 880 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 881 | dbuf.list); |
| 882 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 883 | (hbqno << 16)); |
| 884 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 885 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 886 | posted++; |
| 887 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 888 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 889 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 890 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 891 | return posted; |
| 892 | err: |
| 893 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 894 | while (!list_empty(&hbq_buf_list)) { |
| 895 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 896 | dbuf.list); |
| 897 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 898 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 899 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 900 | } |
| 901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 902 | /** |
| 903 | * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware. |
| 904 | * @phba: Pointer to HBA context object. |
| 905 | * @qno: HBQ number. |
| 906 | * |
| 907 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 908 | * is called with no lock held. The function returns the number of HBQ entries |
| 909 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 910 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 911 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 912 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 913 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 914 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 915 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 916 | } |
| 917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 918 | /** |
| 919 | * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ. |
| 920 | * @phba: Pointer to HBA context object. |
| 921 | * @qno: HBQ queue number. |
| 922 | * |
| 923 | * This function is called from SLI initialization code path with |
| 924 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 925 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 926 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 927 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 928 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 929 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 930 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 931 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 932 | } |
| 933 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 934 | /** |
| 935 | * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag. |
| 936 | * @phba: Pointer to HBA context object. |
| 937 | * @tag: Tag of the hbq buffer. |
| 938 | * |
| 939 | * This function is called with hbalock held. This function searches |
| 940 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 941 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 942 | * it returns NULL. |
| 943 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 944 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 945 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 946 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | struct lpfc_dmabuf *d_buf; |
| 948 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 949 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 950 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 951 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 952 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 953 | return NULL; |
| 954 | |
| 955 | 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] | 956 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 957 | if (hbq_buf->tag == tag) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 958 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 959 | } |
| 960 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 962 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 963 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 965 | } |
| 966 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 967 | /** |
| 968 | * lpfc_sli_free_hbq: Give back the hbq buffer to firmware. |
| 969 | * @phba: Pointer to HBA context object. |
| 970 | * @hbq_buffer: Pointer to HBQ buffer. |
| 971 | * |
| 972 | * This function is called with hbalock. This function gives back |
| 973 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 974 | * post the buffer, it will free the buffer. |
| 975 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 976 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 977 | 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] | 978 | { |
| 979 | uint32_t hbqno; |
| 980 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 981 | if (hbq_buffer) { |
| 982 | hbqno = hbq_buffer->tag >> 16; |
| 983 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
| 984 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 985 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 989 | /** |
| 990 | * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox. |
| 991 | * @mbxCommand: mailbox command code. |
| 992 | * |
| 993 | * This function is called by the mailbox event handler function to verify |
| 994 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 995 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 996 | * and the mailbox event handler will take the HBA offline. |
| 997 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | static int |
| 999 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1000 | { |
| 1001 | uint8_t ret; |
| 1002 | |
| 1003 | switch (mbxCommand) { |
| 1004 | case MBX_LOAD_SM: |
| 1005 | case MBX_READ_NV: |
| 1006 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1007 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | case MBX_RUN_BIU_DIAG: |
| 1009 | case MBX_INIT_LINK: |
| 1010 | case MBX_DOWN_LINK: |
| 1011 | case MBX_CONFIG_LINK: |
| 1012 | case MBX_CONFIG_RING: |
| 1013 | case MBX_RESET_RING: |
| 1014 | case MBX_READ_CONFIG: |
| 1015 | case MBX_READ_RCONFIG: |
| 1016 | case MBX_READ_SPARM: |
| 1017 | case MBX_READ_STATUS: |
| 1018 | case MBX_READ_RPI: |
| 1019 | case MBX_READ_XRI: |
| 1020 | case MBX_READ_REV: |
| 1021 | case MBX_READ_LNK_STAT: |
| 1022 | case MBX_REG_LOGIN: |
| 1023 | case MBX_UNREG_LOGIN: |
| 1024 | case MBX_READ_LA: |
| 1025 | case MBX_CLEAR_LA: |
| 1026 | case MBX_DUMP_MEMORY: |
| 1027 | case MBX_DUMP_CONTEXT: |
| 1028 | case MBX_RUN_DIAGS: |
| 1029 | case MBX_RESTART: |
| 1030 | case MBX_UPDATE_CFG: |
| 1031 | case MBX_DOWN_LOAD: |
| 1032 | case MBX_DEL_LD_ENTRY: |
| 1033 | case MBX_RUN_PROGRAM: |
| 1034 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1035 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1036 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1037 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1039 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | case MBX_LOAD_AREA: |
| 1041 | case MBX_RUN_BIU_DIAG64: |
| 1042 | case MBX_CONFIG_PORT: |
| 1043 | case MBX_READ_SPARM64: |
| 1044 | case MBX_READ_RPI64: |
| 1045 | case MBX_REG_LOGIN64: |
| 1046 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1047 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | case MBX_SET_DEBUG: |
| 1049 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1050 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1051 | case MBX_REG_VPI: |
| 1052 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1053 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1054 | case MBX_PORT_CAPABILITIES: |
| 1055 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | ret = mbxCommand; |
| 1057 | break; |
| 1058 | default: |
| 1059 | ret = MBX_SHUTDOWN; |
| 1060 | break; |
| 1061 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1062 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1064 | |
| 1065 | /** |
| 1066 | * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from |
| 1067 | * lpfc_sli_issue_mbox_wait. |
| 1068 | * @phba: Pointer to HBA context object. |
| 1069 | * @pmboxq: Pointer to mailbox command. |
| 1070 | * |
| 1071 | * This is completion handler function for mailbox commands issued from |
| 1072 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1073 | * mailbox event handler function with no lock held. This function |
| 1074 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1075 | * of the mailbox. |
| 1076 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1078 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | { |
| 1080 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1081 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | |
| 1083 | /* |
| 1084 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1085 | * continued running. |
| 1086 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1087 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1088 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1090 | if (pdone_q) |
| 1091 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1092 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1096 | |
| 1097 | /** |
| 1098 | * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler. |
| 1099 | * @phba: Pointer to HBA context object. |
| 1100 | * @pmb: Pointer to mailbox object. |
| 1101 | * |
| 1102 | * This function is the default mailbox completion handler. It |
| 1103 | * frees the memory resources associated with the completed mailbox |
| 1104 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1105 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1106 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1107 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | { |
| 1110 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1111 | uint16_t rpi; |
| 1112 | int rc; |
| 1113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1116 | if (mp) { |
| 1117 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1118 | kfree(mp); |
| 1119 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1120 | |
| 1121 | /* |
| 1122 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1123 | * is in re-discovery driver need to cleanup the RPI. |
| 1124 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1126 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1127 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1128 | |
| 1129 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1130 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1131 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1132 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1133 | if (rc != MBX_NOT_FINISHED) |
| 1134 | return; |
| 1135 | } |
| 1136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1137 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1138 | return; |
| 1139 | } |
| 1140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1141 | /** |
| 1142 | * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware. |
| 1143 | * @phba: Pointer to HBA context object. |
| 1144 | * |
| 1145 | * This function is called with no lock held. This function processes all |
| 1146 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1147 | * service routine processes mailbox completion interrupt and adds completed |
| 1148 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1149 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1150 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1151 | * function returns the mailbox commands to the upper layer by calling the |
| 1152 | * completion handler function of each mailbox. |
| 1153 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1155 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1157 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1159 | int rc; |
| 1160 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | |
| 1162 | phba->sli.slistat.mbox_event++; |
| 1163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1164 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1165 | spin_lock_irq(&phba->hbalock); |
| 1166 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1167 | spin_unlock_irq(&phba->hbalock); |
| 1168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1170 | do { |
| 1171 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1172 | if (pmb == NULL) |
| 1173 | break; |
| 1174 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1178 | if (pmb->vport) { |
| 1179 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1180 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1181 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1182 | (uint32_t)pmbox->mbxCommand, |
| 1183 | pmbox->un.varWords[0], |
| 1184 | pmbox->un.varWords[1]); |
| 1185 | } |
| 1186 | else { |
| 1187 | lpfc_debugfs_disc_trc(phba->pport, |
| 1188 | LPFC_DISC_TRC_MBOX, |
| 1189 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1190 | (uint32_t)pmbox->mbxCommand, |
| 1191 | pmbox->un.varWords[0], |
| 1192 | pmbox->un.varWords[1]); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | /* |
| 1197 | * It is a fatal error if unknown mbox command completion. |
| 1198 | */ |
| 1199 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1200 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1202 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1203 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1204 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1205 | pmb->vport ? pmb->vport->vpi : 0, |
| 1206 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1207 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | phba->work_hs = HS_FFER3; |
| 1209 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1210 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | } |
| 1212 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | if (pmbox->mbxStatus) { |
| 1214 | phba->sli.slistat.mbox_stat_err++; |
| 1215 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1216 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1217 | lpfc_printf_log(phba, KERN_INFO, |
| 1218 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1219 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1220 | "error - RETRYing Data: x%x " |
| 1221 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1222 | pmb->vport ? pmb->vport->vpi :0, |
| 1223 | pmbox->mbxCommand, |
| 1224 | pmbox->mbxStatus, |
| 1225 | pmbox->un.varWords[0], |
| 1226 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | pmbox->mbxStatus = 0; |
| 1228 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1229 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1231 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1233 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1234 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1239 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1240 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1241 | "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] | 1242 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | pmbox->mbxCommand, |
| 1244 | pmb->mbox_cmpl, |
| 1245 | *((uint32_t *) pmbox), |
| 1246 | pmbox->un.varWords[0], |
| 1247 | pmbox->un.varWords[1], |
| 1248 | pmbox->un.varWords[2], |
| 1249 | pmbox->un.varWords[3], |
| 1250 | pmbox->un.varWords[4], |
| 1251 | pmbox->un.varWords[5], |
| 1252 | pmbox->un.varWords[6], |
| 1253 | pmbox->un.varWords[7]); |
| 1254 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1255 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1257 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1258 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1261 | /** |
| 1262 | * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer. |
| 1263 | * @phba: Pointer to HBA context object. |
| 1264 | * @tag: Tag for the HBQ buffer. |
| 1265 | * |
| 1266 | * This function is called from unsolicited event handler code path to get the |
| 1267 | * HBQ buffer associated with an unsolicited iocb. This function is called with |
| 1268 | * no lock held. It returns the buffer associated with the given tag and posts |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1269 | * another buffer to the firmware. Note that the new buffer must be allocated |
| 1270 | * before taking the hbalock and that the hba lock must be held until it is |
| 1271 | * finished with the hbq entry swap. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1272 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1273 | static struct lpfc_dmabuf * |
| 1274 | lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) |
| 1275 | { |
| 1276 | struct hbq_dmabuf *hbq_entry, *new_hbq_entry; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1277 | uint32_t hbqno; |
| 1278 | void *virt; /* virtual address ptr */ |
| 1279 | dma_addr_t phys; /* mapped address */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1280 | unsigned long flags; |
| 1281 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1282 | hbqno = tag >> 16; |
| 1283 | new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1284 | /* Check whether HBQ is still in use */ |
| 1285 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1286 | if (!phba->hbq_in_use) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1287 | if (new_hbq_entry) |
| 1288 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1289 | new_hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1290 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1291 | return NULL; |
| 1292 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | |
| 1294 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1295 | if (hbq_entry == NULL) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1296 | if (new_hbq_entry) |
| 1297 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1298 | new_hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1299 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | return NULL; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1301 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1302 | list_del(&hbq_entry->dbuf.list); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1303 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1304 | if (new_hbq_entry == NULL) { |
| 1305 | list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1306 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1307 | return &hbq_entry->dbuf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1308 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1309 | new_hbq_entry->tag = -1; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1310 | phys = new_hbq_entry->dbuf.phys; |
| 1311 | virt = new_hbq_entry->dbuf.virt; |
| 1312 | new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys; |
| 1313 | new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt; |
| 1314 | hbq_entry->dbuf.phys = phys; |
| 1315 | hbq_entry->dbuf.virt = virt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1316 | lpfc_sli_free_hbq(phba, hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1317 | list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1318 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1319 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1320 | return &new_hbq_entry->dbuf; |
| 1321 | } |
| 1322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1323 | /** |
| 1324 | * lpfc_sli_get_buff: Get the buffer associated with the buffer tag. |
| 1325 | * @phba: Pointer to HBA context object. |
| 1326 | * @pring: Pointer to driver SLI ring object. |
| 1327 | * @tag: buffer tag. |
| 1328 | * |
| 1329 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1330 | * is set in the tag the buffer is posted for a particular exchange, |
| 1331 | * the function will return the buffer without replacing the buffer. |
| 1332 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1333 | * returns the buffer and also posts another buffer to the firmware. |
| 1334 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1335 | static struct lpfc_dmabuf * |
| 1336 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
| 1337 | struct lpfc_sli_ring *pring, |
| 1338 | uint32_t tag) |
| 1339 | { |
| 1340 | if (tag & QUE_BUFTAG_BIT) |
| 1341 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
| 1342 | else |
| 1343 | return lpfc_sli_replace_hbqbuff(phba, tag); |
| 1344 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1346 | |
| 1347 | /** |
| 1348 | * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler. |
| 1349 | * @phba: Pointer to HBA context object. |
| 1350 | * @pring: Pointer to driver SLI ring object. |
| 1351 | * @saveq: Pointer to the unsolicited iocb. |
| 1352 | * |
| 1353 | * This function is called with no lock held by the ring event handler |
| 1354 | * when there is an unsolicited iocb posted to the response ring by the |
| 1355 | * firmware. This function gets the buffer associated with the iocbs |
| 1356 | * and calls the event handler for the ring. This function handles both |
| 1357 | * qring buffers and hbq buffers. |
| 1358 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1359 | * upper layer functions will free the iocb objects. |
| 1360 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | static int |
| 1362 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1363 | struct lpfc_iocbq *saveq) |
| 1364 | { |
| 1365 | IOCB_t * irsp; |
| 1366 | WORD5 * w5p; |
| 1367 | uint32_t Rctl, Type; |
| 1368 | uint32_t match, i; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1369 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1370 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | |
| 1372 | match = 0; |
| 1373 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1374 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1375 | if (irsp->ulpStatus == IOSTAT_NEED_BUFFER) |
| 1376 | return 1; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1377 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1378 | if (pring->lpfc_sli_rcv_async_status) |
| 1379 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1380 | else |
| 1381 | lpfc_printf_log(phba, |
| 1382 | KERN_WARNING, |
| 1383 | LOG_SLI, |
| 1384 | "0316 Ring %d handler: unexpected " |
| 1385 | "ASYNC_STATUS iocb received evt_code " |
| 1386 | "0x%x\n", |
| 1387 | pring->ringno, |
| 1388 | irsp->un.asyncstat.evt_code); |
| 1389 | return 1; |
| 1390 | } |
| 1391 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1392 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1393 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1394 | if (irsp->ulpBdeCount > 0) { |
| 1395 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1396 | irsp->un.ulpWord[3]); |
| 1397 | lpfc_in_buf_free(phba, dmzbuf); |
| 1398 | } |
| 1399 | |
| 1400 | if (irsp->ulpBdeCount > 1) { |
| 1401 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1402 | irsp->unsli3.sli3Words[3]); |
| 1403 | lpfc_in_buf_free(phba, dmzbuf); |
| 1404 | } |
| 1405 | |
| 1406 | if (irsp->ulpBdeCount > 2) { |
| 1407 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1408 | irsp->unsli3.sli3Words[7]); |
| 1409 | lpfc_in_buf_free(phba, dmzbuf); |
| 1410 | } |
| 1411 | |
| 1412 | return 1; |
| 1413 | } |
| 1414 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1415 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1416 | if (irsp->ulpBdeCount != 0) { |
| 1417 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1418 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1419 | if (!saveq->context2) |
| 1420 | lpfc_printf_log(phba, |
| 1421 | KERN_ERR, |
| 1422 | LOG_SLI, |
| 1423 | "0341 Ring %d Cannot find buffer for " |
| 1424 | "an unsolicited iocb. tag 0x%x\n", |
| 1425 | pring->ringno, |
| 1426 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1427 | } |
| 1428 | if (irsp->ulpBdeCount == 2) { |
| 1429 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1430 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1431 | if (!saveq->context3) |
| 1432 | lpfc_printf_log(phba, |
| 1433 | KERN_ERR, |
| 1434 | LOG_SLI, |
| 1435 | "0342 Ring %d Cannot find buffer for an" |
| 1436 | " unsolicited iocb. tag 0x%x\n", |
| 1437 | pring->ringno, |
| 1438 | irsp->unsli3.sli3Words[7]); |
| 1439 | } |
| 1440 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1441 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1442 | if (irsp->ulpBdeCount != 0) { |
| 1443 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1444 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1445 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1446 | lpfc_printf_log(phba, |
| 1447 | KERN_ERR, |
| 1448 | LOG_SLI, |
| 1449 | "0343 Ring %d Cannot find " |
| 1450 | "buffer for an unsolicited iocb" |
| 1451 | ". tag 0x%x\n", pring->ringno, |
| 1452 | irsp->un.ulpWord[3]); |
| 1453 | } |
| 1454 | if (irsp->ulpBdeCount == 2) { |
| 1455 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1456 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1457 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1458 | lpfc_printf_log(phba, |
| 1459 | KERN_ERR, |
| 1460 | LOG_SLI, |
| 1461 | "0344 Ring %d Cannot find " |
| 1462 | "buffer for an unsolicited " |
| 1463 | "iocb. tag 0x%x\n", |
| 1464 | pring->ringno, |
| 1465 | irsp->unsli3.sli3Words[7]); |
| 1466 | } |
| 1467 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1468 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1469 | if (irsp->ulpBdeCount != 0 && |
| 1470 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1471 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1472 | int found = 0; |
| 1473 | |
| 1474 | /* search continue save q for same XRI */ |
| 1475 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1476 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1477 | list_add_tail(&saveq->list, &iocbq->list); |
| 1478 | found = 1; |
| 1479 | break; |
| 1480 | } |
| 1481 | } |
| 1482 | if (!found) |
| 1483 | list_add_tail(&saveq->clist, |
| 1484 | &pring->iocb_continue_saveq); |
| 1485 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1486 | list_del_init(&iocbq->clist); |
| 1487 | saveq = iocbq; |
| 1488 | irsp = &(saveq->iocb); |
| 1489 | } else |
| 1490 | return 0; |
| 1491 | } |
| 1492 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1493 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1494 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1495 | Rctl = FC_ELS_REQ; |
| 1496 | Type = FC_ELS_DATA; |
| 1497 | } else { |
| 1498 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1499 | Rctl = w5p->hcsw.Rctl; |
| 1500 | Type = w5p->hcsw.Type; |
| 1501 | |
| 1502 | /* Firmware Workaround */ |
| 1503 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1504 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1505 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1506 | Rctl = FC_ELS_REQ; |
| 1507 | Type = FC_ELS_DATA; |
| 1508 | w5p->hcsw.Rctl = Rctl; |
| 1509 | w5p->hcsw.Type = Type; |
| 1510 | } |
| 1511 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | /* unSolicited Responses */ |
| 1514 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1515 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1516 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1517 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | match = 1; |
| 1519 | } else { |
| 1520 | /* We must search, based on rctl / type |
| 1521 | for the right routine */ |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1522 | for (i = 0; i < pring->num_mask; i++) { |
| 1523 | if ((pring->prt[i].rctl == Rctl) |
| 1524 | && (pring->prt[i].type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1525 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1526 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1527 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | match = 1; |
| 1529 | break; |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | if (match == 0) { |
| 1534 | /* Unexpected Rctl / Type received */ |
| 1535 | /* Ring <ringno> handler: unexpected |
| 1536 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1537 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1538 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1539 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1540 | pring->ringno, Rctl, Type); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1542 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | } |
| 1544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1545 | /** |
| 1546 | * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb. |
| 1547 | * @phba: Pointer to HBA context object. |
| 1548 | * @pring: Pointer to driver SLI ring object. |
| 1549 | * @prspiocb: Pointer to response iocb object. |
| 1550 | * |
| 1551 | * This function looks up the iocb_lookup table to get the command iocb |
| 1552 | * corresponding to the given response iocb using the iotag of the |
| 1553 | * response iocb. This function is called with the hbalock held. |
| 1554 | * This function returns the command iocb object if it finds the command |
| 1555 | * iocb else returns NULL. |
| 1556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1558 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1559 | struct lpfc_sli_ring *pring, |
| 1560 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1563 | uint16_t iotag; |
| 1564 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1565 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1567 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1568 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1569 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1570 | pring->txcmplq_cnt--; |
| 1571 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | } |
| 1573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1574 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1575 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1576 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1577 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1578 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | return NULL; |
| 1580 | } |
| 1581 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1582 | /** |
| 1583 | * lpfc_sli_process_sol_iocb: process solicited iocb completion. |
| 1584 | * @phba: Pointer to HBA context object. |
| 1585 | * @pring: Pointer to driver SLI ring object. |
| 1586 | * @saveq: Pointer to the response iocb to be processed. |
| 1587 | * |
| 1588 | * This function is called by the ring event handler for non-fcp |
| 1589 | * rings when there is a new response iocb in the response ring. |
| 1590 | * The caller is not required to hold any locks. This function |
| 1591 | * gets the command iocb associated with the response iocb and |
| 1592 | * calls the completion handler for the command iocb. If there |
| 1593 | * is no completion handler, the function will free the resources |
| 1594 | * associated with command iocb. If the response iocb is for |
| 1595 | * an already aborted command iocb, the status of the completion |
| 1596 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1597 | * This function always returns 1. |
| 1598 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1599 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1600 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | struct lpfc_iocbq *saveq) |
| 1602 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1603 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | int rc = 1; |
| 1605 | unsigned long iflag; |
| 1606 | |
| 1607 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1608 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1609 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1610 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1611 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | if (cmdiocbp) { |
| 1613 | if (cmdiocbp->iocb_cmpl) { |
| 1614 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1615 | * If an ELS command failed send an event to mgmt |
| 1616 | * application. |
| 1617 | */ |
| 1618 | if (saveq->iocb.ulpStatus && |
| 1619 | (pring->ringno == LPFC_ELS_RING) && |
| 1620 | (cmdiocbp->iocb.ulpCommand == |
| 1621 | CMD_ELS_REQUEST64_CR)) |
| 1622 | lpfc_send_els_failure_event(phba, |
| 1623 | cmdiocbp, saveq); |
| 1624 | |
| 1625 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | * Post all ELS completions to the worker thread. |
| 1627 | * All other are passed to the completion callback. |
| 1628 | */ |
| 1629 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1630 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1631 | cmdiocbp->iocb_flag &= |
| 1632 | ~LPFC_DRIVER_ABORTED; |
| 1633 | saveq->iocb.ulpStatus = |
| 1634 | IOSTAT_LOCAL_REJECT; |
| 1635 | saveq->iocb.un.ulpWord[4] = |
| 1636 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1637 | |
| 1638 | /* Firmware could still be in progress |
| 1639 | * of DMAing payload, so don't free data |
| 1640 | * buffer till after a hbeat. |
| 1641 | */ |
| 1642 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1643 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1646 | } else |
| 1647 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | } else { |
| 1649 | /* |
| 1650 | * Unknown initiating command based on the response iotag. |
| 1651 | * This could be the case on the ELS ring because of |
| 1652 | * lpfc_els_abort(). |
| 1653 | */ |
| 1654 | if (pring->ringno != LPFC_ELS_RING) { |
| 1655 | /* |
| 1656 | * Ring <ringno> handler: unexpected completion IoTag |
| 1657 | * <IoTag> |
| 1658 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1659 | lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI, |
| 1660 | "0322 Ring %d handler: " |
| 1661 | "unexpected completion IoTag x%x " |
| 1662 | "Data: x%x x%x x%x x%x\n", |
| 1663 | pring->ringno, |
| 1664 | saveq->iocb.ulpIoTag, |
| 1665 | saveq->iocb.ulpStatus, |
| 1666 | saveq->iocb.un.ulpWord[4], |
| 1667 | saveq->iocb.ulpCommand, |
| 1668 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1669 | } |
| 1670 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | return rc; |
| 1673 | } |
| 1674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1675 | /** |
| 1676 | * lpfc_sli_rsp_pointers_error: Response ring pointer error handler. |
| 1677 | * @phba: Pointer to HBA context object. |
| 1678 | * @pring: Pointer to driver SLI ring object. |
| 1679 | * |
| 1680 | * This function is called from the iocb ring event handlers when |
| 1681 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1682 | * an error attention condition to the worker thread and the worker |
| 1683 | * thread will transition the HBA to offline state. |
| 1684 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | static void |
| 1686 | 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] | 1687 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1688 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1689 | /* |
| 1690 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 1691 | * rsp ring <portRspMax> |
| 1692 | */ |
| 1693 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1694 | "0312 Ring %d handler: portRspPut %d " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1695 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1696 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1697 | pring->numRiocb); |
| 1698 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1699 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1700 | |
| 1701 | /* |
| 1702 | * All error attention handlers are posted to |
| 1703 | * worker thread |
| 1704 | */ |
| 1705 | phba->work_ha |= HA_ERATT; |
| 1706 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1707 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1708 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1709 | |
| 1710 | return; |
| 1711 | } |
| 1712 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1713 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1714 | * lpfc_poll_eratt: Error attention polling timer timeout handler. |
| 1715 | * @ptr: Pointer to address of HBA context object. |
| 1716 | * |
| 1717 | * This function is invoked by the Error Attention polling timer when the |
| 1718 | * timer times out. It will check the SLI Error Attention register for |
| 1719 | * possible attention events. If so, it will post an Error Attention event |
| 1720 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1721 | * Error Attention polling timer for the next poll. |
| 1722 | **/ |
| 1723 | void lpfc_poll_eratt(unsigned long ptr) |
| 1724 | { |
| 1725 | struct lpfc_hba *phba; |
| 1726 | uint32_t eratt = 0; |
| 1727 | |
| 1728 | phba = (struct lpfc_hba *)ptr; |
| 1729 | |
| 1730 | /* Check chip HA register for error event */ |
| 1731 | eratt = lpfc_sli_check_eratt(phba); |
| 1732 | |
| 1733 | if (eratt) |
| 1734 | /* Tell the worker thread there is work to do */ |
| 1735 | lpfc_worker_wake_up(phba); |
| 1736 | else |
| 1737 | /* Restart the timer for next eratt poll */ |
| 1738 | mod_timer(&phba->eratt_poll, jiffies + |
| 1739 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1740 | return; |
| 1741 | } |
| 1742 | |
| 1743 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1744 | * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode. |
| 1745 | * @phba: Pointer to HBA context object. |
| 1746 | * |
| 1747 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1748 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1749 | * is enabled. |
| 1750 | * |
| 1751 | * The caller does not hold any lock. |
| 1752 | * The function processes each response iocb in the response ring until it |
| 1753 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1754 | * LE bit set. The function will call the completion handler of the command iocb |
| 1755 | * if the response iocb indicates a completion for a command iocb or it is |
| 1756 | * an abort completion. |
| 1757 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1758 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1759 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | struct lpfc_sli *psli = &phba->sli; |
| 1761 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1762 | IOCB_t *irsp = NULL; |
| 1763 | IOCB_t *entry = NULL; |
| 1764 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1765 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1766 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1767 | uint32_t status; |
| 1768 | uint32_t portRspPut, portRspMax; |
| 1769 | int type; |
| 1770 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1771 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1772 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1773 | |
| 1774 | pring->stats.iocb_event++; |
| 1775 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1776 | /* |
| 1777 | * The next available response entry should never exceed the maximum |
| 1778 | * entries. If it does, treat it as an adapter hardware error. |
| 1779 | */ |
| 1780 | portRspMax = pring->numRiocb; |
| 1781 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1782 | if (unlikely(portRspPut >= portRspMax)) { |
| 1783 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1784 | return; |
| 1785 | } |
| 1786 | |
| 1787 | rmb(); |
| 1788 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1789 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1790 | if (++pring->rspidx >= portRspMax) |
| 1791 | pring->rspidx = 0; |
| 1792 | |
| 1793 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1794 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1795 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1796 | irsp = &rspiocbq.iocb; |
| 1797 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1798 | pring->stats.iocb_rsp++; |
| 1799 | rsp_cmpl++; |
| 1800 | |
| 1801 | if (unlikely(irsp->ulpStatus)) { |
| 1802 | /* Rsp ring <ringno> error: IOCB */ |
| 1803 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1804 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1805 | "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] | 1806 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1807 | irsp->un.ulpWord[0], |
| 1808 | irsp->un.ulpWord[1], |
| 1809 | irsp->un.ulpWord[2], |
| 1810 | irsp->un.ulpWord[3], |
| 1811 | irsp->un.ulpWord[4], |
| 1812 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1813 | *(uint32_t *)&irsp->un1, |
| 1814 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | switch (type) { |
| 1818 | case LPFC_ABORT_IOCB: |
| 1819 | case LPFC_SOL_IOCB: |
| 1820 | /* |
| 1821 | * Idle exchange closed via ABTS from port. No iocb |
| 1822 | * resources need to be recovered. |
| 1823 | */ |
| 1824 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1825 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1826 | "0314 IOCB cmd 0x%x " |
| 1827 | "processed. Skipping " |
| 1828 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1829 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1830 | break; |
| 1831 | } |
| 1832 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1834 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1835 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1837 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1838 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1839 | &rspiocbq); |
| 1840 | } |
| 1841 | break; |
| 1842 | default: |
| 1843 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1844 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1845 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1846 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1847 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1848 | dev_warn(&((phba->pcidev)->dev), |
| 1849 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1850 | phba->brd_no, adaptermsg); |
| 1851 | } else { |
| 1852 | /* Unknown IOCB command */ |
| 1853 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1854 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1855 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1856 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1857 | irsp->ulpStatus, |
| 1858 | irsp->ulpIoTag, |
| 1859 | irsp->ulpContext); |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | |
| 1864 | /* |
| 1865 | * The response IOCB has been processed. Update the ring |
| 1866 | * pointer in SLIM. If the port response put pointer has not |
| 1867 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1868 | * response put pointer. |
| 1869 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1870 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1871 | |
| 1872 | if (pring->rspidx == portRspPut) |
| 1873 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1874 | } |
| 1875 | |
| 1876 | ha_copy = readl(phba->HAregaddr); |
| 1877 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1878 | |
| 1879 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1880 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1881 | pring->stats.iocb_rsp_full++; |
| 1882 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1883 | writel(status, phba->CAregaddr); |
| 1884 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1885 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1886 | } |
| 1887 | if ((ha_copy & HA_R0CE_RSP) && |
| 1888 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1890 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1891 | pring->stats.iocb_cmd_empty++; |
| 1892 | |
| 1893 | /* Force update of the local copy of cmdGetInx */ |
| 1894 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1895 | lpfc_sli_resume_iocb(phba, pring); |
| 1896 | |
| 1897 | if ((pring->lpfc_sli_cmd_available)) |
| 1898 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1900 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | return; |
| 1904 | } |
| 1905 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1906 | /** |
| 1907 | * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring. |
| 1908 | * @phba: Pointer to HBA context object. |
| 1909 | * @pring: Pointer to driver SLI ring object. |
| 1910 | * @mask: Host attention register mask for this ring. |
| 1911 | * |
| 1912 | * This function is called from the interrupt context when there is a ring |
| 1913 | * event for the fcp ring. The caller does not hold any lock. |
| 1914 | * The function processes each response iocb in the response ring until it |
| 1915 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1916 | * LE bit set. The function will call the completion handler of the command iocb |
| 1917 | * if the response iocb indicates a completion for a command iocb or it is |
| 1918 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1919 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1921 | * to check it explicitly. This function always returns 1. |
| 1922 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1924 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1925 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1927 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1929 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1930 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1931 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | uint32_t status; |
| 1933 | uint32_t portRspPut, portRspMax; |
| 1934 | int rc = 1; |
| 1935 | lpfc_iocb_type type; |
| 1936 | unsigned long iflag; |
| 1937 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1939 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | pring->stats.iocb_event++; |
| 1941 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | /* |
| 1943 | * The next available response entry should never exceed the maximum |
| 1944 | * entries. If it does, treat it as an adapter hardware error. |
| 1945 | */ |
| 1946 | portRspMax = pring->numRiocb; |
| 1947 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1948 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1949 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1950 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | return 1; |
| 1952 | } |
| 1953 | |
| 1954 | rmb(); |
| 1955 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1956 | /* |
| 1957 | * Fetch an entry off the ring and copy it into a local data |
| 1958 | * structure. The copy involves a byte-swap since the |
| 1959 | * network byte order and pci byte orders are different. |
| 1960 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1961 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1962 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1963 | |
| 1964 | if (++pring->rspidx >= portRspMax) |
| 1965 | pring->rspidx = 0; |
| 1966 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1967 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1968 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1969 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1970 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1971 | irsp = &rspiocbq.iocb; |
| 1972 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1974 | pring->stats.iocb_rsp++; |
| 1975 | rsp_cmpl++; |
| 1976 | |
| 1977 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1978 | /* |
| 1979 | * If resource errors reported from HBA, reduce |
| 1980 | * queuedepths of the SCSI device. |
| 1981 | */ |
| 1982 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1983 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1984 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1985 | lpfc_adjust_queue_depth(phba); |
| 1986 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1987 | } |
| 1988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | /* Rsp ring <ringno> error: IOCB */ |
| 1990 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1991 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | "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] | 1993 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1994 | irsp->un.ulpWord[0], |
| 1995 | irsp->un.ulpWord[1], |
| 1996 | irsp->un.ulpWord[2], |
| 1997 | irsp->un.ulpWord[3], |
| 1998 | irsp->un.ulpWord[4], |
| 1999 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2000 | *(uint32_t *)&irsp->un1, |
| 2001 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | switch (type) { |
| 2005 | case LPFC_ABORT_IOCB: |
| 2006 | case LPFC_SOL_IOCB: |
| 2007 | /* |
| 2008 | * Idle exchange closed via ABTS from port. No iocb |
| 2009 | * resources need to be recovered. |
| 2010 | */ |
| 2011 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2012 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2013 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2014 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2015 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2016 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2020 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2021 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2023 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2024 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2025 | &rspiocbq); |
| 2026 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | spin_unlock_irqrestore(&phba->hbalock, |
| 2028 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2029 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2030 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2031 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2032 | iflag); |
| 2033 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | } |
| 2035 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2036 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2037 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2038 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2039 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2040 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | default: |
| 2042 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2043 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2044 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2045 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2046 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2047 | dev_warn(&((phba->pcidev)->dev), |
| 2048 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | phba->brd_no, adaptermsg); |
| 2050 | } else { |
| 2051 | /* Unknown IOCB command */ |
| 2052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2053 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2055 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | irsp->ulpStatus, |
| 2057 | irsp->ulpIoTag, |
| 2058 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | } |
| 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | /* |
| 2064 | * The response IOCB has been processed. Update the ring |
| 2065 | * pointer in SLIM. If the port response put pointer has not |
| 2066 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2067 | * response put pointer. |
| 2068 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2069 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | |
| 2071 | if (pring->rspidx == portRspPut) |
| 2072 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2073 | } |
| 2074 | |
| 2075 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2076 | pring->stats.iocb_rsp_full++; |
| 2077 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2078 | writel(status, phba->CAregaddr); |
| 2079 | readl(phba->CAregaddr); |
| 2080 | } |
| 2081 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2082 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2083 | pring->stats.iocb_cmd_empty++; |
| 2084 | |
| 2085 | /* Force update of the local copy of cmdGetInx */ |
| 2086 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2087 | lpfc_sli_resume_iocb(phba, pring); |
| 2088 | |
| 2089 | if ((pring->lpfc_sli_cmd_available)) |
| 2090 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2091 | |
| 2092 | } |
| 2093 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | return rc; |
| 2096 | } |
| 2097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2098 | /** |
| 2099 | * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings. |
| 2100 | * @phba: Pointer to HBA context object. |
| 2101 | * @pring: Pointer to driver SLI ring object. |
| 2102 | * @mask: Host attention register mask for this ring. |
| 2103 | * |
| 2104 | * This function is called from the worker thread when there is a ring |
| 2105 | * event for non-fcp rings. The caller does not hold any lock . |
| 2106 | * The function processes each response iocb in the response ring until it |
| 2107 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2108 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the |
| 2109 | * response iocb indicates a completion of a command iocb. The function |
| 2110 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited |
| 2111 | * iocb. The function frees the resources or calls the completion handler if |
| 2112 | * this iocb is an abort completion. The function returns 0 when the allocated |
| 2113 | * iocbs are not freed, otherwise returns 1. |
| 2114 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2116 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2117 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2119 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | IOCB_t *entry; |
| 2121 | IOCB_t *irsp = NULL; |
| 2122 | struct lpfc_iocbq *rspiocbp = NULL; |
| 2123 | struct lpfc_iocbq *next_iocb; |
| 2124 | struct lpfc_iocbq *cmdiocbp; |
| 2125 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | uint8_t iocb_cmd_type; |
| 2127 | lpfc_iocb_type type; |
| 2128 | uint32_t status, free_saveq; |
| 2129 | uint32_t portRspPut, portRspMax; |
| 2130 | int rc = 1; |
| 2131 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2133 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | pring->stats.iocb_event++; |
| 2136 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | /* |
| 2138 | * The next available response entry should never exceed the maximum |
| 2139 | * entries. If it does, treat it as an adapter hardware error. |
| 2140 | */ |
| 2141 | portRspMax = pring->numRiocb; |
| 2142 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2143 | if (portRspPut >= portRspMax) { |
| 2144 | /* |
| 2145 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 2146 | * rsp ring <portRspMax> |
| 2147 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2148 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2149 | "0303 Ring %d handler: portRspPut %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2151 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2153 | phba->link_state = LPFC_HBA_ERROR; |
| 2154 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | |
| 2156 | phba->work_hs = HS_FFER3; |
| 2157 | lpfc_handle_eratt(phba); |
| 2158 | |
| 2159 | return 1; |
| 2160 | } |
| 2161 | |
| 2162 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 | while (pring->rspidx != portRspPut) { |
| 2164 | /* |
| 2165 | * Build a completion list and call the appropriate handler. |
| 2166 | * The process is to get the next available response iocb, get |
| 2167 | * a free iocb from the list, copy the response data into the |
| 2168 | * free iocb, insert to the continuation list, and update the |
| 2169 | * next response index to slim. This process makes response |
| 2170 | * iocb's in the ring available to DMA as fast as possible but |
| 2171 | * pays a penalty for a copy operation. Since the iocb is |
| 2172 | * only 32 bytes, this penalty is considered small relative to |
| 2173 | * the PCI reads for register values and a slim write. When |
| 2174 | * the ulpLe field is set, the entire Command has been |
| 2175 | * received. |
| 2176 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2177 | entry = lpfc_resp_iocb(phba, pring); |
| 2178 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2179 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | if (rspiocbp == NULL) { |
| 2182 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2183 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | break; |
| 2185 | } |
| 2186 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2187 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2188 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | irsp = &rspiocbp->iocb; |
| 2190 | |
| 2191 | if (++pring->rspidx >= portRspMax) |
| 2192 | pring->rspidx = 0; |
| 2193 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2194 | if (pring->ringno == LPFC_ELS_RING) { |
| 2195 | lpfc_debugfs_slow_ring_trc(phba, |
| 2196 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2197 | *(((uint32_t *) irsp) + 4), |
| 2198 | *(((uint32_t *) irsp) + 6), |
| 2199 | *(((uint32_t *) irsp) + 7)); |
| 2200 | } |
| 2201 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2202 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2204 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | |
| 2206 | pring->iocb_continueq_cnt++; |
| 2207 | if (irsp->ulpLe) { |
| 2208 | /* |
| 2209 | * By default, the driver expects to free all resources |
| 2210 | * associated with this iocb completion. |
| 2211 | */ |
| 2212 | free_saveq = 1; |
| 2213 | saveq = list_get_first(&pring->iocb_continueq, |
| 2214 | struct lpfc_iocbq, list); |
| 2215 | irsp = &(saveq->iocb); |
| 2216 | list_del_init(&pring->iocb_continueq); |
| 2217 | pring->iocb_continueq_cnt = 0; |
| 2218 | |
| 2219 | pring->stats.iocb_rsp++; |
| 2220 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2221 | /* |
| 2222 | * If resource errors reported from HBA, reduce |
| 2223 | * queuedepths of the SCSI device. |
| 2224 | */ |
| 2225 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2226 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2227 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2228 | lpfc_adjust_queue_depth(phba); |
| 2229 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2230 | } |
| 2231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | if (irsp->ulpStatus) { |
| 2233 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2234 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2235 | "0328 Rsp Ring %d error: " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2236 | "IOCB Data: " |
| 2237 | "x%x x%x x%x x%x " |
| 2238 | "x%x x%x x%x x%x " |
| 2239 | "x%x x%x x%x x%x " |
| 2240 | "x%x x%x x%x x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2241 | pring->ringno, |
| 2242 | irsp->un.ulpWord[0], |
| 2243 | irsp->un.ulpWord[1], |
| 2244 | irsp->un.ulpWord[2], |
| 2245 | irsp->un.ulpWord[3], |
| 2246 | irsp->un.ulpWord[4], |
| 2247 | irsp->un.ulpWord[5], |
| 2248 | *(((uint32_t *) irsp) + 6), |
| 2249 | *(((uint32_t *) irsp) + 7), |
| 2250 | *(((uint32_t *) irsp) + 8), |
| 2251 | *(((uint32_t *) irsp) + 9), |
| 2252 | *(((uint32_t *) irsp) + 10), |
| 2253 | *(((uint32_t *) irsp) + 11), |
| 2254 | *(((uint32_t *) irsp) + 12), |
| 2255 | *(((uint32_t *) irsp) + 13), |
| 2256 | *(((uint32_t *) irsp) + 14), |
| 2257 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /* |
| 2261 | * Fetch the IOCB command type and call the correct |
| 2262 | * completion routine. Solicited and Unsolicited |
| 2263 | * IOCBs on the ELS ring get freed back to the |
| 2264 | * lpfc_iocb_list by the discovery kernel thread. |
| 2265 | */ |
| 2266 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2267 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2268 | if (type == LPFC_SOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2269 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2271 | saveq); |
| 2272 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2274 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | saveq); |
| 2277 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2278 | if (!rc) |
| 2279 | free_saveq = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | } else if (type == LPFC_ABORT_IOCB) { |
| 2281 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 2282 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2283 | lpfc_sli_iocbq_lookup(phba, pring, |
| 2284 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2285 | /* Call the specified completion |
| 2286 | routine */ |
| 2287 | if (cmdiocbp->iocb_cmpl) { |
| 2288 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2289 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | iflag); |
| 2291 | (cmdiocbp->iocb_cmpl) (phba, |
| 2292 | cmdiocbp, saveq); |
| 2293 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2294 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2296 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2297 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2298 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | } |
| 2300 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 2301 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2302 | |
| 2303 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2304 | |
| 2305 | memset(adaptermsg, 0, |
| 2306 | LPFC_MAX_ADPTMSG); |
| 2307 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2308 | MAX_MSG_DATA); |
| 2309 | dev_warn(&((phba->pcidev)->dev), |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2310 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | phba->brd_no, adaptermsg); |
| 2312 | } else { |
| 2313 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2314 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2315 | "0335 Unknown IOCB " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | "command Data: x%x " |
| 2317 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2318 | irsp->ulpCommand, |
| 2319 | irsp->ulpStatus, |
| 2320 | irsp->ulpIoTag, |
| 2321 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2326 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2327 | &saveq->list, list) { |
| 2328 | list_del(&rspiocbp->list); |
| 2329 | __lpfc_sli_release_iocbq(phba, |
| 2330 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2332 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2334 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /* |
| 2338 | * If the port response put pointer has not been updated, sync |
| 2339 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2340 | * response put pointer. |
| 2341 | */ |
| 2342 | if (pring->rspidx == portRspPut) { |
| 2343 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2344 | } |
| 2345 | } /* while (pring->rspidx != portRspPut) */ |
| 2346 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | /* At least one response entry has been freed */ |
| 2349 | pring->stats.iocb_rsp_full++; |
| 2350 | /* SET RxRE_RSP in Chip Att register */ |
| 2351 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2352 | writel(status, phba->CAregaddr); |
| 2353 | readl(phba->CAregaddr); /* flush */ |
| 2354 | } |
| 2355 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2356 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2357 | pring->stats.iocb_cmd_empty++; |
| 2358 | |
| 2359 | /* Force update of the local copy of cmdGetInx */ |
| 2360 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2361 | lpfc_sli_resume_iocb(phba, pring); |
| 2362 | |
| 2363 | if ((pring->lpfc_sli_cmd_available)) |
| 2364 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2365 | |
| 2366 | } |
| 2367 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | return rc; |
| 2370 | } |
| 2371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2372 | /** |
| 2373 | * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring. |
| 2374 | * @phba: Pointer to HBA context object. |
| 2375 | * @pring: Pointer to driver SLI ring object. |
| 2376 | * |
| 2377 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2378 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2379 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2380 | * the return of this function. The caller is not required to hold any locks. |
| 2381 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2384 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2385 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2387 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2389 | if (pring->ringno == LPFC_ELS_RING) { |
| 2390 | lpfc_fabric_abort_hba(phba); |
| 2391 | } |
| 2392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | /* Error everything on txq and txcmplq |
| 2394 | * First do the txq. |
| 2395 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2396 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2397 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | |
| 2400 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2401 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2402 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2403 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2405 | |
| 2406 | while (!list_empty(&completions)) { |
| 2407 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | cmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2409 | list_del_init(&iocb->list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2411 | if (!iocb->iocb_cmpl) |
| 2412 | lpfc_sli_release_iocbq(phba, iocb); |
| 2413 | else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2415 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
| 2420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | /** |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2422 | * lpfc_sli_flush_fcp_rings: flush all iocbs in the fcp ring. |
| 2423 | * @phba: Pointer to HBA context object. |
| 2424 | * |
| 2425 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2426 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2427 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2428 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2429 | * slot has been permanently disabled. |
| 2430 | **/ |
| 2431 | void |
| 2432 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2433 | { |
| 2434 | LIST_HEAD(txq); |
| 2435 | LIST_HEAD(txcmplq); |
| 2436 | struct lpfc_iocbq *iocb; |
| 2437 | IOCB_t *cmd = NULL; |
| 2438 | struct lpfc_sli *psli = &phba->sli; |
| 2439 | struct lpfc_sli_ring *pring; |
| 2440 | |
| 2441 | /* Currently, only one fcp ring */ |
| 2442 | pring = &psli->ring[psli->fcp_ring]; |
| 2443 | |
| 2444 | spin_lock_irq(&phba->hbalock); |
| 2445 | /* Retrieve everything on txq */ |
| 2446 | list_splice_init(&pring->txq, &txq); |
| 2447 | pring->txq_cnt = 0; |
| 2448 | |
| 2449 | /* Retrieve everything on the txcmplq */ |
| 2450 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2451 | pring->txcmplq_cnt = 0; |
| 2452 | spin_unlock_irq(&phba->hbalock); |
| 2453 | |
| 2454 | /* Flush the txq */ |
| 2455 | while (!list_empty(&txq)) { |
| 2456 | iocb = list_get_first(&txq, struct lpfc_iocbq, list); |
| 2457 | cmd = &iocb->iocb; |
| 2458 | list_del_init(&iocb->list); |
| 2459 | |
| 2460 | if (!iocb->iocb_cmpl) |
| 2461 | lpfc_sli_release_iocbq(phba, iocb); |
| 2462 | else { |
| 2463 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2464 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2465 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | /* Flush the txcmpq */ |
| 2470 | while (!list_empty(&txcmplq)) { |
| 2471 | iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list); |
| 2472 | cmd = &iocb->iocb; |
| 2473 | list_del_init(&iocb->list); |
| 2474 | |
| 2475 | if (!iocb->iocb_cmpl) |
| 2476 | lpfc_sli_release_iocbq(phba, iocb); |
| 2477 | else { |
| 2478 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2479 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2480 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2486 | * lpfc_sli_brdready: Check for host status bits. |
| 2487 | * @phba: Pointer to HBA context object. |
| 2488 | * @mask: Bit mask to be checked. |
| 2489 | * |
| 2490 | * This function reads the host status register and compares |
| 2491 | * with the provided bit mask to check if HBA completed |
| 2492 | * the restart. This function will wait in a loop for the |
| 2493 | * HBA to complete restart. If the HBA does not restart within |
| 2494 | * 15 iterations, the function will reset the HBA again. The |
| 2495 | * function returns 1 when HBA fail to restart otherwise returns |
| 2496 | * zero. |
| 2497 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2498 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2499 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2500 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2501 | uint32_t status; |
| 2502 | int i = 0; |
| 2503 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2505 | /* Read the HBA Host Status Register */ |
| 2506 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2508 | /* |
| 2509 | * Check status register every 100ms for 5 retries, then every |
| 2510 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2511 | * every 2.5 sec for 4. |
| 2512 | * Break our of the loop if errors occurred during init. |
| 2513 | */ |
| 2514 | while (((status & mask) != mask) && |
| 2515 | !(status & HS_FFERM) && |
| 2516 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2518 | if (i <= 5) |
| 2519 | msleep(10); |
| 2520 | else if (i <= 10) |
| 2521 | msleep(500); |
| 2522 | else |
| 2523 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2524 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2525 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2526 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2527 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2528 | lpfc_sli_brdrestart(phba); |
| 2529 | } |
| 2530 | /* Read the HBA Host Status Register */ |
| 2531 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2534 | /* Check to see if any errors occurred during init */ |
| 2535 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2537 | retval = 1; |
| 2538 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2540 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | } |
| 2542 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2543 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2545 | /** |
| 2546 | * lpfc_reset_barrier: Make HBA ready for HBA reset. |
| 2547 | * @phba: Pointer to HBA context object. |
| 2548 | * |
| 2549 | * This function is called before resetting an HBA. This |
| 2550 | * function requests HBA to quiesce DMAs before a reset. |
| 2551 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2552 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2553 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2554 | uint32_t __iomem *resp_buf; |
| 2555 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2556 | volatile uint32_t mbox; |
| 2557 | uint32_t hc_copy; |
| 2558 | int i; |
| 2559 | uint8_t hdrtype; |
| 2560 | |
| 2561 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2562 | if (hdrtype != 0x80 || |
| 2563 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2564 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2565 | return; |
| 2566 | |
| 2567 | /* |
| 2568 | * Tell the other part of the chip to suspend temporarily all |
| 2569 | * its DMA activity. |
| 2570 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2571 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2572 | |
| 2573 | /* Disable the error attention */ |
| 2574 | hc_copy = readl(phba->HCregaddr); |
| 2575 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2576 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2578 | |
| 2579 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2580 | /* Clear Chip error bit */ |
| 2581 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2582 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | mbox = 0; |
| 2586 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2587 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2588 | |
| 2589 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2590 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2591 | writel(mbox, mbox_buf); |
| 2592 | |
| 2593 | for (i = 0; |
| 2594 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2595 | mdelay(1); |
| 2596 | |
| 2597 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2598 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2599 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2600 | goto restore_hc; |
| 2601 | else |
| 2602 | goto clear_errat; |
| 2603 | } |
| 2604 | |
| 2605 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2606 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2607 | mdelay(1); |
| 2608 | |
| 2609 | clear_errat: |
| 2610 | |
| 2611 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2612 | mdelay(1); |
| 2613 | |
| 2614 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2615 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2620 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2621 | writel(hc_copy, phba->HCregaddr); |
| 2622 | readl(phba->HCregaddr); /* flush */ |
| 2623 | } |
| 2624 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2625 | /** |
| 2626 | * lpfc_sli_brdkill: Issue a kill_board mailbox command. |
| 2627 | * @phba: Pointer to HBA context object. |
| 2628 | * |
| 2629 | * This function issues a kill_board mailbox command and waits for |
| 2630 | * the error attention interrupt. This function is called for stopping |
| 2631 | * the firmware processing. The caller is not required to hold any |
| 2632 | * locks. This function calls lpfc_hba_down_post function to free |
| 2633 | * any pending commands after the kill. The function will return 1 when it |
| 2634 | * fails to kill the board else will return 0. |
| 2635 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2636 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2639 | struct lpfc_sli *psli; |
| 2640 | LPFC_MBOXQ_t *pmb; |
| 2641 | uint32_t status; |
| 2642 | uint32_t ha_copy; |
| 2643 | int retval; |
| 2644 | int i = 0; |
| 2645 | |
| 2646 | psli = &phba->sli; |
| 2647 | |
| 2648 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2649 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2650 | "0329 Kill HBA Data: x%x x%x\n", |
| 2651 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2652 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2653 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2654 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2655 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2656 | |
| 2657 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2659 | status = readl(phba->HCregaddr); |
| 2660 | status &= ~HC_ERINT_ENA; |
| 2661 | writel(status, phba->HCregaddr); |
| 2662 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2664 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2665 | |
| 2666 | lpfc_kill_board(phba, pmb); |
| 2667 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2668 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2669 | |
| 2670 | if (retval != MBX_SUCCESS) { |
| 2671 | if (retval != MBX_BUSY) |
| 2672 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | spin_lock_irq(&phba->hbalock); |
| 2674 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2675 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2676 | return 1; |
| 2677 | } |
| 2678 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2679 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2680 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2681 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2682 | |
| 2683 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2684 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2685 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2686 | * board is now undefined. |
| 2687 | */ |
| 2688 | ha_copy = readl(phba->HAregaddr); |
| 2689 | |
| 2690 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2691 | mdelay(100); |
| 2692 | ha_copy = readl(phba->HAregaddr); |
| 2693 | } |
| 2694 | |
| 2695 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2696 | if (ha_copy & HA_ERATT) { |
| 2697 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2699 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2700 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2701 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2702 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2703 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2704 | |
| 2705 | psli->mbox_active = NULL; |
| 2706 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2707 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2708 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2710 | } |
| 2711 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2712 | /** |
| 2713 | * lpfc_sli_brdreset: Reset the HBA. |
| 2714 | * @phba: Pointer to HBA context object. |
| 2715 | * |
| 2716 | * This function resets the HBA by writing HC_INITFF to the control |
| 2717 | * register. After the HBA resets, this function resets all the iocb ring |
| 2718 | * indices. This function disables PCI layer parity checking during |
| 2719 | * the reset. |
| 2720 | * This function returns 0 always. |
| 2721 | * The caller is not required to hold any locks. |
| 2722 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2723 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2725 | { |
| 2726 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2728 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2729 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2731 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2733 | /* Reset HBA */ |
| 2734 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2735 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | |
| 2738 | /* perform board reset */ |
| 2739 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | phba->pport->fc_myDID = 0; |
| 2741 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2743 | /* Turn off parity checking and serr during the physical reset */ |
| 2744 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2745 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2746 | (cfg_value & |
| 2747 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2748 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2749 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2750 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2751 | writel(HC_INITFF, phba->HCregaddr); |
| 2752 | mdelay(1); |
| 2753 | readl(phba->HCregaddr); /* flush */ |
| 2754 | writel(0, phba->HCregaddr); |
| 2755 | readl(phba->HCregaddr); /* flush */ |
| 2756 | |
| 2757 | /* Restore PCI cmd register */ |
| 2758 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | |
| 2760 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2761 | for (i = 0; i < psli->num_rings; i++) { |
| 2762 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | pring->flag = 0; |
| 2764 | pring->rspidx = 0; |
| 2765 | pring->next_cmdidx = 0; |
| 2766 | pring->local_getidx = 0; |
| 2767 | pring->cmdidx = 0; |
| 2768 | pring->missbufcnt = 0; |
| 2769 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2771 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2772 | return 0; |
| 2773 | } |
| 2774 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2775 | /** |
| 2776 | * lpfc_sli_brdrestart: Restart the HBA. |
| 2777 | * @phba: Pointer to HBA context object. |
| 2778 | * |
| 2779 | * This function is called in the SLI initialization code path to |
| 2780 | * restart the HBA. The caller is not required to hold any lock. |
| 2781 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2782 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2783 | * function to free any pending commands. The function enables |
| 2784 | * POST only during the first initialization. The function returns zero. |
| 2785 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2786 | * command before the return of this function. |
| 2787 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2788 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2789 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2790 | { |
| 2791 | MAILBOX_t *mb; |
| 2792 | struct lpfc_sli *psli; |
| 2793 | uint16_t skip_post; |
| 2794 | volatile uint32_t word0; |
| 2795 | void __iomem *to_slim; |
| 2796 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2797 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2798 | |
| 2799 | psli = &phba->sli; |
| 2800 | |
| 2801 | /* Restart HBA */ |
| 2802 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2803 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2804 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2805 | |
| 2806 | word0 = 0; |
| 2807 | mb = (MAILBOX_t *) &word0; |
| 2808 | mb->mbxCommand = MBX_RESTART; |
| 2809 | mb->mbxHc = 1; |
| 2810 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2811 | lpfc_reset_barrier(phba); |
| 2812 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2813 | to_slim = phba->MBslimaddr; |
| 2814 | writel(*(uint32_t *) mb, to_slim); |
| 2815 | readl(to_slim); /* flush */ |
| 2816 | |
| 2817 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2818 | if (phba->pport->port_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2819 | skip_post = 1; |
| 2820 | word0 = 1; /* This is really setting up word1 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | } else { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2822 | skip_post = 0; |
| 2823 | word0 = 0; /* This is really setting up word1 */ |
| 2824 | } |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2825 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2826 | writel(*(uint32_t *) mb, to_slim); |
| 2827 | readl(to_slim); /* flush */ |
| 2828 | |
| 2829 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2830 | phba->pport->stopped = 0; |
| 2831 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2832 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2833 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2834 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2835 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2836 | psli->stats_start = get_seconds(); |
| 2837 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2838 | if (skip_post) |
| 2839 | mdelay(100); |
| 2840 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | mdelay(2000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2842 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2843 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2844 | |
| 2845 | return 0; |
| 2846 | } |
| 2847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2848 | /** |
| 2849 | * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart. |
| 2850 | * @phba: Pointer to HBA context object. |
| 2851 | * |
| 2852 | * This function is called after a HBA restart to wait for successful |
| 2853 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2854 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2855 | * iteration, the function will restart the HBA again. The function returns |
| 2856 | * zero if HBA successfully restarted else returns negative error code. |
| 2857 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | static int |
| 2859 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2860 | { |
| 2861 | uint32_t status, i = 0; |
| 2862 | |
| 2863 | /* Read the HBA Host Status Register */ |
| 2864 | status = readl(phba->HSregaddr); |
| 2865 | |
| 2866 | /* Check status register to see what current state is */ |
| 2867 | i = 0; |
| 2868 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2869 | |
| 2870 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2871 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2872 | * 4. |
| 2873 | */ |
| 2874 | if (i++ >= 20) { |
| 2875 | /* Adapter failed to init, timeout, status reg |
| 2876 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2878 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2879 | "timeout, status reg x%x, " |
| 2880 | "FW Data: A8 x%x AC x%x\n", status, |
| 2881 | readl(phba->MBslimaddr + 0xa8), |
| 2882 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | return -ETIMEDOUT; |
| 2885 | } |
| 2886 | |
| 2887 | /* Check to see if any errors occurred during init */ |
| 2888 | if (status & HS_FFERM) { |
| 2889 | /* ERROR: During chipset initialization */ |
| 2890 | /* Adapter failed to init, chipset, status reg |
| 2891 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2893 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2894 | "chipset, status reg x%x, " |
| 2895 | "FW Data: A8 x%x AC x%x\n", status, |
| 2896 | readl(phba->MBslimaddr + 0xa8), |
| 2897 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | return -EIO; |
| 2900 | } |
| 2901 | |
| 2902 | if (i <= 5) { |
| 2903 | msleep(10); |
| 2904 | } else if (i <= 10) { |
| 2905 | msleep(500); |
| 2906 | } else { |
| 2907 | msleep(2500); |
| 2908 | } |
| 2909 | |
| 2910 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2911 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2912 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2913 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | } |
| 2915 | /* Read the HBA Host Status Register */ |
| 2916 | status = readl(phba->HSregaddr); |
| 2917 | } |
| 2918 | |
| 2919 | /* Check to see if any errors occurred during init */ |
| 2920 | if (status & HS_FFERM) { |
| 2921 | /* ERROR: During chipset initialization */ |
| 2922 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2924 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2925 | "status reg x%x, " |
| 2926 | "FW Data: A8 x%x AC x%x\n", status, |
| 2927 | readl(phba->MBslimaddr + 0xa8), |
| 2928 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2929 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2930 | return -EIO; |
| 2931 | } |
| 2932 | |
| 2933 | /* Clear all interrupt enable conditions */ |
| 2934 | writel(0, phba->HCregaddr); |
| 2935 | readl(phba->HCregaddr); /* flush */ |
| 2936 | |
| 2937 | /* setup host attn register */ |
| 2938 | writel(0xffffffff, phba->HAregaddr); |
| 2939 | readl(phba->HAregaddr); /* flush */ |
| 2940 | return 0; |
| 2941 | } |
| 2942 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2943 | /** |
| 2944 | * lpfc_sli_hbq_count: Get the number of HBQs to be configured. |
| 2945 | * |
| 2946 | * This function calculates and returns the number of HBQs required to be |
| 2947 | * configured. |
| 2948 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2949 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2950 | lpfc_sli_hbq_count(void) |
| 2951 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2952 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2953 | } |
| 2954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2955 | /** |
| 2956 | * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries. |
| 2957 | * |
| 2958 | * This function adds the number of hbq entries in every HBQ to get |
| 2959 | * the total number of hbq entries required for the HBA and returns |
| 2960 | * the total count. |
| 2961 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2962 | static int |
| 2963 | lpfc_sli_hbq_entry_count(void) |
| 2964 | { |
| 2965 | int hbq_count = lpfc_sli_hbq_count(); |
| 2966 | int count = 0; |
| 2967 | int i; |
| 2968 | |
| 2969 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2970 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2971 | return count; |
| 2972 | } |
| 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
| 2975 | * lpfc_sli_hbq_size: Calculate memory required for all hbq entries. |
| 2976 | * |
| 2977 | * This function calculates amount of memory required for all hbq entries |
| 2978 | * to be configured and returns the total memory required. |
| 2979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2981 | lpfc_sli_hbq_size(void) |
| 2982 | { |
| 2983 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2984 | } |
| 2985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2986 | /** |
| 2987 | * lpfc_sli_hbq_setup: configure and initialize HBQs. |
| 2988 | * @phba: Pointer to HBA context object. |
| 2989 | * |
| 2990 | * This function is called during the SLI initialization to configure |
| 2991 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 2992 | * required to hold any locks. This function will return zero if successful |
| 2993 | * else it will return negative error code. |
| 2994 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2995 | static int |
| 2996 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2997 | { |
| 2998 | int hbq_count = lpfc_sli_hbq_count(); |
| 2999 | LPFC_MBOXQ_t *pmb; |
| 3000 | MAILBOX_t *pmbox; |
| 3001 | uint32_t hbqno; |
| 3002 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3003 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3004 | /* Get a Mailbox buffer to setup mailbox |
| 3005 | * commands for HBA initialization |
| 3006 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3007 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3008 | |
| 3009 | if (!pmb) |
| 3010 | return -ENOMEM; |
| 3011 | |
| 3012 | pmbox = &pmb->mb; |
| 3013 | |
| 3014 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 3015 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3016 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3017 | |
| 3018 | hbq_entry_index = 0; |
| 3019 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 3020 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 3021 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 3022 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 3023 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3024 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3025 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 3026 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3027 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 3028 | |
| 3029 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 3030 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 3031 | mbxStatus <status>, ring <num> */ |
| 3032 | |
| 3033 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3034 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3035 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3036 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3037 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3038 | pmbox->mbxStatus, hbqno); |
| 3039 | |
| 3040 | phba->link_state = LPFC_HBA_ERROR; |
| 3041 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3042 | return ENXIO; |
| 3043 | } |
| 3044 | } |
| 3045 | phba->hbq_count = hbq_count; |
| 3046 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3047 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3048 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3049 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3050 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 3051 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3052 | return 0; |
| 3053 | } |
| 3054 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3055 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3056 | * lpfc_sli_config_port: Issue config port mailbox command. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3057 | * @phba: Pointer to HBA context object. |
| 3058 | * @sli_mode: sli mode - 2/3 |
| 3059 | * |
| 3060 | * This function is called by the sli intialization code path |
| 3061 | * to issue config_port mailbox command. This function restarts the |
| 3062 | * HBA firmware and issues a config_port mailbox command to configure |
| 3063 | * the SLI interface in the sli mode specified by sli_mode |
| 3064 | * variable. The caller is not required to hold any locks. |
| 3065 | * The function returns 0 if successful, else returns negative error |
| 3066 | * code. |
| 3067 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3068 | int |
| 3069 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | { |
| 3071 | LPFC_MBOXQ_t *pmb; |
| 3072 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3073 | |
| 3074 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3075 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3076 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | return -ENOMEM; |
| 3078 | } |
| 3079 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3080 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3082 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3083 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3085 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3086 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | msleep(2500); |
| 3088 | rc = lpfc_sli_chipset_init(phba); |
| 3089 | if (rc) |
| 3090 | break; |
| 3091 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3092 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3093 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | resetcount++; |
| 3096 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3097 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3098 | * value of 0 means the call was successful. Any other |
| 3099 | * nonzero value is a failure, but if ERESTART is returned, |
| 3100 | * the driver may reset the HBA and try again. |
| 3101 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3102 | rc = lpfc_config_port_prep(phba); |
| 3103 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3104 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3106 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | lpfc_config_port(phba, pmb); |
| 3110 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3111 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3112 | LPFC_SLI3_HBQ_ENABLED | |
| 3113 | LPFC_SLI3_CRP_ENABLED | |
| 3114 | LPFC_SLI3_INB_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3115 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3117 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3118 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3119 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3120 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3122 | spin_unlock_irq(&phba->hbalock); |
| 3123 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3124 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3125 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3126 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3127 | if (!done) { |
| 3128 | rc = -EINVAL; |
| 3129 | goto do_prep_failed; |
| 3130 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3131 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3132 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3133 | rc = -ENXIO; |
| 3134 | goto do_prep_failed; |
| 3135 | } |
| 3136 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3137 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3138 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3139 | } else |
| 3140 | phba->max_vpi = 0; |
| 3141 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3142 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3143 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3144 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3145 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3146 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame^] | 3147 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3148 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3149 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3150 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3151 | phba->inb_last_counter = |
| 3152 | phba->mbox->us.s3_inb_pgp.counter; |
| 3153 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame^] | 3154 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3155 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3156 | phba->inb_ha_copy = NULL; |
| 3157 | phba->inb_counter = NULL; |
| 3158 | } |
| 3159 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame^] | 3160 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3161 | phba->port_gp = phba->mbox->us.s2.port; |
| 3162 | phba->inb_ha_copy = NULL; |
| 3163 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3164 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3165 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3166 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3167 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3168 | return rc; |
| 3169 | } |
| 3170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | |
| 3172 | /** |
| 3173 | * lpfc_sli_hba_setup: SLI intialization function. |
| 3174 | * @phba: Pointer to HBA context object. |
| 3175 | * |
| 3176 | * This function is the main SLI intialization function. This function |
| 3177 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3178 | * error attention handler code. Caller is not required to hold any |
| 3179 | * locks. This function issues config_port mailbox command to configure |
| 3180 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3181 | * calls the config_port_post function to issue init_link mailbox |
| 3182 | * command and to start the discovery. The function will return zero |
| 3183 | * if successful, else it will return negative error code. |
| 3184 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3185 | int |
| 3186 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3187 | { |
| 3188 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3189 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3190 | |
| 3191 | switch (lpfc_sli_mode) { |
| 3192 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3193 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3194 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3195 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3196 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3197 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3198 | break; |
| 3199 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3200 | mode = 2; |
| 3201 | break; |
| 3202 | case 0: |
| 3203 | case 3: |
| 3204 | break; |
| 3205 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3207 | "1819 Unrecognized lpfc_sli_mode " |
| 3208 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3209 | |
| 3210 | break; |
| 3211 | } |
| 3212 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3213 | rc = lpfc_sli_config_port(phba, mode); |
| 3214 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3215 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3217 | "1820 Unable to select SLI-3. " |
| 3218 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3219 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3220 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3221 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | goto lpfc_sli_hba_setup_error; |
| 3223 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3224 | if (phba->sli_rev == 3) { |
| 3225 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3226 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3227 | } else { |
| 3228 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3229 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3230 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3234 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3235 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3236 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | |
| 3238 | if (rc) |
| 3239 | goto lpfc_sli_hba_setup_error; |
| 3240 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3241 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3242 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3243 | rc = lpfc_sli_hbq_setup(phba); |
| 3244 | if (rc) |
| 3245 | goto lpfc_sli_hba_setup_error; |
| 3246 | } |
| 3247 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3249 | |
| 3250 | rc = lpfc_config_port_post(phba); |
| 3251 | if (rc) |
| 3252 | goto lpfc_sli_hba_setup_error; |
| 3253 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3254 | return rc; |
| 3255 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3256 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3257 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3258 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3259 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | return rc; |
| 3261 | } |
| 3262 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3263 | |
| 3264 | /** |
| 3265 | * lpfc_mbox_timeout: Timeout call back function for mbox timer. |
| 3266 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3268 | * This is the callback function for mailbox timer. The mailbox |
| 3269 | * timer is armed when a new mailbox command is issued and the timer |
| 3270 | * is deleted when the mailbox complete. The function is called by |
| 3271 | * the kernel timer code when a mailbox does not complete within |
| 3272 | * expected time. This function wakes up the worker thread to |
| 3273 | * process the mailbox timeout and returns. All the processing is |
| 3274 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3275 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | void |
| 3277 | lpfc_mbox_timeout(unsigned long ptr) |
| 3278 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3279 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3281 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3284 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | if (!tmo_posted) |
| 3286 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3287 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3288 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3289 | if (!tmo_posted) |
| 3290 | lpfc_worker_wake_up(phba); |
| 3291 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | } |
| 3293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3294 | |
| 3295 | /** |
| 3296 | * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout. |
| 3297 | * @phba: Pointer to HBA context object. |
| 3298 | * |
| 3299 | * This function is called from worker thread when a mailbox command times out. |
| 3300 | * The caller is not required to hold any locks. This function will reset the |
| 3301 | * HBA and recover all the pending commands. |
| 3302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | void |
| 3304 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3305 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3306 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3307 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3308 | struct lpfc_sli *psli = &phba->sli; |
| 3309 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3311 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | return; |
| 3313 | } |
| 3314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3316 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3317 | "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] | 3318 | mb->mbxCommand, |
| 3319 | phba->pport->port_state, |
| 3320 | phba->sli.sli_flag, |
| 3321 | phba->sli.mbox_active); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3323 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3324 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3325 | * it to fail all oustanding SCSI IO. |
| 3326 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3327 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3328 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3329 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3330 | spin_lock_irq(&phba->hbalock); |
| 3331 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3332 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3333 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3334 | |
| 3335 | pring = &psli->ring[psli->fcp_ring]; |
| 3336 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3337 | |
| 3338 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3339 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3340 | /* |
| 3341 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 3342 | * on oustanding mailbox commands. |
| 3343 | */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3344 | /* If resets are disabled then set error state and return. */ |
| 3345 | if (!phba->cfg_enable_hba_reset) { |
| 3346 | phba->link_state = LPFC_HBA_ERROR; |
| 3347 | return; |
| 3348 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3349 | lpfc_offline_prep(phba); |
| 3350 | lpfc_offline(phba); |
| 3351 | lpfc_sli_brdrestart(phba); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3352 | lpfc_online(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3353 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | return; |
| 3355 | } |
| 3356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3357 | /** |
| 3358 | * lpfc_sli_issue_mbox: Issue a mailbox command to firmware. |
| 3359 | * @phba: Pointer to HBA context object. |
| 3360 | * @pmbox: Pointer to mailbox object. |
| 3361 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3362 | * |
| 3363 | * This function is called by discovery code and HBA management code |
| 3364 | * to submit a mailbox command to firmware. This function gets the |
| 3365 | * hbalock to protect the data structures. |
| 3366 | * The mailbox command can be submitted in polling mode, in which case |
| 3367 | * this function will wait in a polling loop for the completion of the |
| 3368 | * mailbox. |
| 3369 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3370 | * function will submit the command and returns immediately without waiting |
| 3371 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3372 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3373 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3374 | * mailbox is issued in polling mode and there is already a mailbox |
| 3375 | * pending, then the function will return an error. If the mailbox is issued |
| 3376 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3377 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3378 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3379 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3380 | * return codes the caller owns the mailbox command after the return of |
| 3381 | * the function. |
| 3382 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | 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] | 3385 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3387 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | uint32_t status, evtctr; |
| 3389 | uint32_t ha_copy; |
| 3390 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3391 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3393 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3395 | int processing_queue = 0; |
| 3396 | |
| 3397 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3398 | if (!pmbox) { |
| 3399 | /* processing mbox queue from intr_handler */ |
| 3400 | processing_queue = 1; |
| 3401 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3402 | pmbox = lpfc_mbox_get(phba); |
| 3403 | if (!pmbox) { |
| 3404 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3405 | return MBX_SUCCESS; |
| 3406 | } |
| 3407 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3409 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3410 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3411 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3412 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3413 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3414 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3415 | "1806 Mbox x%x failed. No vport\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3416 | pmbox->mb.mbxCommand); |
| 3417 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3418 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3419 | } |
| 3420 | } |
| 3421 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3422 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3423 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3424 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3425 | goto out_not_finished; |
| 3426 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3429 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | mb = &pmbox->mb; |
| 3431 | status = MBX_SUCCESS; |
| 3432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3433 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3434 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3435 | |
| 3436 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3437 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3438 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3439 | } |
| 3440 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3441 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3442 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3444 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3445 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3446 | } |
| 3447 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3449 | /* Polling for a mbox command when another one is already active |
| 3450 | * is not allowed in SLI. Also, the driver must have established |
| 3451 | * SLI2 mode to queue and process multiple mbox commands. |
| 3452 | */ |
| 3453 | |
| 3454 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3455 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | |
| 3457 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3458 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3459 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3463 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3464 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3465 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3466 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | } |
| 3468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | /* Another mailbox command is still being processed, queue this |
| 3470 | * command to be processed later. |
| 3471 | */ |
| 3472 | lpfc_mbox_put(phba, pmbox); |
| 3473 | |
| 3474 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3475 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3476 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3477 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3479 | mb->mbxCommand, phba->pport->port_state, |
| 3480 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | |
| 3482 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3483 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3485 | if (pmbox->vport) { |
| 3486 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3487 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3488 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3489 | (uint32_t)mb->mbxCommand, |
| 3490 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3491 | } |
| 3492 | else { |
| 3493 | lpfc_debugfs_disc_trc(phba->pport, |
| 3494 | LPFC_DISC_TRC_MBOX, |
| 3495 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3496 | (uint32_t)mb->mbxCommand, |
| 3497 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3498 | } |
| 3499 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3500 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | } |
| 3502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3504 | |
| 3505 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3506 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3507 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 3508 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3510 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3511 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3512 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3513 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | } |
| 3515 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3516 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3517 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3521 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3522 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3523 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3524 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3525 | mb->mbxCommand, phba->pport->port_state, |
| 3526 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3527 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3528 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3529 | if (pmbox->vport) { |
| 3530 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3531 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3532 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3533 | (uint32_t)mb->mbxCommand, |
| 3534 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3535 | } |
| 3536 | else { |
| 3537 | lpfc_debugfs_disc_trc(phba->pport, |
| 3538 | LPFC_DISC_TRC_MBOX, |
| 3539 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3540 | (uint32_t)mb->mbxCommand, |
| 3541 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | psli->slistat.mbox_cmd++; |
| 3546 | evtctr = psli->slistat.mbox_event; |
| 3547 | |
| 3548 | /* next set own bit for the adapter and copy over command word */ |
| 3549 | mb->mbxOwner = OWN_CHIP; |
| 3550 | |
| 3551 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3553 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3555 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3557 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3561 | word */ |
| 3562 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3563 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3564 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3565 | |
| 3566 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3567 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | to_slim = phba->MBslimaddr; |
| 3569 | writel(ldata, to_slim); |
| 3570 | readl(to_slim); /* flush */ |
| 3571 | |
| 3572 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3573 | /* switch over to host mailbox */ |
| 3574 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | |
| 3580 | switch (flag) { |
| 3581 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3582 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3584 | /* Interrupt board to do it */ |
| 3585 | writel(CA_MBATT, phba->CAregaddr); |
| 3586 | readl(phba->CAregaddr); /* flush */ |
| 3587 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | break; |
| 3589 | |
| 3590 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3591 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3593 | /* Interrupt board to do it */ |
| 3594 | writel(CA_MBATT, phba->CAregaddr); |
| 3595 | readl(phba->CAregaddr); /* flush */ |
| 3596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3598 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3599 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3600 | word0 = le32_to_cpu(word0); |
| 3601 | } else { |
| 3602 | /* First read mbox status word */ |
| 3603 | word0 = readl(phba->MBslimaddr); |
| 3604 | } |
| 3605 | |
| 3606 | /* Read the HBA Host Attention Register */ |
| 3607 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3608 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3609 | mb->mbxCommand) * |
| 3610 | 1000) + jiffies; |
| 3611 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3612 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3613 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3614 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3615 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3616 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3617 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3618 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3620 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | /* Check if we took a mbox interrupt while we were |
| 3624 | polling */ |
| 3625 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3626 | && (evtctr != psli->slistat.mbox_event)) |
| 3627 | break; |
| 3628 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3629 | if (i++ > 10) { |
| 3630 | spin_unlock_irqrestore(&phba->hbalock, |
| 3631 | drvr_flag); |
| 3632 | msleep(1); |
| 3633 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | |
| 3636 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3637 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3638 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | word0 = le32_to_cpu(word0); |
| 3640 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3641 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3642 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | /* Check real SLIM for any errors */ |
| 3644 | slimword0 = readl(phba->MBslimaddr); |
| 3645 | slimmb = (MAILBOX_t *) & slimword0; |
| 3646 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3647 | && slimmb->mbxStatus) { |
| 3648 | psli->sli_flag &= |
| 3649 | ~LPFC_SLI2_ACTIVE; |
| 3650 | word0 = slimword0; |
| 3651 | } |
| 3652 | } |
| 3653 | } else { |
| 3654 | /* First copy command data */ |
| 3655 | word0 = readl(phba->MBslimaddr); |
| 3656 | } |
| 3657 | /* Read the HBA Host Attention Register */ |
| 3658 | ha_copy = readl(phba->HAregaddr); |
| 3659 | } |
| 3660 | |
| 3661 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3663 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | } else { |
| 3665 | /* First copy command data */ |
| 3666 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3667 | MAILBOX_CMD_SIZE); |
| 3668 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3669 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3670 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3672 | mb->un.varDmp.word_cnt); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | writel(HA_MBATT, phba->HAregaddr); |
| 3677 | readl(phba->HAregaddr); /* flush */ |
| 3678 | |
| 3679 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3680 | status = mb->mbxStatus; |
| 3681 | } |
| 3682 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3683 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3684 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3685 | |
| 3686 | out_not_finished: |
| 3687 | if (processing_queue) { |
| 3688 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3689 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3690 | } |
| 3691 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | } |
| 3693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3694 | /** |
| 3695 | * __lpfc_sli_ringtx_put: Add an iocb to the txq. |
| 3696 | * @phba: Pointer to HBA context object. |
| 3697 | * @pring: Pointer to driver SLI ring object. |
| 3698 | * @piocb: Pointer to address of newly added command iocb. |
| 3699 | * |
| 3700 | * This function is called with hbalock held to add a command |
| 3701 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3702 | * to the ring. |
| 3703 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3704 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3705 | __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] | 3706 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3707 | { |
| 3708 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3709 | list_add_tail(&piocb->list, &pring->txq); |
| 3710 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | } |
| 3712 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3713 | /** |
| 3714 | * lpfc_sli_next_iocb: Get the next iocb in the txq. |
| 3715 | * @phba: Pointer to HBA context object. |
| 3716 | * @pring: Pointer to driver SLI ring object. |
| 3717 | * @piocb: Pointer to address of newly added command iocb. |
| 3718 | * |
| 3719 | * This function is called with hbalock held before a new |
| 3720 | * iocb is submitted to the firmware. This function checks |
| 3721 | * txq to flush the iocbs in txq to Firmware before |
| 3722 | * submitting new iocbs to the Firmware. |
| 3723 | * If there are iocbs in the txq which need to be submitted |
| 3724 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3725 | * of the txq after dequeuing it from txq. |
| 3726 | * If there is no iocb in the txq then the function will return |
| 3727 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3728 | * *piocb to find if there are more commands in the txq. |
| 3729 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | static struct lpfc_iocbq * |
| 3731 | 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] | 3732 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | { |
| 3734 | struct lpfc_iocbq * nextiocb; |
| 3735 | |
| 3736 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3737 | if (!nextiocb) { |
| 3738 | nextiocb = *piocb; |
| 3739 | *piocb = NULL; |
| 3740 | } |
| 3741 | |
| 3742 | return nextiocb; |
| 3743 | } |
| 3744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3745 | /** |
| 3746 | * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb. |
| 3747 | * @phba: Pointer to HBA context object. |
| 3748 | * @pring: Pointer to driver SLI ring object. |
| 3749 | * @piocb: Pointer to command iocb. |
| 3750 | * @flag: Flag indicating if this command can be put into txq. |
| 3751 | * |
| 3752 | * __lpfc_sli_issue_iocb is used by other functions in the driver |
| 3753 | * to issue an iocb command to the HBA. If the PCI slot is recovering |
| 3754 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3755 | * flag is turned on, the function returns IOCB_ERROR. |
| 3756 | * When the link is down, this function allows only iocbs for |
| 3757 | * posting buffers. |
| 3758 | * This function finds next available slot in the command ring and |
| 3759 | * posts the command to the available slot and writes the port |
| 3760 | * attention register to request HBA start processing new iocb. |
| 3761 | * If there is no slot available in the ring and |
| 3762 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the |
| 3763 | * txq, otherwise the function returns IOCB_BUSY. |
| 3764 | * |
| 3765 | * This function is called with hbalock held. |
| 3766 | * The function will return success after it successfully submit the |
| 3767 | * iocb to firmware or after adding to the txq. |
| 3768 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3769 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3770 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3772 | { |
| 3773 | struct lpfc_iocbq *nextiocb; |
| 3774 | IOCB_t *iocb; |
| 3775 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3776 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3777 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3778 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3779 | lpfc_printf_log(phba, KERN_ERR, |
| 3780 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3781 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3782 | piocb->iocb.ulpCommand); |
| 3783 | dump_stack(); |
| 3784 | return IOCB_ERROR; |
| 3785 | } |
| 3786 | |
| 3787 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3788 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3789 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3790 | return IOCB_ERROR; |
| 3791 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | /* |
| 3793 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3794 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3795 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | return IOCB_ERROR; |
| 3797 | |
| 3798 | /* |
| 3799 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3800 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3802 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | goto iocb_busy; |
| 3804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3805 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3807 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | * can be issued if the link is not up. |
| 3809 | */ |
| 3810 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3811 | case CMD_GEN_REQUEST64_CR: |
| 3812 | case CMD_GEN_REQUEST64_CX: |
| 3813 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 3814 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 3815 | FC_FCP_CMND) || |
| 3816 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 3817 | MENLO_TRANSPORT_TYPE)) |
| 3818 | |
| 3819 | goto iocb_busy; |
| 3820 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | case CMD_QUE_RING_BUF_CN: |
| 3822 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | /* |
| 3824 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3825 | * completion, iocb_cmpl MUST be 0. |
| 3826 | */ |
| 3827 | if (piocb->iocb_cmpl) |
| 3828 | piocb->iocb_cmpl = NULL; |
| 3829 | /*FALLTHROUGH*/ |
| 3830 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3831 | case CMD_CLOSE_XRI_CN: |
| 3832 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | break; |
| 3834 | default: |
| 3835 | goto iocb_busy; |
| 3836 | } |
| 3837 | |
| 3838 | /* |
| 3839 | * For FCP commands, we must be in a state where we can process link |
| 3840 | * attention events. |
| 3841 | */ |
| 3842 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3843 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3848 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3849 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3850 | |
| 3851 | if (iocb) |
| 3852 | lpfc_sli_update_ring(phba, pring); |
| 3853 | else |
| 3854 | lpfc_sli_update_full_ring(phba, pring); |
| 3855 | |
| 3856 | if (!piocb) |
| 3857 | return IOCB_SUCCESS; |
| 3858 | |
| 3859 | goto out_busy; |
| 3860 | |
| 3861 | iocb_busy: |
| 3862 | pring->stats.iocb_cmd_delay++; |
| 3863 | |
| 3864 | out_busy: |
| 3865 | |
| 3866 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3867 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | return IOCB_SUCCESS; |
| 3869 | } |
| 3870 | |
| 3871 | return IOCB_BUSY; |
| 3872 | } |
| 3873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3875 | /** |
| 3876 | * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb. |
| 3877 | * @phba: Pointer to HBA context object. |
| 3878 | * @pring: Pointer to driver SLI ring object. |
| 3879 | * @piocb: Pointer to command iocb. |
| 3880 | * @flag: Flag indicating if this command can be put into txq. |
| 3881 | * |
| 3882 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 3883 | * function. This function gets the hbalock and calls |
| 3884 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 3885 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 3886 | * functions which do not hold hbalock. |
| 3887 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3888 | int |
| 3889 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3890 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3891 | { |
| 3892 | unsigned long iflags; |
| 3893 | int rc; |
| 3894 | |
| 3895 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 3896 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 3897 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 3898 | |
| 3899 | return rc; |
| 3900 | } |
| 3901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3902 | /** |
| 3903 | * lpfc_extra_ring_setup: Extra ring setup function. |
| 3904 | * @phba: Pointer to HBA context object. |
| 3905 | * |
| 3906 | * This function is called while driver attaches with the |
| 3907 | * HBA to setup the extra ring. The extra ring is used |
| 3908 | * only when driver needs to support target mode functionality |
| 3909 | * or IP over FC functionalities. |
| 3910 | * |
| 3911 | * This function is called with no lock held. |
| 3912 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3913 | static int |
| 3914 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 3915 | { |
| 3916 | struct lpfc_sli *psli; |
| 3917 | struct lpfc_sli_ring *pring; |
| 3918 | |
| 3919 | psli = &phba->sli; |
| 3920 | |
| 3921 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3922 | |
| 3923 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3924 | pring = &psli->ring[psli->fcp_ring]; |
| 3925 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3926 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3927 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3928 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3929 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3930 | /* and give them to the extra ring */ |
| 3931 | pring = &psli->ring[psli->extra_ring]; |
| 3932 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3933 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3934 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3935 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3936 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3937 | |
| 3938 | /* Setup default profile for this ring */ |
| 3939 | pring->iotag_max = 4096; |
| 3940 | pring->num_mask = 1; |
| 3941 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3942 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 3943 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3944 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 3945 | return 0; |
| 3946 | } |
| 3947 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3948 | /** |
| 3949 | * lpfc_sli_async_event_handler: ASYNC iocb handler function. |
| 3950 | * @phba: Pointer to HBA context object. |
| 3951 | * @pring: Pointer to driver SLI ring object. |
| 3952 | * @iocbq: Pointer to iocb object. |
| 3953 | * |
| 3954 | * This function is called by the slow ring event handler |
| 3955 | * function when there is an ASYNC event iocb in the ring. |
| 3956 | * This function is called with no lock held. |
| 3957 | * Currently this function handles only temperature related |
| 3958 | * ASYNC events. The function decodes the temperature sensor |
| 3959 | * event message and posts events for the management applications. |
| 3960 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3961 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3962 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 3963 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 3964 | { |
| 3965 | IOCB_t *icmd; |
| 3966 | uint16_t evt_code; |
| 3967 | uint16_t temp; |
| 3968 | struct temp_event temp_event_data; |
| 3969 | struct Scsi_Host *shost; |
| 3970 | |
| 3971 | icmd = &iocbq->iocb; |
| 3972 | evt_code = icmd->un.asyncstat.evt_code; |
| 3973 | temp = icmd->ulpContext; |
| 3974 | |
| 3975 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 3976 | (evt_code != ASYNC_TEMP_SAFE)) { |
| 3977 | lpfc_printf_log(phba, |
| 3978 | KERN_ERR, |
| 3979 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3980 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3981 | " evt_code 0x%x\n", |
| 3982 | pring->ringno, |
| 3983 | icmd->un.asyncstat.evt_code); |
| 3984 | return; |
| 3985 | } |
| 3986 | temp_event_data.data = (uint32_t)temp; |
| 3987 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 3988 | if (evt_code == ASYNC_TEMP_WARN) { |
| 3989 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 3990 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3991 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3992 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3993 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3994 | "corrective action. temperature : %d Celsius\n", |
| 3995 | temp); |
| 3996 | } |
| 3997 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 3998 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 3999 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4000 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4001 | LOG_TEMP, |
| 4002 | "0340 Adapter temperature is OK now. " |
| 4003 | "temperature : %d Celsius\n", |
| 4004 | temp); |
| 4005 | } |
| 4006 | |
| 4007 | /* Send temperature change event to applications */ |
| 4008 | shost = lpfc_shost_from_vport(phba->pport); |
| 4009 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4010 | sizeof(temp_event_data), (char *) &temp_event_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4011 | LPFC_NL_VENDOR_ID); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4012 | |
| 4013 | } |
| 4014 | |
| 4015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4016 | /** |
| 4017 | * lpfc_sli_setup: SLI ring setup function. |
| 4018 | * @phba: Pointer to HBA context object. |
| 4019 | * |
| 4020 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 4021 | * number of iocbs per ring and iotags. This function is |
| 4022 | * called while driver attach to the HBA and before the |
| 4023 | * interrupts are enabled. So there is no need for locking. |
| 4024 | * |
| 4025 | * This function always returns 0. |
| 4026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | int |
| 4028 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 4029 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4030 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4031 | struct lpfc_sli *psli = &phba->sli; |
| 4032 | struct lpfc_sli_ring *pring; |
| 4033 | |
| 4034 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 4035 | psli->sli_flag = 0; |
| 4036 | psli->fcp_ring = LPFC_FCP_RING; |
| 4037 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4038 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4040 | psli->iocbq_lookup = NULL; |
| 4041 | psli->iocbq_lookup_len = 0; |
| 4042 | psli->last_iotag = 0; |
| 4043 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | for (i = 0; i < psli->num_rings; i++) { |
| 4045 | pring = &psli->ring[i]; |
| 4046 | switch (i) { |
| 4047 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 4048 | /* numCiocb and numRiocb are used in config_port */ |
| 4049 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 4050 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 4051 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4052 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4053 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4054 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4055 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4056 | SLI3_IOCB_CMD_SIZE : |
| 4057 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4058 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4059 | SLI3_IOCB_RSP_SIZE : |
| 4060 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 | pring->iotag_ctr = 0; |
| 4062 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4063 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | pring->fast_iotag = pring->iotag_max; |
| 4065 | pring->num_mask = 0; |
| 4066 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4067 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | /* numCiocb and numRiocb are used in config_port */ |
| 4069 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 4070 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4071 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4072 | SLI3_IOCB_CMD_SIZE : |
| 4073 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4074 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | SLI3_IOCB_RSP_SIZE : |
| 4076 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | pring->num_mask = 0; |
| 4079 | break; |
| 4080 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 4081 | /* numCiocb and numRiocb are used in config_port */ |
| 4082 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 4083 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4084 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4085 | SLI3_IOCB_CMD_SIZE : |
| 4086 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4087 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4088 | SLI3_IOCB_RSP_SIZE : |
| 4089 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | pring->fast_iotag = 0; |
| 4091 | pring->iotag_ctr = 0; |
| 4092 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4093 | pring->lpfc_sli_rcv_async_status = |
| 4094 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | pring->num_mask = 4; |
| 4096 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 4097 | pring->prt[0].rctl = FC_ELS_REQ; |
| 4098 | pring->prt[0].type = FC_ELS_DATA; |
| 4099 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4100 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 4102 | pring->prt[1].rctl = FC_ELS_RSP; |
| 4103 | pring->prt[1].type = FC_ELS_DATA; |
| 4104 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4105 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 4107 | /* NameServer Inquiry */ |
| 4108 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 4109 | /* NameServer */ |
| 4110 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 4111 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4112 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 4114 | /* NameServer response */ |
| 4115 | pring->prt[3].rctl = FC_SOL_CTL; |
| 4116 | /* NameServer */ |
| 4117 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 4118 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4119 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | break; |
| 4121 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4122 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4123 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4125 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4127 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 4128 | "SLI2 SLIM Data: x%x x%lx\n", |
| 4129 | phba->brd_no, totiocbsize, |
| 4130 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4132 | if (phba->cfg_multi_ring_support == 2) |
| 4133 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | |
| 4135 | return 0; |
| 4136 | } |
| 4137 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4138 | /** |
| 4139 | * lpfc_sli_queue_setup: Queue initialization function. |
| 4140 | * @phba: Pointer to HBA context object. |
| 4141 | * |
| 4142 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4143 | * ring. This function also initializes ring indices of each ring. |
| 4144 | * This function is called during the initialization of the SLI |
| 4145 | * interface of an HBA. |
| 4146 | * This function is called with no lock held and always returns |
| 4147 | * 1. |
| 4148 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | { |
| 4152 | struct lpfc_sli *psli; |
| 4153 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4154 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | |
| 4156 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4159 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4161 | for (i = 0; i < psli->num_rings; i++) { |
| 4162 | pring = &psli->ring[i]; |
| 4163 | pring->ringno = i; |
| 4164 | pring->next_cmdidx = 0; |
| 4165 | pring->local_getidx = 0; |
| 4166 | pring->cmdidx = 0; |
| 4167 | INIT_LIST_HEAD(&pring->txq); |
| 4168 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4169 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4170 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | spin_unlock_irq(&phba->hbalock); |
| 4174 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | } |
| 4176 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4177 | /** |
| 4178 | * lpfc_sli_host_down: Vport cleanup function. |
| 4179 | * @vport: Pointer to virtual port object. |
| 4180 | * |
| 4181 | * lpfc_sli_host_down is called to clean up the resources |
| 4182 | * associated with a vport before destroying virtual |
| 4183 | * port data structures. |
| 4184 | * This function does following operations: |
| 4185 | * - Free discovery resources associated with this virtual |
| 4186 | * port. |
| 4187 | * - Free iocbs associated with this virtual port in |
| 4188 | * the txq. |
| 4189 | * - Send abort for all iocb commands associated with this |
| 4190 | * vport in txcmplq. |
| 4191 | * |
| 4192 | * This function is called with no lock held and always returns 1. |
| 4193 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4195 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4196 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4197 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4198 | struct lpfc_hba *phba = vport->phba; |
| 4199 | struct lpfc_sli *psli = &phba->sli; |
| 4200 | struct lpfc_sli_ring *pring; |
| 4201 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4202 | int i; |
| 4203 | unsigned long flags = 0; |
| 4204 | uint16_t prev_pring_flag; |
| 4205 | |
| 4206 | lpfc_cleanup_discovery_resources(vport); |
| 4207 | |
| 4208 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4209 | for (i = 0; i < psli->num_rings; i++) { |
| 4210 | pring = &psli->ring[i]; |
| 4211 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4212 | /* Only slow rings */ |
| 4213 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4214 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4215 | /* Set the lpfc data pending flag */ |
| 4216 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4217 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4218 | /* |
| 4219 | * Error everything on the txq since these iocbs have not been |
| 4220 | * given to the FW yet. |
| 4221 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4222 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4223 | if (iocb->vport != vport) |
| 4224 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4225 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4226 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | /* Next issue ABTS for everything on the txcmplq */ |
| 4230 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4231 | list) { |
| 4232 | if (iocb->vport != vport) |
| 4233 | continue; |
| 4234 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4235 | } |
| 4236 | |
| 4237 | pring->flag = prev_pring_flag; |
| 4238 | } |
| 4239 | |
| 4240 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4241 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4242 | while (!list_empty(&completions)) { |
| 4243 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
| 4244 | |
| 4245 | if (!iocb->iocb_cmpl) |
| 4246 | lpfc_sli_release_iocbq(phba, iocb); |
| 4247 | else { |
| 4248 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4249 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4250 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 4251 | } |
| 4252 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4253 | return 1; |
| 4254 | } |
| 4255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4256 | /** |
| 4257 | * lpfc_sli_hba_down: Resource cleanup function for the HBA. |
| 4258 | * @phba: Pointer to HBA context object. |
| 4259 | * |
| 4260 | * This function cleans up all iocb, buffers, mailbox commands |
| 4261 | * while shutting down the HBA. This function is called with no |
| 4262 | * lock held and always returns 1. |
| 4263 | * This function does the following to cleanup driver resources: |
| 4264 | * - Free discovery resources for each virtual port |
| 4265 | * - Cleanup any pending fabric iocbs |
| 4266 | * - Iterate through the iocb txq and free each entry |
| 4267 | * in the list. |
| 4268 | * - Free up any buffer posted to the HBA |
| 4269 | * - Free mailbox commands in the mailbox queue. |
| 4270 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4271 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4274 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4275 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4277 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | LPFC_MBOXQ_t *pmb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4279 | struct lpfc_iocbq *iocb; |
| 4280 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | int i; |
| 4282 | unsigned long flags = 0; |
| 4283 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | lpfc_hba_down_prep(phba); |
| 4285 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4286 | lpfc_fabric_abort_hba(phba); |
| 4287 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | for (i = 0; i < psli->num_rings; i++) { |
| 4290 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4291 | /* Only slow rings */ |
| 4292 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4293 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4294 | /* Set the lpfc data pending flag */ |
| 4295 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4296 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | |
| 4298 | /* |
| 4299 | * Error everything on the txq since these iocbs have not been |
| 4300 | * given to the FW yet. |
| 4301 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4302 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | pring->txq_cnt = 0; |
| 4304 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4308 | while (!list_empty(&completions)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4309 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4310 | cmd = &iocb->iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4311 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4312 | if (!iocb->iocb_cmpl) |
| 4313 | lpfc_sli_release_iocbq(phba, iocb); |
| 4314 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4315 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4316 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4317 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4319 | } |
| 4320 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4321 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4322 | list_splice_init(&phba->elsbuf, &completions); |
| 4323 | phba->elsbuf_cnt = 0; |
| 4324 | phba->elsbuf_prev_cnt = 0; |
| 4325 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4326 | |
| 4327 | while (!list_empty(&completions)) { |
| 4328 | list_remove_head(&completions, buf_ptr, |
| 4329 | struct lpfc_dmabuf, list); |
| 4330 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4331 | kfree(buf_ptr); |
| 4332 | } |
| 4333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | /* Return any active mbox cmds */ |
| 4335 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4336 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4337 | |
| 4338 | spin_lock(&phba->pport->work_port_lock); |
| 4339 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4340 | spin_unlock(&phba->pport->work_port_lock); |
| 4341 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4342 | /* Return any pending or completed mbox cmds */ |
| 4343 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4344 | if (psli->mbox_active) { |
| 4345 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4346 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4349 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4350 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4351 | |
| 4352 | while (!list_empty(&completions)) { |
| 4353 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4355 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | return 1; |
| 4359 | } |
| 4360 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4361 | /** |
| 4362 | * lpfc_sli_pcimem_bcopy: SLI memory copy function. |
| 4363 | * @srcp: Source memory pointer. |
| 4364 | * @destp: Destination memory pointer. |
| 4365 | * @cnt: Number of words required to be copied. |
| 4366 | * |
| 4367 | * This function is used for copying data between driver memory |
| 4368 | * and the SLI memory. This function also changes the endianness |
| 4369 | * of each word if native endianness is different from SLI |
| 4370 | * endianness. This function can be called with or without |
| 4371 | * lock. |
| 4372 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | void |
| 4374 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4375 | { |
| 4376 | uint32_t *src = srcp; |
| 4377 | uint32_t *dest = destp; |
| 4378 | uint32_t ldata; |
| 4379 | int i; |
| 4380 | |
| 4381 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4382 | ldata = *src; |
| 4383 | ldata = le32_to_cpu(ldata); |
| 4384 | *dest = ldata; |
| 4385 | src++; |
| 4386 | dest++; |
| 4387 | } |
| 4388 | } |
| 4389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4390 | |
| 4391 | /** |
| 4392 | * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq. |
| 4393 | * @phba: Pointer to HBA context object. |
| 4394 | * @pring: Pointer to driver SLI ring object. |
| 4395 | * @mp: Pointer to driver buffer object. |
| 4396 | * |
| 4397 | * This function is called with no lock held. |
| 4398 | * It always return zero after adding the buffer to the postbufq |
| 4399 | * buffer list. |
| 4400 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4402 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4403 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | { |
| 4405 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4406 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4407 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4408 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | return 0; |
| 4412 | } |
| 4413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | /** |
| 4415 | * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted |
| 4416 | * using CMD_QUE_XRI64_CX iocb. |
| 4417 | * @phba: Pointer to HBA context object. |
| 4418 | * |
| 4419 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4420 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4421 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4422 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4423 | * The function returns the allocated tag. The function is called with |
| 4424 | * no locks held. |
| 4425 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4426 | uint32_t |
| 4427 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4428 | { |
| 4429 | spin_lock_irq(&phba->hbalock); |
| 4430 | phba->buffer_tag_count++; |
| 4431 | /* |
| 4432 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4433 | * a tag assigned by HBQ. |
| 4434 | */ |
| 4435 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4436 | spin_unlock_irq(&phba->hbalock); |
| 4437 | return phba->buffer_tag_count; |
| 4438 | } |
| 4439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4440 | /** |
| 4441 | * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with |
| 4442 | * posted using CMD_QUE_XRI64_CX iocb. |
| 4443 | * @phba: Pointer to HBA context object. |
| 4444 | * @pring: Pointer to driver SLI ring object. |
| 4445 | * @tag: Buffer tag. |
| 4446 | * |
| 4447 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4448 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4449 | * iocb is posted to the response ring with the tag of the buffer. |
| 4450 | * This function searches the pring->postbufq list using the tag |
| 4451 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4452 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4453 | * buffer is returned to the caller else NULL is returned. |
| 4454 | * This function is called with no lock held. |
| 4455 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4456 | struct lpfc_dmabuf * |
| 4457 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4458 | uint32_t tag) |
| 4459 | { |
| 4460 | struct lpfc_dmabuf *mp, *next_mp; |
| 4461 | struct list_head *slp = &pring->postbufq; |
| 4462 | |
| 4463 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4464 | spin_lock_irq(&phba->hbalock); |
| 4465 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4466 | if (mp->buffer_tag == tag) { |
| 4467 | list_del_init(&mp->list); |
| 4468 | pring->postbufq_cnt--; |
| 4469 | spin_unlock_irq(&phba->hbalock); |
| 4470 | return mp; |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | spin_unlock_irq(&phba->hbalock); |
| 4475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4476 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4477 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4478 | pring->ringno, (unsigned long) tag, |
| 4479 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4480 | |
| 4481 | return NULL; |
| 4482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4484 | /** |
| 4485 | * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for |
| 4486 | * unsolicited ct and els events. |
| 4487 | * @phba: Pointer to HBA context object. |
| 4488 | * @pring: Pointer to driver SLI ring object. |
| 4489 | * @phys: DMA address of the buffer. |
| 4490 | * |
| 4491 | * This function searches the buffer list using the dma_address |
| 4492 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4493 | * corresponding to the dma_address. The function returns the |
| 4494 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4495 | * This function is called by the ct and els unsolicited event |
| 4496 | * handlers to get the buffer associated with the unsolicited |
| 4497 | * event. |
| 4498 | * |
| 4499 | * This function is called with no lock held. |
| 4500 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | struct lpfc_dmabuf * |
| 4502 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4503 | dma_addr_t phys) |
| 4504 | { |
| 4505 | struct lpfc_dmabuf *mp, *next_mp; |
| 4506 | struct list_head *slp = &pring->postbufq; |
| 4507 | |
| 4508 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4509 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4511 | if (mp->phys == phys) { |
| 4512 | list_del_init(&mp->list); |
| 4513 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4515 | return mp; |
| 4516 | } |
| 4517 | } |
| 4518 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4521 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4523 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4525 | return NULL; |
| 4526 | } |
| 4527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4528 | /** |
| 4529 | * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs. |
| 4530 | * @phba: Pointer to HBA context object. |
| 4531 | * @cmdiocb: Pointer to driver command iocb object. |
| 4532 | * @rspiocb: Pointer to driver response iocb object. |
| 4533 | * |
| 4534 | * This function is the completion handler for the abort iocbs for |
| 4535 | * ELS commands. This function is called from the ELS ring event |
| 4536 | * handler with no lock held. This function frees memory resources |
| 4537 | * associated with the abort iocb. |
| 4538 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4541 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4544 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4545 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4546 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4547 | |
| 4548 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4549 | |
| 4550 | if (irsp->ulpStatus) { |
| 4551 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4552 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4553 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4555 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4556 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4557 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4558 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4559 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4560 | "with tag %x context %x, abort status %x, " |
| 4561 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4562 | abort_iocb, abort_iotag, abort_context, |
| 4563 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4564 | |
| 4565 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4566 | * If the iocb is not found in Firmware queue the iocb |
| 4567 | * might have completed already. Do not free it again. |
| 4568 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4569 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4570 | spin_unlock_irq(&phba->hbalock); |
| 4571 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4572 | return; |
| 4573 | } |
| 4574 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4575 | * make sure we have the right iocbq before taking it |
| 4576 | * off the txcmplq and try to call completion routine. |
| 4577 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4578 | if (!abort_iocb || |
| 4579 | abort_iocb->iocb.ulpContext != abort_context || |
| 4580 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4581 | spin_unlock_irq(&phba->hbalock); |
| 4582 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4583 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4584 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4586 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4587 | /* Firmware could still be in progress of DMAing |
| 4588 | * payload, so don't free data buffer till after |
| 4589 | * a hbeat. |
| 4590 | */ |
| 4591 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4592 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4593 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4594 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4595 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4596 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4600 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | return; |
| 4602 | } |
| 4603 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4604 | /** |
| 4605 | * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command. |
| 4606 | * @phba: Pointer to HBA context object. |
| 4607 | * @cmdiocb: Pointer to driver command iocb object. |
| 4608 | * @rspiocb: Pointer to driver response iocb object. |
| 4609 | * |
| 4610 | * The function is called from SLI ring event handler with no |
| 4611 | * lock held. This function is the completion handler for ELS commands |
| 4612 | * which are aborted. The function frees memory resources used for |
| 4613 | * the aborted ELS commands. |
| 4614 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4615 | static void |
| 4616 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4617 | struct lpfc_iocbq *rspiocb) |
| 4618 | { |
| 4619 | IOCB_t *irsp = &rspiocb->iocb; |
| 4620 | |
| 4621 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4622 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4623 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4624 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4625 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4626 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4627 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4628 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4629 | else |
| 4630 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4631 | return; |
| 4632 | } |
| 4633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4634 | /** |
| 4635 | * lpfc_sli_issue_abort_iotag: Abort function for a command iocb. |
| 4636 | * @phba: Pointer to HBA context object. |
| 4637 | * @pring: Pointer to driver SLI ring object. |
| 4638 | * @cmdiocb: Pointer to driver command iocb object. |
| 4639 | * |
| 4640 | * This function issues an abort iocb for the provided command |
| 4641 | * iocb. This function is called with hbalock held. |
| 4642 | * The function returns 0 when it fails due to memory allocation |
| 4643 | * failure or when the command iocb is an abort request. |
| 4644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4647 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4649 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4650 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | IOCB_t *icmd = NULL; |
| 4652 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4653 | int retval = IOCB_ERROR; |
| 4654 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4655 | /* |
| 4656 | * There are certain command types we don't want to abort. And we |
| 4657 | * don't want to abort commands that are already in the process of |
| 4658 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4659 | */ |
| 4660 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4661 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4662 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4663 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4664 | return 0; |
| 4665 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4666 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4667 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4668 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4669 | if ((vport->load_flag & FC_UNLOADING) && |
| 4670 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4671 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4672 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4673 | else |
| 4674 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4675 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4676 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4677 | |
| 4678 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4679 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | if (abtsiocbp == NULL) |
| 4681 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4682 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4683 | /* This signals the response to set the correct status |
| 4684 | * before calling the completion handler. |
| 4685 | */ |
| 4686 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4687 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4688 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4689 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4690 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4691 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4692 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4693 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4695 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4696 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4697 | else |
| 4698 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4699 | |
| 4700 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4701 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4702 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4703 | "0339 Abort xri x%x, original iotag x%x, " |
| 4704 | "abort cmd iotag x%x\n", |
| 4705 | iabt->un.acxri.abortContextTag, |
| 4706 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4707 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4708 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4709 | if (retval) |
| 4710 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4711 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4712 | /* |
| 4713 | * Caller to this routine should check for IOCB_ERROR |
| 4714 | * and handle it properly. This routine no longer removes |
| 4715 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4716 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | } |
| 4719 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4720 | /** |
| 4721 | * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands |
| 4722 | * associated with a vport/SCSI target/lun. |
| 4723 | * @iocbq: Pointer to driver iocb object. |
| 4724 | * @vport: Pointer to driver virtual port object. |
| 4725 | * @tgt_id: SCSI ID of the target. |
| 4726 | * @lun_id: LUN ID of the scsi device. |
| 4727 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4728 | * |
| 4729 | * This function acts as iocb filter for functions which abort or count |
| 4730 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4731 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4732 | * 1 if the filtering criteria is not met. |
| 4733 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4734 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4735 | * lun_id parameter. |
| 4736 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4737 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4738 | * parameters. |
| 4739 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4740 | * given iocb is for the SCSI host associated with the given vport. |
| 4741 | * This function is called with no locks held. |
| 4742 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4744 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4745 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4746 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4748 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | int rc = 1; |
| 4750 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4751 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4752 | return rc; |
| 4753 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4754 | if (iocbq->vport != vport) |
| 4755 | return rc; |
| 4756 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4757 | 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] | 4758 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4759 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | return rc; |
| 4761 | |
| 4762 | switch (ctx_cmd) { |
| 4763 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4764 | if ((lpfc_cmd->rdata->pnode) && |
| 4765 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4766 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | rc = 0; |
| 4768 | break; |
| 4769 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4770 | if ((lpfc_cmd->rdata->pnode) && |
| 4771 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4772 | rc = 0; |
| 4773 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | case LPFC_CTX_HOST: |
| 4775 | rc = 0; |
| 4776 | break; |
| 4777 | default: |
| 4778 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4779 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4780 | break; |
| 4781 | } |
| 4782 | |
| 4783 | return rc; |
| 4784 | } |
| 4785 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4786 | /** |
| 4787 | * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending. |
| 4788 | * @vport: Pointer to virtual port. |
| 4789 | * @tgt_id: SCSI ID of the target. |
| 4790 | * @lun_id: LUN ID of the scsi device. |
| 4791 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4792 | * |
| 4793 | * This function returns number of FCP commands pending for the vport. |
| 4794 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4795 | * commands pending on the vport associated with SCSI device specified |
| 4796 | * by tgt_id and lun_id parameters. |
| 4797 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4798 | * commands pending on the vport associated with SCSI target specified |
| 4799 | * by tgt_id parameter. |
| 4800 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4801 | * commands pending on the vport. |
| 4802 | * This function returns the number of iocbs which satisfy the filter. |
| 4803 | * This function is called without any lock held. |
| 4804 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4806 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4807 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4808 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4809 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4810 | struct lpfc_iocbq *iocbq; |
| 4811 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4813 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4814 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4815 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4816 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4817 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4818 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | return sum; |
| 4822 | } |
| 4823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4824 | /** |
| 4825 | * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted |
| 4826 | * FCP iocb. |
| 4827 | * @phba: Pointer to HBA context object |
| 4828 | * @cmdiocb: Pointer to command iocb object. |
| 4829 | * @rspiocb: Pointer to response iocb object. |
| 4830 | * |
| 4831 | * This function is called when an aborted FCP iocb completes. This |
| 4832 | * function is called by the ring event handler with no lock held. |
| 4833 | * This function frees the iocb. |
| 4834 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4835 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4836 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4837 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4838 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4839 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4840 | return; |
| 4841 | } |
| 4842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4843 | /** |
| 4844 | * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands |
| 4845 | * pending on a SCSI host(vport)/target/lun. |
| 4846 | * @vport: Pointer to virtual port. |
| 4847 | * @pring: Pointer to driver SLI ring object. |
| 4848 | * @tgt_id: SCSI ID of the target. |
| 4849 | * @lun_id: LUN ID of the scsi device. |
| 4850 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4851 | * |
| 4852 | * This function sends an abort command for every SCSI command |
| 4853 | * associated with the given virtual port pending on the ring |
| 4854 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 4855 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 4856 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 4857 | * parameters |
| 4858 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 4859 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 4860 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 4861 | * FCP iocbs associated with virtual port. |
| 4862 | * This function returns number of iocbs it failed to abort. |
| 4863 | * This function is called with no locks held. |
| 4864 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4865 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4866 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 4867 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4868 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4869 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4870 | struct lpfc_iocbq *iocbq; |
| 4871 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4872 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4874 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4875 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4876 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 4877 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4878 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4879 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4880 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | continue; |
| 4882 | |
| 4883 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4884 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | if (abtsiocb == NULL) { |
| 4886 | errcnt++; |
| 4887 | continue; |
| 4888 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4889 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4890 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4892 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 4893 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 4894 | abtsiocb->iocb.ulpLe = 1; |
| 4895 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4896 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4898 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 4900 | else |
| 4901 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 4902 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4903 | /* Setup callback routine and issue the command. */ |
| 4904 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4905 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 4906 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4907 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | errcnt++; |
| 4909 | continue; |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | return errcnt; |
| 4914 | } |
| 4915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4916 | /** |
| 4917 | * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using |
| 4918 | * lpfc_sli_issue_iocb_wait. |
| 4919 | * @phba: Pointer to HBA context object. |
| 4920 | * @cmdiocbq: Pointer to command iocb. |
| 4921 | * @rspiocbq: Pointer to response iocb. |
| 4922 | * |
| 4923 | * This function is the completion handler for iocbs issued using |
| 4924 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 4925 | * ring event handler function without any lock held. This function |
| 4926 | * can be called from both worker thread context and interrupt |
| 4927 | * context. This function also can be called from other thread which |
| 4928 | * cleans up the SLI layer objects. |
| 4929 | * This function copy the contents of the response iocb to the |
| 4930 | * response iocb memory object provided by the caller of |
| 4931 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4932 | * sleeps for the iocb completion. |
| 4933 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4934 | static void |
| 4935 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 4936 | struct lpfc_iocbq *cmdiocbq, |
| 4937 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4939 | wait_queue_head_t *pdone_q; |
| 4940 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4943 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 4944 | if (cmdiocbq->context2 && rspiocbq) |
| 4945 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 4946 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 4947 | |
| 4948 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4949 | if (pdone_q) |
| 4950 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4951 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4952 | return; |
| 4953 | } |
| 4954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4955 | /** |
| 4956 | * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands. |
| 4957 | * @phba: Pointer to HBA context object.. |
| 4958 | * @pring: Pointer to sli ring. |
| 4959 | * @piocb: Pointer to command iocb. |
| 4960 | * @prspiocbq: Pointer to response iocb. |
| 4961 | * @timeout: Timeout in number of seconds. |
| 4962 | * |
| 4963 | * This function issues the iocb to firmware and waits for the |
| 4964 | * iocb to complete. If the iocb command is not |
| 4965 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 4966 | * Caller should not free the iocb resources if this function |
| 4967 | * returns IOCB_TIMEDOUT. |
| 4968 | * The function waits for the iocb completion using an |
| 4969 | * non-interruptible wait. |
| 4970 | * This function will sleep while waiting for iocb completion. |
| 4971 | * So, this function should not be called from any context which |
| 4972 | * does not allow sleeping. Due to the same reason, this function |
| 4973 | * cannot be called with interrupt disabled. |
| 4974 | * This function assumes that the iocb completions occur while |
| 4975 | * this function sleep. So, this function cannot be called from |
| 4976 | * the thread which process iocb completion for this ring. |
| 4977 | * This function clears the iocb_flag of the iocb object before |
| 4978 | * issuing the iocb and the iocb completion handler sets this |
| 4979 | * flag and wakes this thread when the iocb completes. |
| 4980 | * The contents of the response iocb will be copied to prspiocbq |
| 4981 | * by the completion handler when the command completes. |
| 4982 | * This function returns IOCB_SUCCESS when success. |
| 4983 | * This function is called with no lock held. |
| 4984 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4986 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 4987 | struct lpfc_sli_ring *pring, |
| 4988 | struct lpfc_iocbq *piocb, |
| 4989 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4990 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4991 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4992 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4993 | long timeleft, timeout_req = 0; |
| 4994 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4995 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4996 | |
| 4997 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4998 | * If the caller has provided a response iocbq buffer, then context2 |
| 4999 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5000 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5001 | if (prspiocbq) { |
| 5002 | if (piocb->context2) |
| 5003 | return IOCB_ERROR; |
| 5004 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5005 | } |
| 5006 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5007 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 5008 | piocb->context_un.wait_queue = &done_q; |
| 5009 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5010 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5011 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5012 | creg_val = readl(phba->HCregaddr); |
| 5013 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 5014 | writel(creg_val, phba->HCregaddr); |
| 5015 | readl(phba->HCregaddr); /* flush */ |
| 5016 | } |
| 5017 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5018 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 5019 | if (retval == IOCB_SUCCESS) { |
| 5020 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5021 | timeleft = wait_event_timeout(done_q, |
| 5022 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 5023 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5025 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 5026 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5027 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5028 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5029 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5030 | "0338 IOCB wait timeout error - no " |
| 5031 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5032 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5033 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5034 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5035 | "0330 IOCB wake NOT set, " |
| 5036 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5037 | timeout, (timeleft / jiffies)); |
| 5038 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5039 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5040 | } else { |
| 5041 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5042 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5043 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5044 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | } |
| 5046 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5047 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5048 | creg_val = readl(phba->HCregaddr); |
| 5049 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 5050 | writel(creg_val, phba->HCregaddr); |
| 5051 | readl(phba->HCregaddr); /* flush */ |
| 5052 | } |
| 5053 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5054 | if (prspiocbq) |
| 5055 | piocb->context2 = NULL; |
| 5056 | |
| 5057 | piocb->context_un.wait_queue = NULL; |
| 5058 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | return retval; |
| 5060 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5061 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5062 | /** |
| 5063 | * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox. |
| 5064 | * @phba: Pointer to HBA context object. |
| 5065 | * @pmboxq: Pointer to driver mailbox object. |
| 5066 | * @timeout: Timeout in number of seconds. |
| 5067 | * |
| 5068 | * This function issues the mailbox to firmware and waits for the |
| 5069 | * mailbox command to complete. If the mailbox command is not |
| 5070 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 5071 | * The function waits for the mailbox completion using an |
| 5072 | * interruptible wait. If the thread is woken up due to a |
| 5073 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 5074 | * should not free the mailbox resources, if this function returns |
| 5075 | * MBX_TIMEOUT. |
| 5076 | * This function will sleep while waiting for mailbox completion. |
| 5077 | * So, this function should not be called from any context which |
| 5078 | * does not allow sleeping. Due to the same reason, this function |
| 5079 | * cannot be called with interrupt disabled. |
| 5080 | * This function assumes that the mailbox completion occurs while |
| 5081 | * this function sleep. So, this function cannot be called from |
| 5082 | * the worker thread which processes mailbox completion. |
| 5083 | * This function is called in the context of HBA management |
| 5084 | * applications. |
| 5085 | * This function returns MBX_SUCCESS when successful. |
| 5086 | * This function is called with no lock held. |
| 5087 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5088 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5089 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | uint32_t timeout) |
| 5091 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5092 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5093 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5094 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5095 | |
| 5096 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5097 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5098 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5100 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5101 | /* setup wake call as IOCB callback */ |
| 5102 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 5103 | /* setup context field to pass wait_queue pointer to wake function */ |
| 5104 | pmboxq->context1 = &done_q; |
| 5105 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | /* now issue the command */ |
| 5107 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 5108 | |
| 5109 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5110 | wait_event_interruptible_timeout(done_q, |
| 5111 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 5112 | timeout * HZ); |
| 5113 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5114 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5115 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5116 | /* |
| 5117 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 5118 | * else do not free the resources. |
| 5119 | */ |
| 5120 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5121 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5122 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5123 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5124 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5125 | } |
| 5126 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5127 | } |
| 5128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5129 | return retval; |
| 5130 | } |
| 5131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5132 | /** |
| 5133 | * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function. |
| 5134 | * @phba: Pointer to HBA context. |
| 5135 | * |
| 5136 | * This function is called to cleanup any pending mailbox |
| 5137 | * objects in the driver queue before bringing the HBA offline. |
| 5138 | * This function is called while resetting the HBA. |
| 5139 | * The function is called without any lock held. The function |
| 5140 | * takes hbalock to update SLI data structure. |
| 5141 | * This function returns 1 when there is an active mailbox |
| 5142 | * command pending else returns 0. |
| 5143 | **/ |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5144 | int |
| 5145 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 5146 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5147 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5148 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5149 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5150 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5151 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5152 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 5153 | return 1; |
| 5154 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5155 | /* |
| 5156 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 5157 | * did finish. This way we won't get the misleading |
| 5158 | * "Stray Mailbox Interrupt" message. |
| 5159 | */ |
| 5160 | spin_lock_irq(&phba->hbalock); |
| 5161 | ha_copy = phba->work_ha; |
| 5162 | phba->work_ha &= ~HA_MBATT; |
| 5163 | spin_unlock_irq(&phba->hbalock); |
| 5164 | |
| 5165 | if (ha_copy & HA_MBATT) |
| 5166 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 5167 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5168 | |
| 5169 | msleep(1); |
| 5170 | } |
| 5171 | |
| 5172 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 5173 | } |
| 5174 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5175 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5176 | * lpfc_sli_check_eratt: check error attention events |
| 5177 | * @phba: Pointer to HBA context. |
| 5178 | * |
| 5179 | * This function is called form timer soft interrupt context to check HBA's |
| 5180 | * error attention register bit for error attention events. |
| 5181 | * |
| 5182 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5183 | * Register and returns 0 otherwise. |
| 5184 | **/ |
| 5185 | int |
| 5186 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 5187 | { |
| 5188 | uint32_t ha_copy; |
| 5189 | |
| 5190 | /* If somebody is waiting to handle an eratt, don't process it |
| 5191 | * here. The brdkill function will do this. |
| 5192 | */ |
| 5193 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5194 | return 0; |
| 5195 | |
| 5196 | /* Check if interrupt handler handles this ERATT */ |
| 5197 | spin_lock_irq(&phba->hbalock); |
| 5198 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 5199 | /* Interrupt handler has handled ERATT */ |
| 5200 | spin_unlock_irq(&phba->hbalock); |
| 5201 | return 0; |
| 5202 | } |
| 5203 | |
| 5204 | /* Read chip Host Attention (HA) register */ |
| 5205 | ha_copy = readl(phba->HAregaddr); |
| 5206 | if (ha_copy & HA_ERATT) { |
| 5207 | /* Read host status register to retrieve error event */ |
| 5208 | lpfc_sli_read_hs(phba); |
| 5209 | /* Set the driver HA work bitmap */ |
| 5210 | phba->work_ha |= HA_ERATT; |
| 5211 | /* Indicate polling handles this ERATT */ |
| 5212 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5213 | spin_unlock_irq(&phba->hbalock); |
| 5214 | return 1; |
| 5215 | } |
| 5216 | spin_unlock_irq(&phba->hbalock); |
| 5217 | return 0; |
| 5218 | } |
| 5219 | |
| 5220 | /** |
| 5221 | * lpfc_sp_intr_handler: The slow-path interrupt handler of lpfc driver. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5222 | * @irq: Interrupt number. |
| 5223 | * @dev_id: The device context pointer. |
| 5224 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5225 | * This function is directly called from the PCI layer as an interrupt |
| 5226 | * service routine when the device is enabled with MSI-X multi-message |
| 5227 | * interrupt mode and there are slow-path events in the HBA. However, |
| 5228 | * when the device is enabled with either MSI or Pin-IRQ interrupt mode, |
| 5229 | * this function is called as part of the device-level interrupt handler. |
| 5230 | * When the PCI slot is in error recovery or the HBA is undergoing |
| 5231 | * initialization, the interrupt handler will not process the interrupt. |
| 5232 | * The link attention and ELS ring attention events are handled by the |
| 5233 | * worker thread. The interrupt handler signals the worker thread and |
| 5234 | * and returns for these events. This function is called without any |
| 5235 | * lock held. It gets the hbalock to access and update SLI data |
| 5236 | * structures. |
| 5237 | * |
| 5238 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5239 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5240 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5241 | irqreturn_t |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5242 | lpfc_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5243 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5244 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | uint32_t ha_copy; |
| 5246 | uint32_t work_ha_copy; |
| 5247 | unsigned long status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | uint32_t control; |
| 5249 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5250 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5251 | struct lpfc_vport *vport; |
| 5252 | struct lpfc_nodelist *ndlp; |
| 5253 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5254 | LPFC_MBOXQ_t *pmb; |
| 5255 | int rc; |
| 5256 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | /* |
| 5258 | * Get the driver's phba structure from the dev_id and |
| 5259 | * assume the HBA is not interrupting. |
| 5260 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5261 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | |
| 5263 | if (unlikely(!phba)) |
| 5264 | return IRQ_NONE; |
| 5265 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5267 | * Stuff needs to be attented to when this function is invoked as an |
| 5268 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5270 | if (phba->intr_type == MSIX) { |
| 5271 | /* If the pci channel is offline, ignore all the interrupts */ |
| 5272 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5273 | return IRQ_NONE; |
| 5274 | /* Update device-level interrupt statistics */ |
| 5275 | phba->sli.slistat.sli_intr++; |
| 5276 | /* Ignore all interrupts during initialization. */ |
| 5277 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5278 | return IRQ_NONE; |
| 5279 | /* Need to read HA REG for slow-path events */ |
| 5280 | spin_lock(&phba->hbalock); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5281 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5282 | /* If somebody is waiting to handle an eratt don't process it |
| 5283 | * here. The brdkill function will do this. |
| 5284 | */ |
| 5285 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5286 | ha_copy &= ~HA_ERATT; |
| 5287 | /* Check the need for handling ERATT in interrupt handler */ |
| 5288 | if (ha_copy & HA_ERATT) { |
| 5289 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5290 | /* ERATT polling has handled ERATT */ |
| 5291 | ha_copy &= ~HA_ERATT; |
| 5292 | else |
| 5293 | /* Indicate interrupt handler handles ERATT */ |
| 5294 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5295 | } |
| 5296 | /* Clear up only attention source related to slow-path */ |
| 5297 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 5298 | phba->HAregaddr); |
| 5299 | readl(phba->HAregaddr); /* flush */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5300 | spin_unlock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5301 | } else |
| 5302 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5305 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5306 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5307 | if (work_ha_copy & HA_LATT) { |
| 5308 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5309 | /* |
| 5310 | * Turn off Link Attention interrupts |
| 5311 | * until CLEAR_LA done |
| 5312 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5313 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5314 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5315 | control = readl(phba->HCregaddr); |
| 5316 | control &= ~HC_LAINT_ENA; |
| 5317 | writel(control, phba->HCregaddr); |
| 5318 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5319 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5320 | } |
| 5321 | else |
| 5322 | work_ha_copy &= ~HA_LATT; |
| 5323 | } |
| 5324 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5325 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5326 | /* |
| 5327 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5328 | * the only slow ring. |
| 5329 | */ |
| 5330 | status = (work_ha_copy & |
| 5331 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5332 | status >>= (4*LPFC_ELS_RING); |
| 5333 | if (status & HA_RXMASK) { |
| 5334 | spin_lock(&phba->hbalock); |
| 5335 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5336 | |
| 5337 | lpfc_debugfs_slow_ring_trc(phba, |
| 5338 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5339 | control, status, |
| 5340 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5341 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5342 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5343 | lpfc_debugfs_slow_ring_trc(phba, |
| 5344 | "ISR Disable ring:" |
| 5345 | "pwork:x%x hawork:x%x wait:x%x", |
| 5346 | phba->work_ha, work_ha_copy, |
| 5347 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5348 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5349 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5350 | control &= |
| 5351 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5352 | writel(control, phba->HCregaddr); |
| 5353 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5354 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5355 | else { |
| 5356 | lpfc_debugfs_slow_ring_trc(phba, |
| 5357 | "ISR slow ring: pwork:" |
| 5358 | "x%x hawork:x%x wait:x%x", |
| 5359 | phba->work_ha, work_ha_copy, |
| 5360 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5361 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5362 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5363 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | } |
| 5365 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5366 | spin_lock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5367 | if (work_ha_copy & HA_ERATT) |
| 5368 | lpfc_sli_read_hs(phba); |
| 5369 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5370 | pmb = phba->sli.mbox_active; |
| 5371 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5372 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5373 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5374 | |
| 5375 | /* First check out the status word */ |
| 5376 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5377 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5378 | spin_unlock(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5379 | /* |
| 5380 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5381 | * mbxStatus <status> |
| 5382 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5383 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5384 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5385 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5386 | "Interrupt mbxCommand x%x " |
| 5387 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5388 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5389 | pmbox->mbxCommand, |
| 5390 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5391 | /* clear mailbox attention bit */ |
| 5392 | work_ha_copy &= ~HA_MBATT; |
| 5393 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5394 | phba->sli.mbox_active = NULL; |
| 5395 | spin_unlock(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5396 | phba->last_completion_time = jiffies; |
| 5397 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5398 | if (pmb->mbox_cmpl) { |
| 5399 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5400 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5401 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5402 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5403 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5404 | |
| 5405 | lpfc_debugfs_disc_trc(vport, |
| 5406 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5407 | "MBOX dflt rpi: : " |
| 5408 | "status:x%x rpi:x%x", |
| 5409 | (uint32_t)pmbox->mbxStatus, |
| 5410 | pmbox->un.varWords[0], 0); |
| 5411 | |
| 5412 | if (!pmbox->mbxStatus) { |
| 5413 | mp = (struct lpfc_dmabuf *) |
| 5414 | (pmb->context1); |
| 5415 | ndlp = (struct lpfc_nodelist *) |
| 5416 | pmb->context2; |
| 5417 | |
| 5418 | /* Reg_LOGIN of dflt RPI was |
| 5419 | * successful. new lets get |
| 5420 | * rid of the RPI using the |
| 5421 | * same mbox buffer. |
| 5422 | */ |
| 5423 | lpfc_unreg_login(phba, |
| 5424 | vport->vpi, |
| 5425 | pmbox->un.varWords[0], |
| 5426 | pmb); |
| 5427 | pmb->mbox_cmpl = |
| 5428 | lpfc_mbx_cmpl_dflt_rpi; |
| 5429 | pmb->context1 = mp; |
| 5430 | pmb->context2 = ndlp; |
| 5431 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5432 | rc = lpfc_sli_issue_mbox(phba, |
| 5433 | pmb, |
| 5434 | MBX_NOWAIT); |
| 5435 | if (rc != MBX_BUSY) |
| 5436 | lpfc_printf_log(phba, |
| 5437 | KERN_ERR, |
| 5438 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5439 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5440 | "been MBX_BUSY"); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5441 | goto send_current_mbox; |
| 5442 | } |
| 5443 | } |
| 5444 | spin_lock(&phba->pport->work_port_lock); |
| 5445 | phba->pport->work_port_events &= |
| 5446 | ~WORKER_MBOX_TMO; |
| 5447 | spin_unlock(&phba->pport->work_port_lock); |
| 5448 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5449 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5450 | } else |
| 5451 | spin_unlock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5452 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5453 | if ((work_ha_copy & HA_MBATT) && |
| 5454 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5455 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5456 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5457 | do { |
| 5458 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5459 | MBX_NOWAIT); |
| 5460 | } while (rc == MBX_NOT_FINISHED); |
| 5461 | if (rc != MBX_SUCCESS) |
| 5462 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5463 | LOG_SLI, "0349 rc should be " |
| 5464 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5465 | } |
| 5466 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | phba->work_ha |= work_ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5469 | spin_unlock(&phba->hbalock); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5470 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5471 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5472 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5474 | } /* lpfc_sp_intr_handler */ |
| 5475 | |
| 5476 | /** |
| 5477 | * lpfc_fp_intr_handler: The fast-path interrupt handler of lpfc driver. |
| 5478 | * @irq: Interrupt number. |
| 5479 | * @dev_id: The device context pointer. |
| 5480 | * |
| 5481 | * This function is directly called from the PCI layer as an interrupt |
| 5482 | * service routine when the device is enabled with MSI-X multi-message |
| 5483 | * interrupt mode and there is a fast-path FCP IOCB ring event in the |
| 5484 | * HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 5485 | * interrupt mode, this function is called as part of the device-level |
| 5486 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 5487 | * is undergoing initialization, the interrupt handler will not process |
| 5488 | * the interrupt. The SCSI FCP fast-path ring event are handled in the |
| 5489 | * intrrupt context. This function is called without any lock held. It |
| 5490 | * gets the hbalock to access and update SLI data structures. |
| 5491 | * |
| 5492 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5493 | * returns IRQ_NONE. |
| 5494 | **/ |
| 5495 | irqreturn_t |
| 5496 | lpfc_fp_intr_handler(int irq, void *dev_id) |
| 5497 | { |
| 5498 | struct lpfc_hba *phba; |
| 5499 | uint32_t ha_copy; |
| 5500 | unsigned long status; |
| 5501 | |
| 5502 | /* Get the driver's phba structure from the dev_id and |
| 5503 | * assume the HBA is not interrupting. |
| 5504 | */ |
| 5505 | phba = (struct lpfc_hba *) dev_id; |
| 5506 | |
| 5507 | if (unlikely(!phba)) |
| 5508 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | |
| 5510 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5511 | * Stuff needs to be attented to when this function is invoked as an |
| 5512 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5513 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5514 | if (phba->intr_type == MSIX) { |
| 5515 | /* If pci channel is offline, ignore all the interrupts */ |
| 5516 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5517 | return IRQ_NONE; |
| 5518 | /* Update device-level interrupt statistics */ |
| 5519 | phba->sli.slistat.sli_intr++; |
| 5520 | /* Ignore all interrupts during initialization. */ |
| 5521 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5522 | return IRQ_NONE; |
| 5523 | /* Need to read HA REG for FCP ring and other ring events */ |
| 5524 | ha_copy = readl(phba->HAregaddr); |
| 5525 | /* Clear up only attention source related to fast-path */ |
| 5526 | spin_lock(&phba->hbalock); |
| 5527 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 5528 | phba->HAregaddr); |
| 5529 | readl(phba->HAregaddr); /* flush */ |
| 5530 | spin_unlock(&phba->hbalock); |
| 5531 | } else |
| 5532 | ha_copy = phba->ha_copy; |
| 5533 | |
| 5534 | /* |
| 5535 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 5536 | */ |
| 5537 | ha_copy &= ~(phba->work_ha_mask); |
| 5538 | |
| 5539 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5541 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5542 | lpfc_sli_handle_fast_ring_event(phba, |
| 5543 | &phba->sli.ring[LPFC_FCP_RING], |
| 5544 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5545 | |
| 5546 | if (phba->cfg_multi_ring_support == 2) { |
| 5547 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5548 | * Process all events on extra ring. Take the optimized path |
| 5549 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5550 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5551 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5552 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5553 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5554 | lpfc_sli_handle_fast_ring_event(phba, |
| 5555 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5556 | status); |
| 5557 | } |
| 5558 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5560 | } /* lpfc_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5562 | /** |
| 5563 | * lpfc_intr_handler: The device-level interrupt handler of lpfc driver. |
| 5564 | * @irq: Interrupt number. |
| 5565 | * @dev_id: The device context pointer. |
| 5566 | * |
| 5567 | * This function is the device-level interrupt handler called from the PCI |
| 5568 | * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is |
| 5569 | * an event in the HBA which requires driver attention. This function |
| 5570 | * invokes the slow-path interrupt attention handling function and fast-path |
| 5571 | * interrupt attention handling function in turn to process the relevant |
| 5572 | * HBA attention events. This function is called without any lock held. It |
| 5573 | * gets the hbalock to access and update SLI data structures. |
| 5574 | * |
| 5575 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 5576 | * returns IRQ_NONE. |
| 5577 | **/ |
| 5578 | irqreturn_t |
| 5579 | lpfc_intr_handler(int irq, void *dev_id) |
| 5580 | { |
| 5581 | struct lpfc_hba *phba; |
| 5582 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 5583 | unsigned long status1, status2; |
| 5584 | |
| 5585 | /* |
| 5586 | * Get the driver's phba structure from the dev_id and |
| 5587 | * assume the HBA is not interrupting. |
| 5588 | */ |
| 5589 | phba = (struct lpfc_hba *) dev_id; |
| 5590 | |
| 5591 | if (unlikely(!phba)) |
| 5592 | return IRQ_NONE; |
| 5593 | |
| 5594 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 5595 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5596 | return IRQ_NONE; |
| 5597 | |
| 5598 | /* Update device level interrupt statistics */ |
| 5599 | phba->sli.slistat.sli_intr++; |
| 5600 | |
| 5601 | /* Ignore all interrupts during initialization. */ |
| 5602 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5603 | return IRQ_NONE; |
| 5604 | |
| 5605 | spin_lock(&phba->hbalock); |
| 5606 | phba->ha_copy = readl(phba->HAregaddr); |
| 5607 | if (unlikely(!phba->ha_copy)) { |
| 5608 | spin_unlock(&phba->hbalock); |
| 5609 | return IRQ_NONE; |
| 5610 | } else if (phba->ha_copy & HA_ERATT) { |
| 5611 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5612 | /* ERATT polling has handled ERATT */ |
| 5613 | phba->ha_copy &= ~HA_ERATT; |
| 5614 | else |
| 5615 | /* Indicate interrupt handler handles ERATT */ |
| 5616 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5617 | } |
| 5618 | |
| 5619 | /* Clear attention sources except link and error attentions */ |
| 5620 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5621 | readl(phba->HAregaddr); /* flush */ |
| 5622 | spin_unlock(&phba->hbalock); |
| 5623 | |
| 5624 | /* |
| 5625 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 5626 | */ |
| 5627 | |
| 5628 | /* status of events with mailbox and link attention */ |
| 5629 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 5630 | |
| 5631 | /* status of events with ELS ring */ |
| 5632 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5633 | status2 >>= (4*LPFC_ELS_RING); |
| 5634 | |
| 5635 | if (status1 || (status2 & HA_RXMASK)) |
| 5636 | sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id); |
| 5637 | else |
| 5638 | sp_irq_rc = IRQ_NONE; |
| 5639 | |
| 5640 | /* |
| 5641 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 5642 | */ |
| 5643 | |
| 5644 | /* status of events with FCP ring */ |
| 5645 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5646 | status1 >>= (4*LPFC_FCP_RING); |
| 5647 | |
| 5648 | /* status of events with extra ring */ |
| 5649 | if (phba->cfg_multi_ring_support == 2) { |
| 5650 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5651 | status2 >>= (4*LPFC_EXTRA_RING); |
| 5652 | } else |
| 5653 | status2 = 0; |
| 5654 | |
| 5655 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
| 5656 | fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id); |
| 5657 | else |
| 5658 | fp_irq_rc = IRQ_NONE; |
| 5659 | |
| 5660 | /* Return device-level interrupt handling status */ |
| 5661 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
| 5662 | } /* lpfc_intr_handler */ |