| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_cmnd.h> |
| 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 31 | #include <scsi/scsi_transport_fc.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
| 35 | #include "lpfc_disc.h" |
| 36 | #include "lpfc_scsi.h" |
| 37 | #include "lpfc.h" |
| 38 | #include "lpfc_crtn.h" |
| 39 | #include "lpfc_logmsg.h" |
| 40 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 41 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 45 | * This allows multiple uses of lpfc_msgBlk0311 |
| 46 | * w/o perturbing log msg utility. |
| 47 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 48 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | lpfc_printf_log(phba, \ |
| 50 | KERN_INFO, \ |
| 51 | LOG_MBOX | LOG_SLI, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 52 | "(%d):0311 Mailbox command x%x cannot " \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | "issue Data: x%x x%x x%x\n", \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 55 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 56 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 58 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | |
| 60 | |
| 61 | /* There are only four IOCB completion types. */ |
| 62 | typedef enum _lpfc_iocb_type { |
| 63 | LPFC_UNKNOWN_IOCB, |
| 64 | LPFC_UNSOL_IOCB, |
| 65 | LPFC_SOL_IOCB, |
| 66 | LPFC_ABORT_IOCB |
| 67 | } lpfc_iocb_type; |
| 68 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 69 | /** |
| 70 | * lpfc_cmd_iocb: Get next command iocb entry in the ring. |
| 71 | * @phba: Pointer to HBA context object. |
| 72 | * @pring: Pointer to driver SLI ring object. |
| 73 | * |
| 74 | * This function returns pointer to next command iocb entry |
| 75 | * in the command ring. The caller must hold hbalock to prevent |
| 76 | * other threads consume the next command iocb. |
| 77 | * SLI-2/SLI-3 provide different sized iocbs. |
| 78 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 79 | static inline IOCB_t * |
| 80 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 81 | { |
| 82 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 83 | pring->cmdidx * phba->iocb_cmd_size); |
| 84 | } |
| 85 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 86 | /** |
| 87 | * lpfc_resp_iocb: Get next response iocb entry in the ring. |
| 88 | * @phba: Pointer to HBA context object. |
| 89 | * @pring: Pointer to driver SLI ring object. |
| 90 | * |
| 91 | * This function returns pointer to next response iocb entry |
| 92 | * in the response ring. The caller must hold hbalock to make sure |
| 93 | * that no other thread consume the next response iocb. |
| 94 | * SLI-2/SLI-3 provide different sized iocbs. |
| 95 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 96 | static inline IOCB_t * |
| 97 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 98 | { |
| 99 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 100 | pring->rspidx * phba->iocb_rsp_size); |
| 101 | } |
| 102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 103 | /** |
| 104 | * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 105 | * @phba: Pointer to HBA context object. |
| 106 | * |
| 107 | * This function is called with hbalock held. This function |
| 108 | * allocates a new driver iocb object from the iocb pool. If the |
| 109 | * allocation is successful, it returns pointer to the newly |
| 110 | * allocated iocb object else it returns NULL. |
| 111 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 112 | static struct lpfc_iocbq * |
| 113 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 114 | { |
| 115 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 116 | struct lpfc_iocbq * iocbq = NULL; |
| 117 | |
| 118 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 119 | return iocbq; |
| 120 | } |
| 121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | /** |
| 123 | * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. |
| 124 | * @phba: Pointer to HBA context object. |
| 125 | * |
| 126 | * This function is called with no lock held. This function |
| 127 | * allocates a new driver iocb object from the iocb pool. If the |
| 128 | * allocation is successful, it returns pointer to the newly |
| 129 | * allocated iocb object else it returns NULL. |
| 130 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 131 | struct lpfc_iocbq * |
| 132 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 133 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 134 | struct lpfc_iocbq * iocbq = NULL; |
| 135 | unsigned long iflags; |
| 136 | |
| 137 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 138 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 139 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 140 | return iocbq; |
| 141 | } |
| 142 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 143 | /** |
| 144 | * __lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 145 | * @phba: Pointer to HBA context object. |
| 146 | * @iocbq: Pointer to driver iocb object. |
| 147 | * |
| 148 | * This function is called with hbalock held to release driver |
| 149 | * iocb object to the iocb pool. The iotag in the iocb object |
| 150 | * does not change for each use of the iocb object. This function |
| 151 | * clears all other fields of the iocb object when it is freed. |
| 152 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 153 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 155 | { |
| 156 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Clean all volatile data fields, preserve iotag and node struct. |
| 160 | */ |
| 161 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 162 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 163 | } |
| 164 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 165 | /** |
| 166 | * lpfc_sli_release_iocbq: Release iocb to the iocb pool. |
| 167 | * @phba: Pointer to HBA context object. |
| 168 | * @iocbq: Pointer to driver iocb object. |
| 169 | * |
| 170 | * This function is called with no lock held to release the iocb to |
| 171 | * iocb pool. |
| 172 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 173 | void |
| 174 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 175 | { |
| 176 | unsigned long iflags; |
| 177 | |
| 178 | /* |
| 179 | * Clean all volatile data fields, preserve iotag and node struct. |
| 180 | */ |
| 181 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 182 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 183 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 184 | } |
| 185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 186 | /** |
| 187 | * lpfc_sli_iocb_cmd_type: Get the iocb type. |
| 188 | * @iocb_cmnd : iocb command code. |
| 189 | * |
| 190 | * This function is called by ring event handler function to get the iocb type. |
| 191 | * This function translates the iocb command to an iocb command type used to |
| 192 | * decide the final disposition of each completed IOCB. |
| 193 | * The function returns |
| 194 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 195 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 196 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 197 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 198 | * |
| 199 | * The caller is not required to hold any lock. |
| 200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | static lpfc_iocb_type |
| 202 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 203 | { |
| 204 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 205 | |
| 206 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 207 | return 0; |
| 208 | |
| 209 | switch (iocb_cmnd) { |
| 210 | case CMD_XMIT_SEQUENCE_CR: |
| 211 | case CMD_XMIT_SEQUENCE_CX: |
| 212 | case CMD_XMIT_BCAST_CN: |
| 213 | case CMD_XMIT_BCAST_CX: |
| 214 | case CMD_ELS_REQUEST_CR: |
| 215 | case CMD_ELS_REQUEST_CX: |
| 216 | case CMD_CREATE_XRI_CR: |
| 217 | case CMD_CREATE_XRI_CX: |
| 218 | case CMD_GET_RPI_CN: |
| 219 | case CMD_XMIT_ELS_RSP_CX: |
| 220 | case CMD_GET_RPI_CR: |
| 221 | case CMD_FCP_IWRITE_CR: |
| 222 | case CMD_FCP_IWRITE_CX: |
| 223 | case CMD_FCP_IREAD_CR: |
| 224 | case CMD_FCP_IREAD_CX: |
| 225 | case CMD_FCP_ICMND_CR: |
| 226 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 227 | case CMD_FCP_TSEND_CX: |
| 228 | case CMD_FCP_TRSP_CX: |
| 229 | case CMD_FCP_TRECEIVE_CX: |
| 230 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | case CMD_ADAPTER_MSG: |
| 232 | case CMD_ADAPTER_DUMP: |
| 233 | case CMD_XMIT_SEQUENCE64_CR: |
| 234 | case CMD_XMIT_SEQUENCE64_CX: |
| 235 | case CMD_XMIT_BCAST64_CN: |
| 236 | case CMD_XMIT_BCAST64_CX: |
| 237 | case CMD_ELS_REQUEST64_CR: |
| 238 | case CMD_ELS_REQUEST64_CX: |
| 239 | case CMD_FCP_IWRITE64_CR: |
| 240 | case CMD_FCP_IWRITE64_CX: |
| 241 | case CMD_FCP_IREAD64_CR: |
| 242 | case CMD_FCP_IREAD64_CX: |
| 243 | case CMD_FCP_ICMND64_CR: |
| 244 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 245 | case CMD_FCP_TSEND64_CX: |
| 246 | case CMD_FCP_TRSP64_CX: |
| 247 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | case CMD_GEN_REQUEST64_CR: |
| 249 | case CMD_GEN_REQUEST64_CX: |
| 250 | case CMD_XMIT_ELS_RSP64_CX: |
| 251 | type = LPFC_SOL_IOCB; |
| 252 | break; |
| 253 | case CMD_ABORT_XRI_CN: |
| 254 | case CMD_ABORT_XRI_CX: |
| 255 | case CMD_CLOSE_XRI_CN: |
| 256 | case CMD_CLOSE_XRI_CX: |
| 257 | case CMD_XRI_ABORTED_CX: |
| 258 | case CMD_ABORT_MXRI64_CN: |
| 259 | type = LPFC_ABORT_IOCB; |
| 260 | break; |
| 261 | case CMD_RCV_SEQUENCE_CX: |
| 262 | case CMD_RCV_ELS_REQ_CX: |
| 263 | case CMD_RCV_SEQUENCE64_CX: |
| 264 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 265 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 266 | case CMD_IOCB_RCV_SEQ64_CX: |
| 267 | case CMD_IOCB_RCV_ELS64_CX: |
| 268 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 269 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | type = LPFC_UNSOL_IOCB; |
| 271 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 272 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 273 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 274 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 275 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 276 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 277 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 278 | case CMD_IOCB_RET_HBQE64_CN: |
| 279 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 280 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 281 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 282 | case CMD_IOCB_LOGENTRY_CN: |
| 283 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 284 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 285 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 286 | type = LPFC_UNKNOWN_IOCB; |
| 287 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 288 | default: |
| 289 | type = LPFC_UNKNOWN_IOCB; |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | return type; |
| 294 | } |
| 295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 296 | /** |
| 297 | * lpfc_sli_ring_map: Issue config_ring mbox for all rings. |
| 298 | * @phba: Pointer to HBA context object. |
| 299 | * |
| 300 | * This function is called from SLI initialization code |
| 301 | * to configure every ring of the HBA's SLI interface. The |
| 302 | * caller is not required to hold any lock. This function issues |
| 303 | * a config_ring mailbox command for each ring. |
| 304 | * This function returns zero if successful else returns a negative |
| 305 | * error code. |
| 306 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 308 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 309 | { |
| 310 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 311 | LPFC_MBOXQ_t *pmb; |
| 312 | MAILBOX_t *pmbox; |
| 313 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 314 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 315 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 316 | if (!pmb) |
| 317 | return -ENOMEM; |
| 318 | pmbox = &pmb->mb; |
| 319 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | lpfc_config_ring(phba, i, pmb); |
| 322 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 323 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 325 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 326 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 327 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 328 | rc, pmbox->mbxCommand, |
| 329 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 330 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 331 | ret = -ENXIO; |
| 332 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | } |
| 334 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 335 | mempool_free(pmb, phba->mbox_mem_pool); |
| 336 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 337 | } |
| 338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 339 | /** |
| 340 | * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq. |
| 341 | * @phba: Pointer to HBA context object. |
| 342 | * @pring: Pointer to driver SLI ring object. |
| 343 | * @piocb: Pointer to the driver iocb object. |
| 344 | * |
| 345 | * This function is called with hbalock held. The function adds the |
| 346 | * new iocb to txcmplq of the given ring. This function always returns |
| 347 | * 0. If this function is called for ELS ring, this function checks if |
| 348 | * there is a vport associated with the ELS command. This function also |
| 349 | * starts els_tmofunc timer if this is an ELS command. |
| 350 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 351 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 352 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 353 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 356 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 358 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 359 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 360 | if (!piocb->vport) |
| 361 | BUG(); |
| 362 | else |
| 363 | mod_timer(&piocb->vport->els_tmofunc, |
| 364 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 365 | } |
| 366 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 367 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 368 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 369 | } |
| 370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 371 | /** |
| 372 | * lpfc_sli_ringtx_get: Get first element of the txq. |
| 373 | * @phba: Pointer to HBA context object. |
| 374 | * @pring: Pointer to driver SLI ring object. |
| 375 | * |
| 376 | * This function is called with hbalock held to get next |
| 377 | * iocb in txq of the given ring. If there is any iocb in |
| 378 | * the txq, the function returns first iocb in the list after |
| 379 | * removing the iocb from the list, else it returns NULL. |
| 380 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 381 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 382 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 383 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | struct lpfc_iocbq *cmd_iocb; |
| 385 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 386 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 387 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 389 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | } |
| 391 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 392 | /** |
| 393 | * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring. |
| 394 | * @phba: Pointer to HBA context object. |
| 395 | * @pring: Pointer to driver SLI ring object. |
| 396 | * |
| 397 | * This function is called with hbalock held and the caller must post the |
| 398 | * iocb without releasing the lock. If the caller releases the lock, |
| 399 | * iocb slot returned by the function is not guaranteed to be available. |
| 400 | * The function returns pointer to the next available iocb slot if there |
| 401 | * is available slot in the ring, else it returns NULL. |
| 402 | * If the get index of the ring is ahead of the put index, the function |
| 403 | * will post an error attention event to the worker thread to take the |
| 404 | * HBA to offline state. |
| 405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | static IOCB_t * |
| 407 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 408 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 409 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 412 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 413 | pring->next_cmdidx = 0; |
| 414 | |
| 415 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 416 | |
| 417 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 418 | |
| 419 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 420 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 421 | "0315 Ring %d issue: portCmdGet %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | "is bigger then cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 423 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | pring->local_getidx, max_cmd_idx); |
| 425 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 426 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | /* |
| 428 | * All error attention handlers are posted to |
| 429 | * worker thread |
| 430 | */ |
| 431 | phba->work_ha |= HA_ERATT; |
| 432 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 433 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 434 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | |
| 436 | return NULL; |
| 437 | } |
| 438 | |
| 439 | if (pring->local_getidx == pring->next_cmdidx) |
| 440 | return NULL; |
| 441 | } |
| 442 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 443 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | } |
| 445 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 446 | /** |
| 447 | * lpfc_sli_next_iotag: Get an iotag for the iocb. |
| 448 | * @phba: Pointer to HBA context object. |
| 449 | * @iocbq: Pointer to driver iocb object. |
| 450 | * |
| 451 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 452 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 453 | * array and assigns a new iotag. |
| 454 | * The function returns the allocated iotag if successful, else returns zero. |
| 455 | * Zero is not a valid iotag. |
| 456 | * The caller is not required to hold any lock. |
| 457 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 458 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | struct lpfc_iocbq **new_arr; |
| 462 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 463 | size_t new_len; |
| 464 | struct lpfc_sli *psli = &phba->sli; |
| 465 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 466 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 467 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 468 | iotag = psli->last_iotag; |
| 469 | if(++iotag < psli->iocbq_lookup_len) { |
| 470 | psli->last_iotag = iotag; |
| 471 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 472 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 473 | iocbq->iotag = iotag; |
| 474 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 475 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 476 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 477 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | spin_unlock_irq(&phba->hbalock); |
| 479 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 480 | GFP_KERNEL); |
| 481 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 482 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 483 | old_arr = psli->iocbq_lookup; |
| 484 | if (new_len <= psli->iocbq_lookup_len) { |
| 485 | /* highly unprobable case */ |
| 486 | kfree(new_arr); |
| 487 | iotag = psli->last_iotag; |
| 488 | if(++iotag < psli->iocbq_lookup_len) { |
| 489 | psli->last_iotag = iotag; |
| 490 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 491 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 492 | iocbq->iotag = iotag; |
| 493 | return iotag; |
| 494 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 495 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | if (psli->iocbq_lookup) |
| 499 | memcpy(new_arr, old_arr, |
| 500 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 501 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 502 | psli->iocbq_lookup = new_arr; |
| 503 | psli->iocbq_lookup_len = new_len; |
| 504 | psli->last_iotag = iotag; |
| 505 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 507 | iocbq->iotag = iotag; |
| 508 | kfree(old_arr); |
| 509 | return iotag; |
| 510 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 511 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 514 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 515 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 516 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 518 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | } |
| 520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 521 | /** |
| 522 | * lpfc_sli_submit_iocb: Submit an iocb to the firmware. |
| 523 | * @phba: Pointer to HBA context object. |
| 524 | * @pring: Pointer to driver SLI ring object. |
| 525 | * @iocb: Pointer to iocb slot in the ring. |
| 526 | * @nextiocb: Pointer to driver iocb object which need to be |
| 527 | * posted to firmware. |
| 528 | * |
| 529 | * This function is called with hbalock held to post a new iocb to |
| 530 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 531 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 532 | * a completion call back for this iocb else the function will free the |
| 533 | * iocb object. |
| 534 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | static void |
| 536 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 537 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 538 | { |
| 539 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 540 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 542 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 544 | if (pring->ringno == LPFC_ELS_RING) { |
| 545 | lpfc_debugfs_slow_ring_trc(phba, |
| 546 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 547 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 548 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 549 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 550 | } |
| 551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | /* |
| 553 | * Issue iocb command to adapter |
| 554 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 555 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | wmb(); |
| 557 | pring->stats.iocb_cmd++; |
| 558 | |
| 559 | /* |
| 560 | * If there is no completion routine to call, we can release the |
| 561 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 562 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 563 | */ |
| 564 | if (nextiocb->iocb_cmpl) |
| 565 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 566 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 567 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 568 | |
| 569 | /* |
| 570 | * Let the HBA know what IOCB slot will be the next one the |
| 571 | * driver will put a command into. |
| 572 | */ |
| 573 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 574 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 | } |
| 576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 577 | /** |
| 578 | * lpfc_sli_update_full_ring: Update the chip attention register. |
| 579 | * @phba: Pointer to HBA context object. |
| 580 | * @pring: Pointer to driver SLI ring object. |
| 581 | * |
| 582 | * The caller is not required to hold any lock for calling this function. |
| 583 | * This function updates the chip attention bits for the ring to inform firmware |
| 584 | * that there are pending work to be done for this ring and requests an |
| 585 | * interrupt when there is space available in the ring. This function is |
| 586 | * called when the driver is unable to post more iocbs to the ring due |
| 587 | * to unavailability of space in the ring. |
| 588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | { |
| 592 | int ringno = pring->ringno; |
| 593 | |
| 594 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 595 | |
| 596 | wmb(); |
| 597 | |
| 598 | /* |
| 599 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 600 | * The HBA will tell us when an IOCB entry is available. |
| 601 | */ |
| 602 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 603 | readl(phba->CAregaddr); /* flush */ |
| 604 | |
| 605 | pring->stats.iocb_cmd_full++; |
| 606 | } |
| 607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 608 | /** |
| 609 | * lpfc_sli_update_ring: Update chip attention register. |
| 610 | * @phba: Pointer to HBA context object. |
| 611 | * @pring: Pointer to driver SLI ring object. |
| 612 | * |
| 613 | * This function updates the chip attention register bit for the |
| 614 | * given ring to inform HBA that there is more work to be done |
| 615 | * in this ring. The caller is not required to hold any lock. |
| 616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | { |
| 620 | int ringno = pring->ringno; |
| 621 | |
| 622 | /* |
| 623 | * Tell the HBA that there is work to do in this ring. |
| 624 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 625 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 626 | wmb(); |
| 627 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 628 | readl(phba->CAregaddr); /* flush */ |
| 629 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 630 | } |
| 631 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 632 | /** |
| 633 | * lpfc_sli_resume_iocb: Process iocbs in the txq. |
| 634 | * @phba: Pointer to HBA context object. |
| 635 | * @pring: Pointer to driver SLI ring object. |
| 636 | * |
| 637 | * This function is called with hbalock held to post pending iocbs |
| 638 | * in the txq to the firmware. This function is called when driver |
| 639 | * detects space available in the ring. |
| 640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 642 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | { |
| 644 | IOCB_t *iocb; |
| 645 | struct lpfc_iocbq *nextiocb; |
| 646 | |
| 647 | /* |
| 648 | * Check to see if: |
| 649 | * (a) there is anything on the txq to send |
| 650 | * (b) link is up |
| 651 | * (c) link attention events can be processed (fcp ring only) |
| 652 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 653 | */ |
| 654 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 657 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
| 659 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 660 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 661 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 662 | |
| 663 | if (iocb) |
| 664 | lpfc_sli_update_ring(phba, pring); |
| 665 | else |
| 666 | lpfc_sli_update_full_ring(phba, pring); |
| 667 | } |
| 668 | |
| 669 | return; |
| 670 | } |
| 671 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 672 | /** |
| 673 | * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ. |
| 674 | * @phba: Pointer to HBA context object. |
| 675 | * @hbqno: HBQ number. |
| 676 | * |
| 677 | * This function is called with hbalock held to get the next |
| 678 | * available slot for the given HBQ. If there is free slot |
| 679 | * available for the HBQ it will return pointer to the next available |
| 680 | * HBQ entry else it will return NULL. |
| 681 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 682 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 683 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 684 | { |
| 685 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 686 | |
| 687 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 688 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 689 | hbqp->next_hbqPutIdx = 0; |
| 690 | |
| 691 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 692 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 693 | uint32_t getidx = le32_to_cpu(raw_index); |
| 694 | |
| 695 | hbqp->local_hbqGetIdx = getidx; |
| 696 | |
| 697 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 698 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 699 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 700 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 701 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 702 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 703 | hbqp->entry_count); |
| 704 | |
| 705 | phba->link_state = LPFC_HBA_ERROR; |
| 706 | return NULL; |
| 707 | } |
| 708 | |
| 709 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 710 | return NULL; |
| 711 | } |
| 712 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 713 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 714 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 715 | } |
| 716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 717 | /** |
| 718 | * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers. |
| 719 | * @phba: Pointer to HBA context object. |
| 720 | * |
| 721 | * This function is called with no lock held to free all the |
| 722 | * hbq buffers while uninitializing the SLI interface. It also |
| 723 | * frees the HBQ buffers returned by the firmware but not yet |
| 724 | * processed by the upper layers. |
| 725 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 726 | void |
| 727 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 728 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 729 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 730 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 731 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 732 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 733 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 734 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 735 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 736 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 737 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 738 | for (i = 0; i < hbq_count; ++i) { |
| 739 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 740 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 741 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 742 | list_del(&hbq_buf->dbuf.list); |
| 743 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 744 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 745 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 746 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 747 | /* Return all HBQ buffer that are in-fly */ |
| 748 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 749 | &phba->hbqbuf_in_list, list) { |
| 750 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 751 | list_del(&hbq_buf->dbuf.list); |
| 752 | if (hbq_buf->tag == -1) { |
| 753 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 754 | (phba, hbq_buf); |
| 755 | } else { |
| 756 | hbqno = hbq_buf->tag >> 16; |
| 757 | if (hbqno >= LPFC_MAX_HBQS) |
| 758 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 759 | (phba, hbq_buf); |
| 760 | else |
| 761 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 762 | hbq_buf); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* Mark the HBQs not in use */ |
| 767 | phba->hbq_in_use = 0; |
| 768 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 769 | } |
| 770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 771 | /** |
| 772 | * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware. |
| 773 | * @phba: Pointer to HBA context object. |
| 774 | * @hbqno: HBQ number. |
| 775 | * @hbq_buf: Pointer to HBQ buffer. |
| 776 | * |
| 777 | * This function is called with the hbalock held to post a |
| 778 | * hbq buffer to the firmware. If the function finds an empty |
| 779 | * slot in the HBQ, it will post the buffer. The function will return |
| 780 | * pointer to the hbq entry if it successfully post the buffer |
| 781 | * else it will return NULL. |
| 782 | **/ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 783 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 784 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 785 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | { |
| 787 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 789 | |
| 790 | /* Get next HBQ entry slot to use */ |
| 791 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 792 | if (hbqe) { |
| 793 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 794 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 795 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 796 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 797 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 798 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 799 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 800 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 801 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 802 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 803 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 804 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 805 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 806 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 807 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 808 | return hbqe; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 809 | } |
| 810 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 811 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 812 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 813 | .rn = 1, |
| 814 | .entry_count = 200, |
| 815 | .mask_count = 0, |
| 816 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 817 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | .buffer_count = 0, |
| 819 | .init_count = 20, |
| 820 | .add_count = 5, |
| 821 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 822 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 823 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 824 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 825 | .rn = 1, |
| 826 | .entry_count = 200, |
| 827 | .mask_count = 0, |
| 828 | .profile = 0, |
| 829 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 830 | .buffer_count = 0, |
| 831 | .init_count = 0, |
| 832 | .add_count = 5, |
| 833 | }; |
| 834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 835 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 836 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 838 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 839 | }; |
| 840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 841 | /** |
| 842 | * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ. |
| 843 | * @phba: Pointer to HBA context object. |
| 844 | * @hbqno: HBQ number. |
| 845 | * @count: Number of HBQ buffers to be posted. |
| 846 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 847 | * This function is called with no lock held to post more hbq buffers to the |
| 848 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 849 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 850 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 851 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 852 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 853 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 854 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 855 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 856 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 857 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 858 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 859 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 860 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 861 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 862 | lpfc_hbq_defs[hbqno]->entry_count) |
| 863 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 864 | phba->hbqs[hbqno].buffer_count; |
| 865 | if (!count) |
| 866 | return 0; |
| 867 | /* Allocate HBQ entries */ |
| 868 | for (i = 0; i < count; i++) { |
| 869 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 870 | if (!hbq_buffer) |
| 871 | break; |
| 872 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 873 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 874 | /* Check whether HBQ is still in use */ |
| 875 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 876 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 877 | goto err; |
| 878 | while (!list_empty(&hbq_buf_list)) { |
| 879 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 880 | dbuf.list); |
| 881 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 882 | (hbqno << 16)); |
| 883 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 884 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 885 | posted++; |
| 886 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 887 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 888 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 889 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 890 | return posted; |
| 891 | err: |
| 892 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 893 | while (!list_empty(&hbq_buf_list)) { |
| 894 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 895 | dbuf.list); |
| 896 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 897 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 899 | } |
| 900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 901 | /** |
| 902 | * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware. |
| 903 | * @phba: Pointer to HBA context object. |
| 904 | * @qno: HBQ number. |
| 905 | * |
| 906 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 907 | * is called with no lock held. The function returns the number of HBQ entries |
| 908 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 909 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 910 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 911 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 912 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 913 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 914 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 915 | } |
| 916 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 917 | /** |
| 918 | * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ. |
| 919 | * @phba: Pointer to HBA context object. |
| 920 | * @qno: HBQ queue number. |
| 921 | * |
| 922 | * This function is called from SLI initialization code path with |
| 923 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 924 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 925 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 926 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 927 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 928 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 929 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 930 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 931 | } |
| 932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 933 | /** |
| 934 | * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag. |
| 935 | * @phba: Pointer to HBA context object. |
| 936 | * @tag: Tag of the hbq buffer. |
| 937 | * |
| 938 | * This function is called with hbalock held. This function searches |
| 939 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 940 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 941 | * it returns NULL. |
| 942 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 943 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 944 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 945 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 946 | struct lpfc_dmabuf *d_buf; |
| 947 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 948 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 949 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 950 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 951 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 952 | return NULL; |
| 953 | |
| 954 | 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] | 955 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 956 | if (hbq_buf->tag == tag) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 957 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 958 | } |
| 959 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 960 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 961 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 962 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 964 | } |
| 965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 966 | /** |
| 967 | * lpfc_sli_free_hbq: Give back the hbq buffer to firmware. |
| 968 | * @phba: Pointer to HBA context object. |
| 969 | * @hbq_buffer: Pointer to HBQ buffer. |
| 970 | * |
| 971 | * This function is called with hbalock. This function gives back |
| 972 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 973 | * post the buffer, it will free the buffer. |
| 974 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 975 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 976 | 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] | 977 | { |
| 978 | uint32_t hbqno; |
| 979 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 980 | if (hbq_buffer) { |
| 981 | hbqno = hbq_buffer->tag >> 16; |
| 982 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
| 983 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 984 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 988 | /** |
| 989 | * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox. |
| 990 | * @mbxCommand: mailbox command code. |
| 991 | * |
| 992 | * This function is called by the mailbox event handler function to verify |
| 993 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 994 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 995 | * and the mailbox event handler will take the HBA offline. |
| 996 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | static int |
| 998 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 999 | { |
| 1000 | uint8_t ret; |
| 1001 | |
| 1002 | switch (mbxCommand) { |
| 1003 | case MBX_LOAD_SM: |
| 1004 | case MBX_READ_NV: |
| 1005 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1006 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | case MBX_RUN_BIU_DIAG: |
| 1008 | case MBX_INIT_LINK: |
| 1009 | case MBX_DOWN_LINK: |
| 1010 | case MBX_CONFIG_LINK: |
| 1011 | case MBX_CONFIG_RING: |
| 1012 | case MBX_RESET_RING: |
| 1013 | case MBX_READ_CONFIG: |
| 1014 | case MBX_READ_RCONFIG: |
| 1015 | case MBX_READ_SPARM: |
| 1016 | case MBX_READ_STATUS: |
| 1017 | case MBX_READ_RPI: |
| 1018 | case MBX_READ_XRI: |
| 1019 | case MBX_READ_REV: |
| 1020 | case MBX_READ_LNK_STAT: |
| 1021 | case MBX_REG_LOGIN: |
| 1022 | case MBX_UNREG_LOGIN: |
| 1023 | case MBX_READ_LA: |
| 1024 | case MBX_CLEAR_LA: |
| 1025 | case MBX_DUMP_MEMORY: |
| 1026 | case MBX_DUMP_CONTEXT: |
| 1027 | case MBX_RUN_DIAGS: |
| 1028 | case MBX_RESTART: |
| 1029 | case MBX_UPDATE_CFG: |
| 1030 | case MBX_DOWN_LOAD: |
| 1031 | case MBX_DEL_LD_ENTRY: |
| 1032 | case MBX_RUN_PROGRAM: |
| 1033 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1034 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1036 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1038 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | case MBX_LOAD_AREA: |
| 1040 | case MBX_RUN_BIU_DIAG64: |
| 1041 | case MBX_CONFIG_PORT: |
| 1042 | case MBX_READ_SPARM64: |
| 1043 | case MBX_READ_RPI64: |
| 1044 | case MBX_REG_LOGIN64: |
| 1045 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1046 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | case MBX_SET_DEBUG: |
| 1048 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1049 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1050 | case MBX_REG_VPI: |
| 1051 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1052 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1053 | case MBX_PORT_CAPABILITIES: |
| 1054 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | ret = mbxCommand; |
| 1056 | break; |
| 1057 | default: |
| 1058 | ret = MBX_SHUTDOWN; |
| 1059 | break; |
| 1060 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1061 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1063 | |
| 1064 | /** |
| 1065 | * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from |
| 1066 | * lpfc_sli_issue_mbox_wait. |
| 1067 | * @phba: Pointer to HBA context object. |
| 1068 | * @pmboxq: Pointer to mailbox command. |
| 1069 | * |
| 1070 | * This is completion handler function for mailbox commands issued from |
| 1071 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1072 | * mailbox event handler function with no lock held. This function |
| 1073 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1074 | * of the mailbox. |
| 1075 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1077 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | { |
| 1079 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1080 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | /* |
| 1083 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1084 | * continued running. |
| 1085 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1086 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1087 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1089 | if (pdone_q) |
| 1090 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1091 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | return; |
| 1093 | } |
| 1094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1095 | |
| 1096 | /** |
| 1097 | * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler. |
| 1098 | * @phba: Pointer to HBA context object. |
| 1099 | * @pmb: Pointer to mailbox object. |
| 1100 | * |
| 1101 | * This function is the default mailbox completion handler. It |
| 1102 | * frees the memory resources associated with the completed mailbox |
| 1103 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1104 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1105 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1107 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | { |
| 1109 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1110 | uint16_t rpi; |
| 1111 | int rc; |
| 1112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | if (mp) { |
| 1116 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1117 | kfree(mp); |
| 1118 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1119 | |
| 1120 | /* |
| 1121 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1122 | * is in re-discovery driver need to cleanup the RPI. |
| 1123 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1124 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1125 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1126 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1127 | |
| 1128 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1129 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1130 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1131 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1132 | if (rc != MBX_NOT_FINISHED) |
| 1133 | return; |
| 1134 | } |
| 1135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1136 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1137 | return; |
| 1138 | } |
| 1139 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1140 | /** |
| 1141 | * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware. |
| 1142 | * @phba: Pointer to HBA context object. |
| 1143 | * |
| 1144 | * This function is called with no lock held. This function processes all |
| 1145 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1146 | * service routine processes mailbox completion interrupt and adds completed |
| 1147 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1148 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1149 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1150 | * function returns the mailbox commands to the upper layer by calling the |
| 1151 | * completion handler function of each mailbox. |
| 1152 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1154 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1156 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1158 | int rc; |
| 1159 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | |
| 1161 | phba->sli.slistat.mbox_event++; |
| 1162 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1163 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1164 | spin_lock_irq(&phba->hbalock); |
| 1165 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1166 | spin_unlock_irq(&phba->hbalock); |
| 1167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1169 | do { |
| 1170 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1171 | if (pmb == NULL) |
| 1172 | break; |
| 1173 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1176 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1177 | if (pmb->vport) { |
| 1178 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1179 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1180 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1181 | (uint32_t)pmbox->mbxCommand, |
| 1182 | pmbox->un.varWords[0], |
| 1183 | pmbox->un.varWords[1]); |
| 1184 | } |
| 1185 | else { |
| 1186 | lpfc_debugfs_disc_trc(phba->pport, |
| 1187 | LPFC_DISC_TRC_MBOX, |
| 1188 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1189 | (uint32_t)pmbox->mbxCommand, |
| 1190 | pmbox->un.varWords[0], |
| 1191 | pmbox->un.varWords[1]); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | /* |
| 1196 | * It is a fatal error if unknown mbox command completion. |
| 1197 | */ |
| 1198 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1199 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1201 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1202 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1203 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1204 | pmb->vport ? pmb->vport->vpi : 0, |
| 1205 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1206 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | phba->work_hs = HS_FFER3; |
| 1208 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1209 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | if (pmbox->mbxStatus) { |
| 1213 | phba->sli.slistat.mbox_stat_err++; |
| 1214 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1215 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1216 | lpfc_printf_log(phba, KERN_INFO, |
| 1217 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1218 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1219 | "error - RETRYing Data: x%x " |
| 1220 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1221 | pmb->vport ? pmb->vport->vpi :0, |
| 1222 | pmbox->mbxCommand, |
| 1223 | pmbox->mbxStatus, |
| 1224 | pmbox->un.varWords[0], |
| 1225 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | pmbox->mbxStatus = 0; |
| 1227 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1230 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1232 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1233 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1238 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1239 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1240 | "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] | 1241 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1242 | pmbox->mbxCommand, |
| 1243 | pmb->mbox_cmpl, |
| 1244 | *((uint32_t *) pmbox), |
| 1245 | pmbox->un.varWords[0], |
| 1246 | pmbox->un.varWords[1], |
| 1247 | pmbox->un.varWords[2], |
| 1248 | pmbox->un.varWords[3], |
| 1249 | pmbox->un.varWords[4], |
| 1250 | pmbox->un.varWords[5], |
| 1251 | pmbox->un.varWords[6], |
| 1252 | pmbox->un.varWords[7]); |
| 1253 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1254 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1255 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1256 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1257 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1259 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1260 | /** |
| 1261 | * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer. |
| 1262 | * @phba: Pointer to HBA context object. |
| 1263 | * @tag: Tag for the HBQ buffer. |
| 1264 | * |
| 1265 | * This function is called from unsolicited event handler code path to get the |
| 1266 | * HBQ buffer associated with an unsolicited iocb. This function is called with |
| 1267 | * 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] | 1268 | * another buffer to the firmware. Note that the new buffer must be allocated |
| 1269 | * before taking the hbalock and that the hba lock must be held until it is |
| 1270 | * finished with the hbq entry swap. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1271 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1272 | static struct lpfc_dmabuf * |
| 1273 | lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) |
| 1274 | { |
| 1275 | struct hbq_dmabuf *hbq_entry, *new_hbq_entry; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1276 | uint32_t hbqno; |
| 1277 | void *virt; /* virtual address ptr */ |
| 1278 | dma_addr_t phys; /* mapped address */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1279 | unsigned long flags; |
| 1280 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1281 | hbqno = tag >> 16; |
| 1282 | new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1283 | /* Check whether HBQ is still in use */ |
| 1284 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1285 | if (!phba->hbq_in_use) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1286 | if (new_hbq_entry) |
| 1287 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1288 | new_hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1289 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1290 | return NULL; |
| 1291 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1292 | |
| 1293 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1294 | if (hbq_entry == NULL) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1295 | if (new_hbq_entry) |
| 1296 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1297 | new_hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1298 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1299 | return NULL; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1300 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1301 | list_del(&hbq_entry->dbuf.list); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1302 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1303 | if (new_hbq_entry == NULL) { |
| 1304 | list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1305 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1306 | return &hbq_entry->dbuf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1307 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1308 | new_hbq_entry->tag = -1; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1309 | phys = new_hbq_entry->dbuf.phys; |
| 1310 | virt = new_hbq_entry->dbuf.virt; |
| 1311 | new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys; |
| 1312 | new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt; |
| 1313 | hbq_entry->dbuf.phys = phys; |
| 1314 | hbq_entry->dbuf.virt = virt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1315 | lpfc_sli_free_hbq(phba, hbq_entry); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1316 | list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
| 1317 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1319 | return &new_hbq_entry->dbuf; |
| 1320 | } |
| 1321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1322 | /** |
| 1323 | * lpfc_sli_get_buff: Get the buffer associated with the buffer tag. |
| 1324 | * @phba: Pointer to HBA context object. |
| 1325 | * @pring: Pointer to driver SLI ring object. |
| 1326 | * @tag: buffer tag. |
| 1327 | * |
| 1328 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1329 | * is set in the tag the buffer is posted for a particular exchange, |
| 1330 | * the function will return the buffer without replacing the buffer. |
| 1331 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1332 | * returns the buffer and also posts another buffer to the firmware. |
| 1333 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1334 | static struct lpfc_dmabuf * |
| 1335 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
| 1336 | struct lpfc_sli_ring *pring, |
| 1337 | uint32_t tag) |
| 1338 | { |
| 1339 | if (tag & QUE_BUFTAG_BIT) |
| 1340 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
| 1341 | else |
| 1342 | return lpfc_sli_replace_hbqbuff(phba, tag); |
| 1343 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1344 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1345 | |
| 1346 | /** |
| 1347 | * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler. |
| 1348 | * @phba: Pointer to HBA context object. |
| 1349 | * @pring: Pointer to driver SLI ring object. |
| 1350 | * @saveq: Pointer to the unsolicited iocb. |
| 1351 | * |
| 1352 | * This function is called with no lock held by the ring event handler |
| 1353 | * when there is an unsolicited iocb posted to the response ring by the |
| 1354 | * firmware. This function gets the buffer associated with the iocbs |
| 1355 | * and calls the event handler for the ring. This function handles both |
| 1356 | * qring buffers and hbq buffers. |
| 1357 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1358 | * upper layer functions will free the iocb objects. |
| 1359 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | static int |
| 1361 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1362 | struct lpfc_iocbq *saveq) |
| 1363 | { |
| 1364 | IOCB_t * irsp; |
| 1365 | WORD5 * w5p; |
| 1366 | uint32_t Rctl, Type; |
| 1367 | uint32_t match, i; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1368 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1369 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | |
| 1371 | match = 0; |
| 1372 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1373 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1374 | if (irsp->ulpStatus == IOSTAT_NEED_BUFFER) |
| 1375 | return 1; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1376 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1377 | if (pring->lpfc_sli_rcv_async_status) |
| 1378 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1379 | else |
| 1380 | lpfc_printf_log(phba, |
| 1381 | KERN_WARNING, |
| 1382 | LOG_SLI, |
| 1383 | "0316 Ring %d handler: unexpected " |
| 1384 | "ASYNC_STATUS iocb received evt_code " |
| 1385 | "0x%x\n", |
| 1386 | pring->ringno, |
| 1387 | irsp->un.asyncstat.evt_code); |
| 1388 | return 1; |
| 1389 | } |
| 1390 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1391 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1392 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1393 | if (irsp->ulpBdeCount > 0) { |
| 1394 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1395 | irsp->un.ulpWord[3]); |
| 1396 | lpfc_in_buf_free(phba, dmzbuf); |
| 1397 | } |
| 1398 | |
| 1399 | if (irsp->ulpBdeCount > 1) { |
| 1400 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1401 | irsp->unsli3.sli3Words[3]); |
| 1402 | lpfc_in_buf_free(phba, dmzbuf); |
| 1403 | } |
| 1404 | |
| 1405 | if (irsp->ulpBdeCount > 2) { |
| 1406 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1407 | irsp->unsli3.sli3Words[7]); |
| 1408 | lpfc_in_buf_free(phba, dmzbuf); |
| 1409 | } |
| 1410 | |
| 1411 | return 1; |
| 1412 | } |
| 1413 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1414 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1415 | if (irsp->ulpBdeCount != 0) { |
| 1416 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1417 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1418 | if (!saveq->context2) |
| 1419 | lpfc_printf_log(phba, |
| 1420 | KERN_ERR, |
| 1421 | LOG_SLI, |
| 1422 | "0341 Ring %d Cannot find buffer for " |
| 1423 | "an unsolicited iocb. tag 0x%x\n", |
| 1424 | pring->ringno, |
| 1425 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1426 | } |
| 1427 | if (irsp->ulpBdeCount == 2) { |
| 1428 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1429 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1430 | if (!saveq->context3) |
| 1431 | lpfc_printf_log(phba, |
| 1432 | KERN_ERR, |
| 1433 | LOG_SLI, |
| 1434 | "0342 Ring %d Cannot find buffer for an" |
| 1435 | " unsolicited iocb. tag 0x%x\n", |
| 1436 | pring->ringno, |
| 1437 | irsp->unsli3.sli3Words[7]); |
| 1438 | } |
| 1439 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1440 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1441 | if (irsp->ulpBdeCount != 0) { |
| 1442 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1443 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1444 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1445 | lpfc_printf_log(phba, |
| 1446 | KERN_ERR, |
| 1447 | LOG_SLI, |
| 1448 | "0343 Ring %d Cannot find " |
| 1449 | "buffer for an unsolicited iocb" |
| 1450 | ". tag 0x%x\n", pring->ringno, |
| 1451 | irsp->un.ulpWord[3]); |
| 1452 | } |
| 1453 | if (irsp->ulpBdeCount == 2) { |
| 1454 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1455 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1456 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1457 | lpfc_printf_log(phba, |
| 1458 | KERN_ERR, |
| 1459 | LOG_SLI, |
| 1460 | "0344 Ring %d Cannot find " |
| 1461 | "buffer for an unsolicited " |
| 1462 | "iocb. tag 0x%x\n", |
| 1463 | pring->ringno, |
| 1464 | irsp->unsli3.sli3Words[7]); |
| 1465 | } |
| 1466 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1467 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1468 | if (irsp->ulpBdeCount != 0 && |
| 1469 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1470 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1471 | int found = 0; |
| 1472 | |
| 1473 | /* search continue save q for same XRI */ |
| 1474 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1475 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1476 | list_add_tail(&saveq->list, &iocbq->list); |
| 1477 | found = 1; |
| 1478 | break; |
| 1479 | } |
| 1480 | } |
| 1481 | if (!found) |
| 1482 | list_add_tail(&saveq->clist, |
| 1483 | &pring->iocb_continue_saveq); |
| 1484 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1485 | list_del_init(&iocbq->clist); |
| 1486 | saveq = iocbq; |
| 1487 | irsp = &(saveq->iocb); |
| 1488 | } else |
| 1489 | return 0; |
| 1490 | } |
| 1491 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1492 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1493 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1494 | Rctl = FC_ELS_REQ; |
| 1495 | Type = FC_ELS_DATA; |
| 1496 | } else { |
| 1497 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1498 | Rctl = w5p->hcsw.Rctl; |
| 1499 | Type = w5p->hcsw.Type; |
| 1500 | |
| 1501 | /* Firmware Workaround */ |
| 1502 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1503 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1504 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1505 | Rctl = FC_ELS_REQ; |
| 1506 | Type = FC_ELS_DATA; |
| 1507 | w5p->hcsw.Rctl = Rctl; |
| 1508 | w5p->hcsw.Type = Type; |
| 1509 | } |
| 1510 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | /* unSolicited Responses */ |
| 1513 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1514 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1515 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1516 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | match = 1; |
| 1518 | } else { |
| 1519 | /* We must search, based on rctl / type |
| 1520 | for the right routine */ |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1521 | for (i = 0; i < pring->num_mask; i++) { |
| 1522 | if ((pring->prt[i].rctl == Rctl) |
| 1523 | && (pring->prt[i].type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1524 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1525 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1526 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | match = 1; |
| 1528 | break; |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | if (match == 0) { |
| 1533 | /* Unexpected Rctl / Type received */ |
| 1534 | /* Ring <ringno> handler: unexpected |
| 1535 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1536 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1537 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1538 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1539 | pring->ringno, Rctl, Type); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1541 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | } |
| 1543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1544 | /** |
| 1545 | * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb. |
| 1546 | * @phba: Pointer to HBA context object. |
| 1547 | * @pring: Pointer to driver SLI ring object. |
| 1548 | * @prspiocb: Pointer to response iocb object. |
| 1549 | * |
| 1550 | * This function looks up the iocb_lookup table to get the command iocb |
| 1551 | * corresponding to the given response iocb using the iotag of the |
| 1552 | * response iocb. This function is called with the hbalock held. |
| 1553 | * This function returns the command iocb object if it finds the command |
| 1554 | * iocb else returns NULL. |
| 1555 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1558 | struct lpfc_sli_ring *pring, |
| 1559 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1562 | uint16_t iotag; |
| 1563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1564 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1566 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1567 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1568 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1569 | pring->txcmplq_cnt--; |
| 1570 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | } |
| 1572 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1573 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1574 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1575 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1576 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1577 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | return NULL; |
| 1579 | } |
| 1580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1581 | /** |
| 1582 | * lpfc_sli_process_sol_iocb: process solicited iocb completion. |
| 1583 | * @phba: Pointer to HBA context object. |
| 1584 | * @pring: Pointer to driver SLI ring object. |
| 1585 | * @saveq: Pointer to the response iocb to be processed. |
| 1586 | * |
| 1587 | * This function is called by the ring event handler for non-fcp |
| 1588 | * rings when there is a new response iocb in the response ring. |
| 1589 | * The caller is not required to hold any locks. This function |
| 1590 | * gets the command iocb associated with the response iocb and |
| 1591 | * calls the completion handler for the command iocb. If there |
| 1592 | * is no completion handler, the function will free the resources |
| 1593 | * associated with command iocb. If the response iocb is for |
| 1594 | * an already aborted command iocb, the status of the completion |
| 1595 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1596 | * This function always returns 1. |
| 1597 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1599 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | struct lpfc_iocbq *saveq) |
| 1601 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | int rc = 1; |
| 1604 | unsigned long iflag; |
| 1605 | |
| 1606 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1607 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1608 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1609 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1610 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | if (cmdiocbp) { |
| 1612 | if (cmdiocbp->iocb_cmpl) { |
| 1613 | /* |
| 1614 | * Post all ELS completions to the worker thread. |
| 1615 | * All other are passed to the completion callback. |
| 1616 | */ |
| 1617 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1618 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1619 | cmdiocbp->iocb_flag &= |
| 1620 | ~LPFC_DRIVER_ABORTED; |
| 1621 | saveq->iocb.ulpStatus = |
| 1622 | IOSTAT_LOCAL_REJECT; |
| 1623 | saveq->iocb.un.ulpWord[4] = |
| 1624 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1625 | |
| 1626 | /* Firmware could still be in progress |
| 1627 | * of DMAing payload, so don't free data |
| 1628 | * buffer till after a hbeat. |
| 1629 | */ |
| 1630 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1632 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1634 | } else |
| 1635 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | } else { |
| 1637 | /* |
| 1638 | * Unknown initiating command based on the response iotag. |
| 1639 | * This could be the case on the ELS ring because of |
| 1640 | * lpfc_els_abort(). |
| 1641 | */ |
| 1642 | if (pring->ringno != LPFC_ELS_RING) { |
| 1643 | /* |
| 1644 | * Ring <ringno> handler: unexpected completion IoTag |
| 1645 | * <IoTag> |
| 1646 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1647 | lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI, |
| 1648 | "0322 Ring %d handler: " |
| 1649 | "unexpected completion IoTag x%x " |
| 1650 | "Data: x%x x%x x%x x%x\n", |
| 1651 | pring->ringno, |
| 1652 | saveq->iocb.ulpIoTag, |
| 1653 | saveq->iocb.ulpStatus, |
| 1654 | saveq->iocb.un.ulpWord[4], |
| 1655 | saveq->iocb.ulpCommand, |
| 1656 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | } |
| 1658 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1659 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | return rc; |
| 1661 | } |
| 1662 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1663 | /** |
| 1664 | * lpfc_sli_rsp_pointers_error: Response ring pointer error handler. |
| 1665 | * @phba: Pointer to HBA context object. |
| 1666 | * @pring: Pointer to driver SLI ring object. |
| 1667 | * |
| 1668 | * This function is called from the iocb ring event handlers when |
| 1669 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1670 | * an error attention condition to the worker thread and the worker |
| 1671 | * thread will transition the HBA to offline state. |
| 1672 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | static void |
| 1674 | 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] | 1675 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1676 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1677 | /* |
| 1678 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 1679 | * rsp ring <portRspMax> |
| 1680 | */ |
| 1681 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1682 | "0312 Ring %d handler: portRspPut %d " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1683 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1684 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1685 | pring->numRiocb); |
| 1686 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1687 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1688 | |
| 1689 | /* |
| 1690 | * All error attention handlers are posted to |
| 1691 | * worker thread |
| 1692 | */ |
| 1693 | phba->work_ha |= HA_ERATT; |
| 1694 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1695 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1696 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1697 | |
| 1698 | return; |
| 1699 | } |
| 1700 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1701 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 1702 | * lpfc_poll_eratt: Error attention polling timer timeout handler. |
| 1703 | * @ptr: Pointer to address of HBA context object. |
| 1704 | * |
| 1705 | * This function is invoked by the Error Attention polling timer when the |
| 1706 | * timer times out. It will check the SLI Error Attention register for |
| 1707 | * possible attention events. If so, it will post an Error Attention event |
| 1708 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1709 | * Error Attention polling timer for the next poll. |
| 1710 | **/ |
| 1711 | void lpfc_poll_eratt(unsigned long ptr) |
| 1712 | { |
| 1713 | struct lpfc_hba *phba; |
| 1714 | uint32_t eratt = 0; |
| 1715 | |
| 1716 | phba = (struct lpfc_hba *)ptr; |
| 1717 | |
| 1718 | /* Check chip HA register for error event */ |
| 1719 | eratt = lpfc_sli_check_eratt(phba); |
| 1720 | |
| 1721 | if (eratt) |
| 1722 | /* Tell the worker thread there is work to do */ |
| 1723 | lpfc_worker_wake_up(phba); |
| 1724 | else |
| 1725 | /* Restart the timer for next eratt poll */ |
| 1726 | mod_timer(&phba->eratt_poll, jiffies + |
| 1727 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1728 | return; |
| 1729 | } |
| 1730 | |
| 1731 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1732 | * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode. |
| 1733 | * @phba: Pointer to HBA context object. |
| 1734 | * |
| 1735 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1736 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1737 | * is enabled. |
| 1738 | * |
| 1739 | * The caller does not hold any lock. |
| 1740 | * The function processes each response iocb in the response ring until it |
| 1741 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1742 | * LE bit set. The function will call the completion handler of the command iocb |
| 1743 | * if the response iocb indicates a completion for a command iocb or it is |
| 1744 | * an abort completion. |
| 1745 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1747 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1748 | struct lpfc_sli *psli = &phba->sli; |
| 1749 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1750 | IOCB_t *irsp = NULL; |
| 1751 | IOCB_t *entry = NULL; |
| 1752 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1753 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1754 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1755 | uint32_t status; |
| 1756 | uint32_t portRspPut, portRspMax; |
| 1757 | int type; |
| 1758 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1759 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1761 | |
| 1762 | pring->stats.iocb_event++; |
| 1763 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1764 | /* |
| 1765 | * The next available response entry should never exceed the maximum |
| 1766 | * entries. If it does, treat it as an adapter hardware error. |
| 1767 | */ |
| 1768 | portRspMax = pring->numRiocb; |
| 1769 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1770 | if (unlikely(portRspPut >= portRspMax)) { |
| 1771 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1772 | return; |
| 1773 | } |
| 1774 | |
| 1775 | rmb(); |
| 1776 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1777 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1778 | if (++pring->rspidx >= portRspMax) |
| 1779 | pring->rspidx = 0; |
| 1780 | |
| 1781 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1782 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1783 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1784 | irsp = &rspiocbq.iocb; |
| 1785 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1786 | pring->stats.iocb_rsp++; |
| 1787 | rsp_cmpl++; |
| 1788 | |
| 1789 | if (unlikely(irsp->ulpStatus)) { |
| 1790 | /* Rsp ring <ringno> error: IOCB */ |
| 1791 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1792 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1793 | "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] | 1794 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1795 | irsp->un.ulpWord[0], |
| 1796 | irsp->un.ulpWord[1], |
| 1797 | irsp->un.ulpWord[2], |
| 1798 | irsp->un.ulpWord[3], |
| 1799 | irsp->un.ulpWord[4], |
| 1800 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1801 | *(uint32_t *)&irsp->un1, |
| 1802 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | switch (type) { |
| 1806 | case LPFC_ABORT_IOCB: |
| 1807 | case LPFC_SOL_IOCB: |
| 1808 | /* |
| 1809 | * Idle exchange closed via ABTS from port. No iocb |
| 1810 | * resources need to be recovered. |
| 1811 | */ |
| 1812 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1813 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1814 | "0314 IOCB cmd 0x%x " |
| 1815 | "processed. Skipping " |
| 1816 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1817 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1818 | break; |
| 1819 | } |
| 1820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1822 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1823 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1824 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1825 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1826 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1827 | &rspiocbq); |
| 1828 | } |
| 1829 | break; |
| 1830 | default: |
| 1831 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1832 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1833 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1834 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1835 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1836 | dev_warn(&((phba->pcidev)->dev), |
| 1837 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1838 | phba->brd_no, adaptermsg); |
| 1839 | } else { |
| 1840 | /* Unknown IOCB command */ |
| 1841 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1842 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1843 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1844 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1845 | irsp->ulpStatus, |
| 1846 | irsp->ulpIoTag, |
| 1847 | irsp->ulpContext); |
| 1848 | } |
| 1849 | break; |
| 1850 | } |
| 1851 | |
| 1852 | /* |
| 1853 | * The response IOCB has been processed. Update the ring |
| 1854 | * pointer in SLIM. If the port response put pointer has not |
| 1855 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1856 | * response put pointer. |
| 1857 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1858 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1859 | |
| 1860 | if (pring->rspidx == portRspPut) |
| 1861 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1862 | } |
| 1863 | |
| 1864 | ha_copy = readl(phba->HAregaddr); |
| 1865 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1866 | |
| 1867 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1869 | pring->stats.iocb_rsp_full++; |
| 1870 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1871 | writel(status, phba->CAregaddr); |
| 1872 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1873 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1874 | } |
| 1875 | if ((ha_copy & HA_R0CE_RSP) && |
| 1876 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1878 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1879 | pring->stats.iocb_cmd_empty++; |
| 1880 | |
| 1881 | /* Force update of the local copy of cmdGetInx */ |
| 1882 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1883 | lpfc_sli_resume_iocb(phba, pring); |
| 1884 | |
| 1885 | if ((pring->lpfc_sli_cmd_available)) |
| 1886 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1887 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | return; |
| 1892 | } |
| 1893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1894 | /** |
| 1895 | * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring. |
| 1896 | * @phba: Pointer to HBA context object. |
| 1897 | * @pring: Pointer to driver SLI ring object. |
| 1898 | * @mask: Host attention register mask for this ring. |
| 1899 | * |
| 1900 | * This function is called from the interrupt context when there is a ring |
| 1901 | * event for the fcp ring. The caller does not hold any lock. |
| 1902 | * The function processes each response iocb in the response ring until it |
| 1903 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1904 | * LE bit set. The function will call the completion handler of the command iocb |
| 1905 | * if the response iocb indicates a completion for a command iocb or it is |
| 1906 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1907 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1909 | * to check it explicitly. This function always returns 1. |
| 1910 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1912 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1913 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1915 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1917 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1919 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | uint32_t status; |
| 1921 | uint32_t portRspPut, portRspMax; |
| 1922 | int rc = 1; |
| 1923 | lpfc_iocb_type type; |
| 1924 | unsigned long iflag; |
| 1925 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | pring->stats.iocb_event++; |
| 1929 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1930 | /* |
| 1931 | * The next available response entry should never exceed the maximum |
| 1932 | * entries. If it does, treat it as an adapter hardware error. |
| 1933 | */ |
| 1934 | portRspMax = pring->numRiocb; |
| 1935 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1936 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1937 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1938 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | return 1; |
| 1940 | } |
| 1941 | |
| 1942 | rmb(); |
| 1943 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1944 | /* |
| 1945 | * Fetch an entry off the ring and copy it into a local data |
| 1946 | * structure. The copy involves a byte-swap since the |
| 1947 | * network byte order and pci byte orders are different. |
| 1948 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1949 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1950 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1951 | |
| 1952 | if (++pring->rspidx >= portRspMax) |
| 1953 | pring->rspidx = 0; |
| 1954 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1955 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1956 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1957 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1958 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1959 | irsp = &rspiocbq.iocb; |
| 1960 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1962 | pring->stats.iocb_rsp++; |
| 1963 | rsp_cmpl++; |
| 1964 | |
| 1965 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1966 | /* |
| 1967 | * If resource errors reported from HBA, reduce |
| 1968 | * queuedepths of the SCSI device. |
| 1969 | */ |
| 1970 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1971 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1972 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1973 | lpfc_adjust_queue_depth(phba); |
| 1974 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1975 | } |
| 1976 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | /* Rsp ring <ringno> error: IOCB */ |
| 1978 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1979 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1980 | "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] | 1981 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1982 | irsp->un.ulpWord[0], |
| 1983 | irsp->un.ulpWord[1], |
| 1984 | irsp->un.ulpWord[2], |
| 1985 | irsp->un.ulpWord[3], |
| 1986 | irsp->un.ulpWord[4], |
| 1987 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1988 | *(uint32_t *)&irsp->un1, |
| 1989 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | switch (type) { |
| 1993 | case LPFC_ABORT_IOCB: |
| 1994 | case LPFC_SOL_IOCB: |
| 1995 | /* |
| 1996 | * Idle exchange closed via ABTS from port. No iocb |
| 1997 | * resources need to be recovered. |
| 1998 | */ |
| 1999 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2000 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2001 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2002 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2004 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2005 | break; |
| 2006 | } |
| 2007 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2008 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2009 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2011 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2012 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2013 | &rspiocbq); |
| 2014 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2015 | spin_unlock_irqrestore(&phba->hbalock, |
| 2016 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2017 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2018 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2020 | iflag); |
| 2021 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | } |
| 2023 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2024 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2026 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2028 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | default: |
| 2030 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2031 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2032 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2033 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2034 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2035 | dev_warn(&((phba->pcidev)->dev), |
| 2036 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | phba->brd_no, adaptermsg); |
| 2038 | } else { |
| 2039 | /* Unknown IOCB command */ |
| 2040 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2041 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2042 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2043 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2044 | irsp->ulpStatus, |
| 2045 | irsp->ulpIoTag, |
| 2046 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | } |
| 2048 | break; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
| 2052 | * The response IOCB has been processed. Update the ring |
| 2053 | * pointer in SLIM. If the port response put pointer has not |
| 2054 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2055 | * response put pointer. |
| 2056 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2057 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
| 2059 | if (pring->rspidx == portRspPut) |
| 2060 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2061 | } |
| 2062 | |
| 2063 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2064 | pring->stats.iocb_rsp_full++; |
| 2065 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2066 | writel(status, phba->CAregaddr); |
| 2067 | readl(phba->CAregaddr); |
| 2068 | } |
| 2069 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2070 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2071 | pring->stats.iocb_cmd_empty++; |
| 2072 | |
| 2073 | /* Force update of the local copy of cmdGetInx */ |
| 2074 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2075 | lpfc_sli_resume_iocb(phba, pring); |
| 2076 | |
| 2077 | if ((pring->lpfc_sli_cmd_available)) |
| 2078 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2079 | |
| 2080 | } |
| 2081 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | return rc; |
| 2084 | } |
| 2085 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2086 | /** |
| 2087 | * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings. |
| 2088 | * @phba: Pointer to HBA context object. |
| 2089 | * @pring: Pointer to driver SLI ring object. |
| 2090 | * @mask: Host attention register mask for this ring. |
| 2091 | * |
| 2092 | * This function is called from the worker thread when there is a ring |
| 2093 | * event for non-fcp rings. The caller does not hold any lock . |
| 2094 | * The function processes each response iocb in the response ring until it |
| 2095 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2096 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the |
| 2097 | * response iocb indicates a completion of a command iocb. The function |
| 2098 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited |
| 2099 | * iocb. The function frees the resources or calls the completion handler if |
| 2100 | * this iocb is an abort completion. The function returns 0 when the allocated |
| 2101 | * iocbs are not freed, otherwise returns 1. |
| 2102 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2104 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2105 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2107 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | IOCB_t *entry; |
| 2109 | IOCB_t *irsp = NULL; |
| 2110 | struct lpfc_iocbq *rspiocbp = NULL; |
| 2111 | struct lpfc_iocbq *next_iocb; |
| 2112 | struct lpfc_iocbq *cmdiocbp; |
| 2113 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | uint8_t iocb_cmd_type; |
| 2115 | lpfc_iocb_type type; |
| 2116 | uint32_t status, free_saveq; |
| 2117 | uint32_t portRspPut, portRspMax; |
| 2118 | int rc = 1; |
| 2119 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2121 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | pring->stats.iocb_event++; |
| 2124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | /* |
| 2126 | * The next available response entry should never exceed the maximum |
| 2127 | * entries. If it does, treat it as an adapter hardware error. |
| 2128 | */ |
| 2129 | portRspMax = pring->numRiocb; |
| 2130 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2131 | if (portRspPut >= portRspMax) { |
| 2132 | /* |
| 2133 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then |
| 2134 | * rsp ring <portRspMax> |
| 2135 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2136 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2137 | "0303 Ring %d handler: portRspPut %d " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | "is bigger then rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2139 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2141 | phba->link_state = LPFC_HBA_ERROR; |
| 2142 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | |
| 2144 | phba->work_hs = HS_FFER3; |
| 2145 | lpfc_handle_eratt(phba); |
| 2146 | |
| 2147 | return 1; |
| 2148 | } |
| 2149 | |
| 2150 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | while (pring->rspidx != portRspPut) { |
| 2152 | /* |
| 2153 | * Build a completion list and call the appropriate handler. |
| 2154 | * The process is to get the next available response iocb, get |
| 2155 | * a free iocb from the list, copy the response data into the |
| 2156 | * free iocb, insert to the continuation list, and update the |
| 2157 | * next response index to slim. This process makes response |
| 2158 | * iocb's in the ring available to DMA as fast as possible but |
| 2159 | * pays a penalty for a copy operation. Since the iocb is |
| 2160 | * only 32 bytes, this penalty is considered small relative to |
| 2161 | * the PCI reads for register values and a slim write. When |
| 2162 | * the ulpLe field is set, the entire Command has been |
| 2163 | * received. |
| 2164 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2165 | entry = lpfc_resp_iocb(phba, pring); |
| 2166 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2167 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2168 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | if (rspiocbp == NULL) { |
| 2170 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2171 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2175 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2176 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | irsp = &rspiocbp->iocb; |
| 2178 | |
| 2179 | if (++pring->rspidx >= portRspMax) |
| 2180 | pring->rspidx = 0; |
| 2181 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2182 | if (pring->ringno == LPFC_ELS_RING) { |
| 2183 | lpfc_debugfs_slow_ring_trc(phba, |
| 2184 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2185 | *(((uint32_t *) irsp) + 4), |
| 2186 | *(((uint32_t *) irsp) + 6), |
| 2187 | *(((uint32_t *) irsp) + 7)); |
| 2188 | } |
| 2189 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2190 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2192 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | |
| 2194 | pring->iocb_continueq_cnt++; |
| 2195 | if (irsp->ulpLe) { |
| 2196 | /* |
| 2197 | * By default, the driver expects to free all resources |
| 2198 | * associated with this iocb completion. |
| 2199 | */ |
| 2200 | free_saveq = 1; |
| 2201 | saveq = list_get_first(&pring->iocb_continueq, |
| 2202 | struct lpfc_iocbq, list); |
| 2203 | irsp = &(saveq->iocb); |
| 2204 | list_del_init(&pring->iocb_continueq); |
| 2205 | pring->iocb_continueq_cnt = 0; |
| 2206 | |
| 2207 | pring->stats.iocb_rsp++; |
| 2208 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2209 | /* |
| 2210 | * If resource errors reported from HBA, reduce |
| 2211 | * queuedepths of the SCSI device. |
| 2212 | */ |
| 2213 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2214 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2215 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2216 | lpfc_adjust_queue_depth(phba); |
| 2217 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2218 | } |
| 2219 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | if (irsp->ulpStatus) { |
| 2221 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2222 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2223 | "0328 Rsp Ring %d error: " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2224 | "IOCB Data: " |
| 2225 | "x%x x%x x%x x%x " |
| 2226 | "x%x x%x x%x x%x " |
| 2227 | "x%x x%x x%x x%x " |
| 2228 | "x%x x%x x%x x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2229 | pring->ringno, |
| 2230 | irsp->un.ulpWord[0], |
| 2231 | irsp->un.ulpWord[1], |
| 2232 | irsp->un.ulpWord[2], |
| 2233 | irsp->un.ulpWord[3], |
| 2234 | irsp->un.ulpWord[4], |
| 2235 | irsp->un.ulpWord[5], |
| 2236 | *(((uint32_t *) irsp) + 6), |
| 2237 | *(((uint32_t *) irsp) + 7), |
| 2238 | *(((uint32_t *) irsp) + 8), |
| 2239 | *(((uint32_t *) irsp) + 9), |
| 2240 | *(((uint32_t *) irsp) + 10), |
| 2241 | *(((uint32_t *) irsp) + 11), |
| 2242 | *(((uint32_t *) irsp) + 12), |
| 2243 | *(((uint32_t *) irsp) + 13), |
| 2244 | *(((uint32_t *) irsp) + 14), |
| 2245 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | /* |
| 2249 | * Fetch the IOCB command type and call the correct |
| 2250 | * completion routine. Solicited and Unsolicited |
| 2251 | * IOCBs on the ELS ring get freed back to the |
| 2252 | * lpfc_iocb_list by the discovery kernel thread. |
| 2253 | */ |
| 2254 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2255 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2256 | if (type == LPFC_SOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2257 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | saveq); |
| 2260 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2262 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2263 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | saveq); |
| 2265 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2266 | if (!rc) |
| 2267 | free_saveq = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | } else if (type == LPFC_ABORT_IOCB) { |
| 2269 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 2270 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2271 | lpfc_sli_iocbq_lookup(phba, pring, |
| 2272 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | /* Call the specified completion |
| 2274 | routine */ |
| 2275 | if (cmdiocbp->iocb_cmpl) { |
| 2276 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2277 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | iflag); |
| 2279 | (cmdiocbp->iocb_cmpl) (phba, |
| 2280 | cmdiocbp, saveq); |
| 2281 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2282 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2284 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2285 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2286 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | } |
| 2288 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 2289 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2290 | |
| 2291 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2292 | |
| 2293 | memset(adaptermsg, 0, |
| 2294 | LPFC_MAX_ADPTMSG); |
| 2295 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2296 | MAX_MSG_DATA); |
| 2297 | dev_warn(&((phba->pcidev)->dev), |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2298 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | phba->brd_no, adaptermsg); |
| 2300 | } else { |
| 2301 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2302 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2303 | "0335 Unknown IOCB " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2304 | "command Data: x%x " |
| 2305 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | irsp->ulpCommand, |
| 2307 | irsp->ulpStatus, |
| 2308 | irsp->ulpIoTag, |
| 2309 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2314 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2315 | &saveq->list, list) { |
| 2316 | list_del(&rspiocbp->list); |
| 2317 | __lpfc_sli_release_iocbq(phba, |
| 2318 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2322 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | /* |
| 2326 | * If the port response put pointer has not been updated, sync |
| 2327 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2328 | * response put pointer. |
| 2329 | */ |
| 2330 | if (pring->rspidx == portRspPut) { |
| 2331 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2332 | } |
| 2333 | } /* while (pring->rspidx != portRspPut) */ |
| 2334 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2335 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | /* At least one response entry has been freed */ |
| 2337 | pring->stats.iocb_rsp_full++; |
| 2338 | /* SET RxRE_RSP in Chip Att register */ |
| 2339 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2340 | writel(status, phba->CAregaddr); |
| 2341 | readl(phba->CAregaddr); /* flush */ |
| 2342 | } |
| 2343 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2344 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2345 | pring->stats.iocb_cmd_empty++; |
| 2346 | |
| 2347 | /* Force update of the local copy of cmdGetInx */ |
| 2348 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2349 | lpfc_sli_resume_iocb(phba, pring); |
| 2350 | |
| 2351 | if ((pring->lpfc_sli_cmd_available)) |
| 2352 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2353 | |
| 2354 | } |
| 2355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | return rc; |
| 2358 | } |
| 2359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2360 | /** |
| 2361 | * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring. |
| 2362 | * @phba: Pointer to HBA context object. |
| 2363 | * @pring: Pointer to driver SLI ring object. |
| 2364 | * |
| 2365 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2366 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2367 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2368 | * the return of this function. The caller is not required to hold any locks. |
| 2369 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2372 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2373 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2375 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2377 | if (pring->ringno == LPFC_ELS_RING) { |
| 2378 | lpfc_fabric_abort_hba(phba); |
| 2379 | } |
| 2380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | /* Error everything on txq and txcmplq |
| 2382 | * First do the txq. |
| 2383 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2384 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2385 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | |
| 2388 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2389 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2390 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2391 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2392 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2393 | |
| 2394 | while (!list_empty(&completions)) { |
| 2395 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | cmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2397 | list_del_init(&iocb->list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2399 | if (!iocb->iocb_cmpl) |
| 2400 | lpfc_sli_release_iocbq(phba, iocb); |
| 2401 | else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2403 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | } |
| 2408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2409 | /** |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2410 | * lpfc_sli_flush_fcp_rings: flush all iocbs in the fcp ring. |
| 2411 | * @phba: Pointer to HBA context object. |
| 2412 | * |
| 2413 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2414 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2415 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2416 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2417 | * slot has been permanently disabled. |
| 2418 | **/ |
| 2419 | void |
| 2420 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2421 | { |
| 2422 | LIST_HEAD(txq); |
| 2423 | LIST_HEAD(txcmplq); |
| 2424 | struct lpfc_iocbq *iocb; |
| 2425 | IOCB_t *cmd = NULL; |
| 2426 | struct lpfc_sli *psli = &phba->sli; |
| 2427 | struct lpfc_sli_ring *pring; |
| 2428 | |
| 2429 | /* Currently, only one fcp ring */ |
| 2430 | pring = &psli->ring[psli->fcp_ring]; |
| 2431 | |
| 2432 | spin_lock_irq(&phba->hbalock); |
| 2433 | /* Retrieve everything on txq */ |
| 2434 | list_splice_init(&pring->txq, &txq); |
| 2435 | pring->txq_cnt = 0; |
| 2436 | |
| 2437 | /* Retrieve everything on the txcmplq */ |
| 2438 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2439 | pring->txcmplq_cnt = 0; |
| 2440 | spin_unlock_irq(&phba->hbalock); |
| 2441 | |
| 2442 | /* Flush the txq */ |
| 2443 | while (!list_empty(&txq)) { |
| 2444 | iocb = list_get_first(&txq, struct lpfc_iocbq, list); |
| 2445 | cmd = &iocb->iocb; |
| 2446 | list_del_init(&iocb->list); |
| 2447 | |
| 2448 | if (!iocb->iocb_cmpl) |
| 2449 | lpfc_sli_release_iocbq(phba, iocb); |
| 2450 | else { |
| 2451 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2452 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2453 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /* Flush the txcmpq */ |
| 2458 | while (!list_empty(&txcmplq)) { |
| 2459 | iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list); |
| 2460 | cmd = &iocb->iocb; |
| 2461 | list_del_init(&iocb->list); |
| 2462 | |
| 2463 | if (!iocb->iocb_cmpl) |
| 2464 | lpfc_sli_release_iocbq(phba, iocb); |
| 2465 | else { |
| 2466 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2467 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2468 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2469 | } |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2474 | * lpfc_sli_brdready: Check for host status bits. |
| 2475 | * @phba: Pointer to HBA context object. |
| 2476 | * @mask: Bit mask to be checked. |
| 2477 | * |
| 2478 | * This function reads the host status register and compares |
| 2479 | * with the provided bit mask to check if HBA completed |
| 2480 | * the restart. This function will wait in a loop for the |
| 2481 | * HBA to complete restart. If the HBA does not restart within |
| 2482 | * 15 iterations, the function will reset the HBA again. The |
| 2483 | * function returns 1 when HBA fail to restart otherwise returns |
| 2484 | * zero. |
| 2485 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2486 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2487 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2489 | uint32_t status; |
| 2490 | int i = 0; |
| 2491 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2493 | /* Read the HBA Host Status Register */ |
| 2494 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2496 | /* |
| 2497 | * Check status register every 100ms for 5 retries, then every |
| 2498 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2499 | * every 2.5 sec for 4. |
| 2500 | * Break our of the loop if errors occurred during init. |
| 2501 | */ |
| 2502 | while (((status & mask) != mask) && |
| 2503 | !(status & HS_FFERM) && |
| 2504 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2506 | if (i <= 5) |
| 2507 | msleep(10); |
| 2508 | else if (i <= 10) |
| 2509 | msleep(500); |
| 2510 | else |
| 2511 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2513 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2515 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2516 | lpfc_sli_brdrestart(phba); |
| 2517 | } |
| 2518 | /* Read the HBA Host Status Register */ |
| 2519 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2522 | /* Check to see if any errors occurred during init */ |
| 2523 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2524 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2525 | retval = 1; |
| 2526 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2528 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | } |
| 2530 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2531 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2532 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2533 | /** |
| 2534 | * lpfc_reset_barrier: Make HBA ready for HBA reset. |
| 2535 | * @phba: Pointer to HBA context object. |
| 2536 | * |
| 2537 | * This function is called before resetting an HBA. This |
| 2538 | * function requests HBA to quiesce DMAs before a reset. |
| 2539 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2540 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2541 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2542 | uint32_t __iomem *resp_buf; |
| 2543 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2544 | volatile uint32_t mbox; |
| 2545 | uint32_t hc_copy; |
| 2546 | int i; |
| 2547 | uint8_t hdrtype; |
| 2548 | |
| 2549 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2550 | if (hdrtype != 0x80 || |
| 2551 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2552 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2553 | return; |
| 2554 | |
| 2555 | /* |
| 2556 | * Tell the other part of the chip to suspend temporarily all |
| 2557 | * its DMA activity. |
| 2558 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2559 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2560 | |
| 2561 | /* Disable the error attention */ |
| 2562 | hc_copy = readl(phba->HCregaddr); |
| 2563 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2564 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2565 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2566 | |
| 2567 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2568 | /* Clear Chip error bit */ |
| 2569 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | mbox = 0; |
| 2574 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2575 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2576 | |
| 2577 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2578 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2579 | writel(mbox, mbox_buf); |
| 2580 | |
| 2581 | for (i = 0; |
| 2582 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2583 | mdelay(1); |
| 2584 | |
| 2585 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2586 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2588 | goto restore_hc; |
| 2589 | else |
| 2590 | goto clear_errat; |
| 2591 | } |
| 2592 | |
| 2593 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2594 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2595 | mdelay(1); |
| 2596 | |
| 2597 | clear_errat: |
| 2598 | |
| 2599 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2600 | mdelay(1); |
| 2601 | |
| 2602 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2603 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2608 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2609 | writel(hc_copy, phba->HCregaddr); |
| 2610 | readl(phba->HCregaddr); /* flush */ |
| 2611 | } |
| 2612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2613 | /** |
| 2614 | * lpfc_sli_brdkill: Issue a kill_board mailbox command. |
| 2615 | * @phba: Pointer to HBA context object. |
| 2616 | * |
| 2617 | * This function issues a kill_board mailbox command and waits for |
| 2618 | * the error attention interrupt. This function is called for stopping |
| 2619 | * the firmware processing. The caller is not required to hold any |
| 2620 | * locks. This function calls lpfc_hba_down_post function to free |
| 2621 | * any pending commands after the kill. The function will return 1 when it |
| 2622 | * fails to kill the board else will return 0. |
| 2623 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2624 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2627 | struct lpfc_sli *psli; |
| 2628 | LPFC_MBOXQ_t *pmb; |
| 2629 | uint32_t status; |
| 2630 | uint32_t ha_copy; |
| 2631 | int retval; |
| 2632 | int i = 0; |
| 2633 | |
| 2634 | psli = &phba->sli; |
| 2635 | |
| 2636 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2637 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2638 | "0329 Kill HBA Data: x%x x%x\n", |
| 2639 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2640 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2641 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2642 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2643 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2644 | |
| 2645 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2647 | status = readl(phba->HCregaddr); |
| 2648 | status &= ~HC_ERINT_ENA; |
| 2649 | writel(status, phba->HCregaddr); |
| 2650 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2651 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2652 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2653 | |
| 2654 | lpfc_kill_board(phba, pmb); |
| 2655 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2656 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2657 | |
| 2658 | if (retval != MBX_SUCCESS) { |
| 2659 | if (retval != MBX_BUSY) |
| 2660 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2661 | spin_lock_irq(&phba->hbalock); |
| 2662 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2663 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2664 | return 1; |
| 2665 | } |
| 2666 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2667 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2668 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2669 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2670 | |
| 2671 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2672 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2673 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2674 | * board is now undefined. |
| 2675 | */ |
| 2676 | ha_copy = readl(phba->HAregaddr); |
| 2677 | |
| 2678 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2679 | mdelay(100); |
| 2680 | ha_copy = readl(phba->HAregaddr); |
| 2681 | } |
| 2682 | |
| 2683 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2684 | if (ha_copy & HA_ERATT) { |
| 2685 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2687 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2688 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2689 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2690 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2691 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2692 | |
| 2693 | psli->mbox_active = NULL; |
| 2694 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2695 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2696 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2698 | } |
| 2699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2700 | /** |
| 2701 | * lpfc_sli_brdreset: Reset the HBA. |
| 2702 | * @phba: Pointer to HBA context object. |
| 2703 | * |
| 2704 | * This function resets the HBA by writing HC_INITFF to the control |
| 2705 | * register. After the HBA resets, this function resets all the iocb ring |
| 2706 | * indices. This function disables PCI layer parity checking during |
| 2707 | * the reset. |
| 2708 | * This function returns 0 always. |
| 2709 | * The caller is not required to hold any locks. |
| 2710 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2711 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2712 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2713 | { |
| 2714 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2716 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2719 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2721 | /* Reset HBA */ |
| 2722 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2723 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2725 | |
| 2726 | /* perform board reset */ |
| 2727 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2728 | phba->pport->fc_myDID = 0; |
| 2729 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2731 | /* Turn off parity checking and serr during the physical reset */ |
| 2732 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2733 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2734 | (cfg_value & |
| 2735 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2736 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2737 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2738 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2739 | writel(HC_INITFF, phba->HCregaddr); |
| 2740 | mdelay(1); |
| 2741 | readl(phba->HCregaddr); /* flush */ |
| 2742 | writel(0, phba->HCregaddr); |
| 2743 | readl(phba->HCregaddr); /* flush */ |
| 2744 | |
| 2745 | /* Restore PCI cmd register */ |
| 2746 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | |
| 2748 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2749 | for (i = 0; i < psli->num_rings; i++) { |
| 2750 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | pring->flag = 0; |
| 2752 | pring->rspidx = 0; |
| 2753 | pring->next_cmdidx = 0; |
| 2754 | pring->local_getidx = 0; |
| 2755 | pring->cmdidx = 0; |
| 2756 | pring->missbufcnt = 0; |
| 2757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2759 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2760 | return 0; |
| 2761 | } |
| 2762 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2763 | /** |
| 2764 | * lpfc_sli_brdrestart: Restart the HBA. |
| 2765 | * @phba: Pointer to HBA context object. |
| 2766 | * |
| 2767 | * This function is called in the SLI initialization code path to |
| 2768 | * restart the HBA. The caller is not required to hold any lock. |
| 2769 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2770 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2771 | * function to free any pending commands. The function enables |
| 2772 | * POST only during the first initialization. The function returns zero. |
| 2773 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2774 | * command before the return of this function. |
| 2775 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2776 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2777 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2778 | { |
| 2779 | MAILBOX_t *mb; |
| 2780 | struct lpfc_sli *psli; |
| 2781 | uint16_t skip_post; |
| 2782 | volatile uint32_t word0; |
| 2783 | void __iomem *to_slim; |
| 2784 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2785 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2786 | |
| 2787 | psli = &phba->sli; |
| 2788 | |
| 2789 | /* Restart HBA */ |
| 2790 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2791 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2792 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2793 | |
| 2794 | word0 = 0; |
| 2795 | mb = (MAILBOX_t *) &word0; |
| 2796 | mb->mbxCommand = MBX_RESTART; |
| 2797 | mb->mbxHc = 1; |
| 2798 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2799 | lpfc_reset_barrier(phba); |
| 2800 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2801 | to_slim = phba->MBslimaddr; |
| 2802 | writel(*(uint32_t *) mb, to_slim); |
| 2803 | readl(to_slim); /* flush */ |
| 2804 | |
| 2805 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 | if (phba->pport->port_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2807 | skip_post = 1; |
| 2808 | word0 = 1; /* This is really setting up word1 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | } else { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2810 | skip_post = 0; |
| 2811 | word0 = 0; /* This is really setting up word1 */ |
| 2812 | } |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2813 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2814 | writel(*(uint32_t *) mb, to_slim); |
| 2815 | readl(to_slim); /* flush */ |
| 2816 | |
| 2817 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2818 | phba->pport->stopped = 0; |
| 2819 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2822 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2823 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2824 | psli->stats_start = get_seconds(); |
| 2825 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2826 | if (skip_post) |
| 2827 | mdelay(100); |
| 2828 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | mdelay(2000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2831 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | |
| 2833 | return 0; |
| 2834 | } |
| 2835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2836 | /** |
| 2837 | * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart. |
| 2838 | * @phba: Pointer to HBA context object. |
| 2839 | * |
| 2840 | * This function is called after a HBA restart to wait for successful |
| 2841 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2842 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2843 | * iteration, the function will restart the HBA again. The function returns |
| 2844 | * zero if HBA successfully restarted else returns negative error code. |
| 2845 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | static int |
| 2847 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2848 | { |
| 2849 | uint32_t status, i = 0; |
| 2850 | |
| 2851 | /* Read the HBA Host Status Register */ |
| 2852 | status = readl(phba->HSregaddr); |
| 2853 | |
| 2854 | /* Check status register to see what current state is */ |
| 2855 | i = 0; |
| 2856 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2857 | |
| 2858 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2859 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2860 | * 4. |
| 2861 | */ |
| 2862 | if (i++ >= 20) { |
| 2863 | /* Adapter failed to init, timeout, status reg |
| 2864 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2865 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2866 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2867 | "timeout, status reg x%x, " |
| 2868 | "FW Data: A8 x%x AC x%x\n", status, |
| 2869 | readl(phba->MBslimaddr + 0xa8), |
| 2870 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2871 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | return -ETIMEDOUT; |
| 2873 | } |
| 2874 | |
| 2875 | /* Check to see if any errors occurred during init */ |
| 2876 | if (status & HS_FFERM) { |
| 2877 | /* ERROR: During chipset initialization */ |
| 2878 | /* Adapter failed to init, chipset, status reg |
| 2879 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2881 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2882 | "chipset, status reg x%x, " |
| 2883 | "FW Data: A8 x%x AC x%x\n", status, |
| 2884 | readl(phba->MBslimaddr + 0xa8), |
| 2885 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | return -EIO; |
| 2888 | } |
| 2889 | |
| 2890 | if (i <= 5) { |
| 2891 | msleep(10); |
| 2892 | } else if (i <= 10) { |
| 2893 | msleep(500); |
| 2894 | } else { |
| 2895 | msleep(2500); |
| 2896 | } |
| 2897 | |
| 2898 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2899 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2900 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2901 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | } |
| 2903 | /* Read the HBA Host Status Register */ |
| 2904 | status = readl(phba->HSregaddr); |
| 2905 | } |
| 2906 | |
| 2907 | /* Check to see if any errors occurred during init */ |
| 2908 | if (status & HS_FFERM) { |
| 2909 | /* ERROR: During chipset initialization */ |
| 2910 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2912 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2913 | "status reg x%x, " |
| 2914 | "FW Data: A8 x%x AC x%x\n", status, |
| 2915 | readl(phba->MBslimaddr + 0xa8), |
| 2916 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2917 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | return -EIO; |
| 2919 | } |
| 2920 | |
| 2921 | /* Clear all interrupt enable conditions */ |
| 2922 | writel(0, phba->HCregaddr); |
| 2923 | readl(phba->HCregaddr); /* flush */ |
| 2924 | |
| 2925 | /* setup host attn register */ |
| 2926 | writel(0xffffffff, phba->HAregaddr); |
| 2927 | readl(phba->HAregaddr); /* flush */ |
| 2928 | return 0; |
| 2929 | } |
| 2930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2931 | /** |
| 2932 | * lpfc_sli_hbq_count: Get the number of HBQs to be configured. |
| 2933 | * |
| 2934 | * This function calculates and returns the number of HBQs required to be |
| 2935 | * configured. |
| 2936 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2937 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2938 | lpfc_sli_hbq_count(void) |
| 2939 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2940 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2941 | } |
| 2942 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2943 | /** |
| 2944 | * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries. |
| 2945 | * |
| 2946 | * This function adds the number of hbq entries in every HBQ to get |
| 2947 | * the total number of hbq entries required for the HBA and returns |
| 2948 | * the total count. |
| 2949 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2950 | static int |
| 2951 | lpfc_sli_hbq_entry_count(void) |
| 2952 | { |
| 2953 | int hbq_count = lpfc_sli_hbq_count(); |
| 2954 | int count = 0; |
| 2955 | int i; |
| 2956 | |
| 2957 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2958 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2959 | return count; |
| 2960 | } |
| 2961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2962 | /** |
| 2963 | * lpfc_sli_hbq_size: Calculate memory required for all hbq entries. |
| 2964 | * |
| 2965 | * This function calculates amount of memory required for all hbq entries |
| 2966 | * to be configured and returns the total memory required. |
| 2967 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2969 | lpfc_sli_hbq_size(void) |
| 2970 | { |
| 2971 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2972 | } |
| 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
| 2975 | * lpfc_sli_hbq_setup: configure and initialize HBQs. |
| 2976 | * @phba: Pointer to HBA context object. |
| 2977 | * |
| 2978 | * This function is called during the SLI initialization to configure |
| 2979 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 2980 | * required to hold any locks. This function will return zero if successful |
| 2981 | * else it will return negative error code. |
| 2982 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2983 | static int |
| 2984 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2985 | { |
| 2986 | int hbq_count = lpfc_sli_hbq_count(); |
| 2987 | LPFC_MBOXQ_t *pmb; |
| 2988 | MAILBOX_t *pmbox; |
| 2989 | uint32_t hbqno; |
| 2990 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2991 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2992 | /* Get a Mailbox buffer to setup mailbox |
| 2993 | * commands for HBA initialization |
| 2994 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2995 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2996 | |
| 2997 | if (!pmb) |
| 2998 | return -ENOMEM; |
| 2999 | |
| 3000 | pmbox = &pmb->mb; |
| 3001 | |
| 3002 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 3003 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3004 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3005 | |
| 3006 | hbq_entry_index = 0; |
| 3007 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 3008 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 3009 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 3010 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 3011 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3012 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3013 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 3014 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3015 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 3016 | |
| 3017 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 3018 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 3019 | mbxStatus <status>, ring <num> */ |
| 3020 | |
| 3021 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3022 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3023 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3024 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3025 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3026 | pmbox->mbxStatus, hbqno); |
| 3027 | |
| 3028 | phba->link_state = LPFC_HBA_ERROR; |
| 3029 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3030 | return ENXIO; |
| 3031 | } |
| 3032 | } |
| 3033 | phba->hbq_count = hbq_count; |
| 3034 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3035 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3036 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3037 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3038 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 3039 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3040 | return 0; |
| 3041 | } |
| 3042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3043 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 3044 | * lpfc_sli_config_port: Issue config port mailbox command. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3045 | * @phba: Pointer to HBA context object. |
| 3046 | * @sli_mode: sli mode - 2/3 |
| 3047 | * |
| 3048 | * This function is called by the sli intialization code path |
| 3049 | * to issue config_port mailbox command. This function restarts the |
| 3050 | * HBA firmware and issues a config_port mailbox command to configure |
| 3051 | * the SLI interface in the sli mode specified by sli_mode |
| 3052 | * variable. The caller is not required to hold any locks. |
| 3053 | * The function returns 0 if successful, else returns negative error |
| 3054 | * code. |
| 3055 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 3056 | int |
| 3057 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | { |
| 3059 | LPFC_MBOXQ_t *pmb; |
| 3060 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3061 | |
| 3062 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3063 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3064 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | return -ENOMEM; |
| 3066 | } |
| 3067 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3068 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3070 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3071 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3072 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3073 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3074 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | msleep(2500); |
| 3076 | rc = lpfc_sli_chipset_init(phba); |
| 3077 | if (rc) |
| 3078 | break; |
| 3079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3080 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3081 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3082 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | resetcount++; |
| 3084 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3085 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3086 | * value of 0 means the call was successful. Any other |
| 3087 | * nonzero value is a failure, but if ERESTART is returned, |
| 3088 | * the driver may reset the HBA and try again. |
| 3089 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | rc = lpfc_config_port_prep(phba); |
| 3091 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3092 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3094 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | lpfc_config_port(phba, pmb); |
| 3098 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3099 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3100 | LPFC_SLI3_HBQ_ENABLED | |
| 3101 | LPFC_SLI3_CRP_ENABLED | |
| 3102 | LPFC_SLI3_INB_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3103 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3105 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3106 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3107 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3110 | spin_unlock_irq(&phba->hbalock); |
| 3111 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3112 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3113 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3114 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3115 | if (!done) { |
| 3116 | rc = -EINVAL; |
| 3117 | goto do_prep_failed; |
| 3118 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3119 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3120 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3121 | rc = -ENXIO; |
| 3122 | goto do_prep_failed; |
| 3123 | } |
| 3124 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3125 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3126 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3127 | } else |
| 3128 | phba->max_vpi = 0; |
| 3129 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3130 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3131 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3132 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3133 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3134 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
| 3135 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3136 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3137 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3138 | phba->inb_last_counter = |
| 3139 | phba->mbox->us.s3_inb_pgp.counter; |
| 3140 | } else { |
| 3141 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3142 | phba->inb_ha_copy = NULL; |
| 3143 | phba->inb_counter = NULL; |
| 3144 | } |
| 3145 | } else { |
| 3146 | phba->port_gp = phba->mbox->us.s2.port; |
| 3147 | phba->inb_ha_copy = NULL; |
| 3148 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3149 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3150 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3152 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3153 | return rc; |
| 3154 | } |
| 3155 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3156 | |
| 3157 | /** |
| 3158 | * lpfc_sli_hba_setup: SLI intialization function. |
| 3159 | * @phba: Pointer to HBA context object. |
| 3160 | * |
| 3161 | * This function is the main SLI intialization function. This function |
| 3162 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3163 | * error attention handler code. Caller is not required to hold any |
| 3164 | * locks. This function issues config_port mailbox command to configure |
| 3165 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3166 | * calls the config_port_post function to issue init_link mailbox |
| 3167 | * command and to start the discovery. The function will return zero |
| 3168 | * if successful, else it will return negative error code. |
| 3169 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3170 | int |
| 3171 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3172 | { |
| 3173 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3174 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3175 | |
| 3176 | switch (lpfc_sli_mode) { |
| 3177 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3178 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3180 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3181 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3182 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3183 | break; |
| 3184 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3185 | mode = 2; |
| 3186 | break; |
| 3187 | case 0: |
| 3188 | case 3: |
| 3189 | break; |
| 3190 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3192 | "1819 Unrecognized lpfc_sli_mode " |
| 3193 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3194 | |
| 3195 | break; |
| 3196 | } |
| 3197 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 3198 | rc = lpfc_sli_config_port(phba, mode); |
| 3199 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3200 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3201 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3202 | "1820 Unable to select SLI-3. " |
| 3203 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3204 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 3205 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3206 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | goto lpfc_sli_hba_setup_error; |
| 3208 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3209 | if (phba->sli_rev == 3) { |
| 3210 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3211 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3212 | } else { |
| 3213 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3214 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3215 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3219 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3220 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3221 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | |
| 3223 | if (rc) |
| 3224 | goto lpfc_sli_hba_setup_error; |
| 3225 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 3226 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3227 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3228 | rc = lpfc_sli_hbq_setup(phba); |
| 3229 | if (rc) |
| 3230 | goto lpfc_sli_hba_setup_error; |
| 3231 | } |
| 3232 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3233 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3234 | |
| 3235 | rc = lpfc_config_port_post(phba); |
| 3236 | if (rc) |
| 3237 | goto lpfc_sli_hba_setup_error; |
| 3238 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3239 | return rc; |
| 3240 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3241 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3242 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3243 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3244 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3245 | return rc; |
| 3246 | } |
| 3247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3248 | |
| 3249 | /** |
| 3250 | * lpfc_mbox_timeout: Timeout call back function for mbox timer. |
| 3251 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3253 | * This is the callback function for mailbox timer. The mailbox |
| 3254 | * timer is armed when a new mailbox command is issued and the timer |
| 3255 | * is deleted when the mailbox complete. The function is called by |
| 3256 | * the kernel timer code when a mailbox does not complete within |
| 3257 | * expected time. This function wakes up the worker thread to |
| 3258 | * process the mailbox timeout and returns. All the processing is |
| 3259 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | void |
| 3262 | lpfc_mbox_timeout(unsigned long ptr) |
| 3263 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3268 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3269 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3270 | if (!tmo_posted) |
| 3271 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3272 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3273 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3274 | if (!tmo_posted) |
| 3275 | lpfc_worker_wake_up(phba); |
| 3276 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | } |
| 3278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3279 | |
| 3280 | /** |
| 3281 | * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout. |
| 3282 | * @phba: Pointer to HBA context object. |
| 3283 | * |
| 3284 | * This function is called from worker thread when a mailbox command times out. |
| 3285 | * The caller is not required to hold any locks. This function will reset the |
| 3286 | * HBA and recover all the pending commands. |
| 3287 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | void |
| 3289 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3290 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3291 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3292 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3293 | struct lpfc_sli *psli = &phba->sli; |
| 3294 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3296 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | return; |
| 3298 | } |
| 3299 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3301 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3302 | "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] | 3303 | mb->mbxCommand, |
| 3304 | phba->pport->port_state, |
| 3305 | phba->sli.sli_flag, |
| 3306 | phba->sli.mbox_active); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3308 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3309 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3310 | * it to fail all oustanding SCSI IO. |
| 3311 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3312 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3313 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3314 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3315 | spin_lock_irq(&phba->hbalock); |
| 3316 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3317 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3318 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3319 | |
| 3320 | pring = &psli->ring[psli->fcp_ring]; |
| 3321 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3322 | |
| 3323 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3324 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3325 | /* |
| 3326 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 3327 | * on oustanding mailbox commands. |
| 3328 | */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3329 | /* If resets are disabled then set error state and return. */ |
| 3330 | if (!phba->cfg_enable_hba_reset) { |
| 3331 | phba->link_state = LPFC_HBA_ERROR; |
| 3332 | return; |
| 3333 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3334 | lpfc_offline_prep(phba); |
| 3335 | lpfc_offline(phba); |
| 3336 | lpfc_sli_brdrestart(phba); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3337 | lpfc_online(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3338 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | return; |
| 3340 | } |
| 3341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3342 | /** |
| 3343 | * lpfc_sli_issue_mbox: Issue a mailbox command to firmware. |
| 3344 | * @phba: Pointer to HBA context object. |
| 3345 | * @pmbox: Pointer to mailbox object. |
| 3346 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3347 | * |
| 3348 | * This function is called by discovery code and HBA management code |
| 3349 | * to submit a mailbox command to firmware. This function gets the |
| 3350 | * hbalock to protect the data structures. |
| 3351 | * The mailbox command can be submitted in polling mode, in which case |
| 3352 | * this function will wait in a polling loop for the completion of the |
| 3353 | * mailbox. |
| 3354 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3355 | * function will submit the command and returns immediately without waiting |
| 3356 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3357 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3358 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3359 | * mailbox is issued in polling mode and there is already a mailbox |
| 3360 | * pending, then the function will return an error. If the mailbox is issued |
| 3361 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3362 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3363 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3364 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3365 | * return codes the caller owns the mailbox command after the return of |
| 3366 | * the function. |
| 3367 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3369 | 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] | 3370 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | uint32_t status, evtctr; |
| 3374 | uint32_t ha_copy; |
| 3375 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3376 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3378 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3380 | int processing_queue = 0; |
| 3381 | |
| 3382 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3383 | if (!pmbox) { |
| 3384 | /* processing mbox queue from intr_handler */ |
| 3385 | processing_queue = 1; |
| 3386 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3387 | pmbox = lpfc_mbox_get(phba); |
| 3388 | if (!pmbox) { |
| 3389 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3390 | return MBX_SUCCESS; |
| 3391 | } |
| 3392 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3394 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3395 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3396 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3397 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3398 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3399 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3400 | "1806 Mbox x%x failed. No vport\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3401 | pmbox->mb.mbxCommand); |
| 3402 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3403 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3404 | } |
| 3405 | } |
| 3406 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3407 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3408 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3409 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3410 | goto out_not_finished; |
| 3411 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3412 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3414 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | mb = &pmbox->mb; |
| 3416 | status = MBX_SUCCESS; |
| 3417 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3419 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3420 | |
| 3421 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3422 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3423 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3424 | } |
| 3425 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3426 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3427 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3428 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3429 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3430 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3431 | } |
| 3432 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3434 | /* Polling for a mbox command when another one is already active |
| 3435 | * is not allowed in SLI. Also, the driver must have established |
| 3436 | * SLI2 mode to queue and process multiple mbox commands. |
| 3437 | */ |
| 3438 | |
| 3439 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3440 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | |
| 3442 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3443 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3444 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3448 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3450 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3451 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | } |
| 3453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | /* Another mailbox command is still being processed, queue this |
| 3455 | * command to be processed later. |
| 3456 | */ |
| 3457 | lpfc_mbox_put(phba, pmbox); |
| 3458 | |
| 3459 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3460 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3461 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3463 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3464 | mb->mbxCommand, phba->pport->port_state, |
| 3465 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | |
| 3467 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3468 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3470 | if (pmbox->vport) { |
| 3471 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3472 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3473 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3474 | (uint32_t)mb->mbxCommand, |
| 3475 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3476 | } |
| 3477 | else { |
| 3478 | lpfc_debugfs_disc_trc(phba->pport, |
| 3479 | LPFC_DISC_TRC_MBOX, |
| 3480 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3481 | (uint32_t)mb->mbxCommand, |
| 3482 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3483 | } |
| 3484 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3485 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | } |
| 3487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3488 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3489 | |
| 3490 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3491 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3492 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 3493 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3494 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3495 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3497 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3498 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | } |
| 3500 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3501 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3502 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3506 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3507 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3508 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3509 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3510 | mb->mbxCommand, phba->pport->port_state, |
| 3511 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3513 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3514 | if (pmbox->vport) { |
| 3515 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3516 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3517 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3518 | (uint32_t)mb->mbxCommand, |
| 3519 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3520 | } |
| 3521 | else { |
| 3522 | lpfc_debugfs_disc_trc(phba->pport, |
| 3523 | LPFC_DISC_TRC_MBOX, |
| 3524 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3525 | (uint32_t)mb->mbxCommand, |
| 3526 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3527 | } |
| 3528 | } |
| 3529 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | psli->slistat.mbox_cmd++; |
| 3531 | evtctr = psli->slistat.mbox_event; |
| 3532 | |
| 3533 | /* next set own bit for the adapter and copy over command word */ |
| 3534 | mb->mbxOwner = OWN_CHIP; |
| 3535 | |
| 3536 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3538 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3540 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3541 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3542 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3546 | word */ |
| 3547 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3548 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3549 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3550 | |
| 3551 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3552 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3553 | to_slim = phba->MBslimaddr; |
| 3554 | writel(ldata, to_slim); |
| 3555 | readl(to_slim); /* flush */ |
| 3556 | |
| 3557 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3558 | /* switch over to host mailbox */ |
| 3559 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | |
| 3565 | switch (flag) { |
| 3566 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3567 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3569 | /* Interrupt board to do it */ |
| 3570 | writel(CA_MBATT, phba->CAregaddr); |
| 3571 | readl(phba->CAregaddr); /* flush */ |
| 3572 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | break; |
| 3574 | |
| 3575 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3576 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3578 | /* Interrupt board to do it */ |
| 3579 | writel(CA_MBATT, phba->CAregaddr); |
| 3580 | readl(phba->CAregaddr); /* flush */ |
| 3581 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3583 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3584 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | word0 = le32_to_cpu(word0); |
| 3586 | } else { |
| 3587 | /* First read mbox status word */ |
| 3588 | word0 = readl(phba->MBslimaddr); |
| 3589 | } |
| 3590 | |
| 3591 | /* Read the HBA Host Attention Register */ |
| 3592 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3593 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3594 | mb->mbxCommand) * |
| 3595 | 1000) + jiffies; |
| 3596 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3598 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3599 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3600 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3601 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3603 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3605 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | /* Check if we took a mbox interrupt while we were |
| 3609 | polling */ |
| 3610 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3611 | && (evtctr != psli->slistat.mbox_event)) |
| 3612 | break; |
| 3613 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3614 | if (i++ > 10) { |
| 3615 | spin_unlock_irqrestore(&phba->hbalock, |
| 3616 | drvr_flag); |
| 3617 | msleep(1); |
| 3618 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3619 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | |
| 3621 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3622 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3623 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | word0 = le32_to_cpu(word0); |
| 3625 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3626 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3627 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | /* Check real SLIM for any errors */ |
| 3629 | slimword0 = readl(phba->MBslimaddr); |
| 3630 | slimmb = (MAILBOX_t *) & slimword0; |
| 3631 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3632 | && slimmb->mbxStatus) { |
| 3633 | psli->sli_flag &= |
| 3634 | ~LPFC_SLI2_ACTIVE; |
| 3635 | word0 = slimword0; |
| 3636 | } |
| 3637 | } |
| 3638 | } else { |
| 3639 | /* First copy command data */ |
| 3640 | word0 = readl(phba->MBslimaddr); |
| 3641 | } |
| 3642 | /* Read the HBA Host Attention Register */ |
| 3643 | ha_copy = readl(phba->HAregaddr); |
| 3644 | } |
| 3645 | |
| 3646 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3648 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | } else { |
| 3650 | /* First copy command data */ |
| 3651 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3652 | MAILBOX_CMD_SIZE); |
| 3653 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3654 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3655 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3657 | mb->un.varDmp.word_cnt); |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | writel(HA_MBATT, phba->HAregaddr); |
| 3662 | readl(phba->HAregaddr); /* flush */ |
| 3663 | |
| 3664 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3665 | status = mb->mbxStatus; |
| 3666 | } |
| 3667 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3668 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3669 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3670 | |
| 3671 | out_not_finished: |
| 3672 | if (processing_queue) { |
| 3673 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3674 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3675 | } |
| 3676 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | } |
| 3678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3679 | /** |
| 3680 | * __lpfc_sli_ringtx_put: Add an iocb to the txq. |
| 3681 | * @phba: Pointer to HBA context object. |
| 3682 | * @pring: Pointer to driver SLI ring object. |
| 3683 | * @piocb: Pointer to address of newly added command iocb. |
| 3684 | * |
| 3685 | * This function is called with hbalock held to add a command |
| 3686 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3687 | * to the ring. |
| 3688 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3689 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3690 | __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] | 3691 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | { |
| 3693 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3694 | list_add_tail(&piocb->list, &pring->txq); |
| 3695 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | } |
| 3697 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3698 | /** |
| 3699 | * lpfc_sli_next_iocb: Get the next iocb in the txq. |
| 3700 | * @phba: Pointer to HBA context object. |
| 3701 | * @pring: Pointer to driver SLI ring object. |
| 3702 | * @piocb: Pointer to address of newly added command iocb. |
| 3703 | * |
| 3704 | * This function is called with hbalock held before a new |
| 3705 | * iocb is submitted to the firmware. This function checks |
| 3706 | * txq to flush the iocbs in txq to Firmware before |
| 3707 | * submitting new iocbs to the Firmware. |
| 3708 | * If there are iocbs in the txq which need to be submitted |
| 3709 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3710 | * of the txq after dequeuing it from txq. |
| 3711 | * If there is no iocb in the txq then the function will return |
| 3712 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3713 | * *piocb to find if there are more commands in the txq. |
| 3714 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | static struct lpfc_iocbq * |
| 3716 | 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] | 3717 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | { |
| 3719 | struct lpfc_iocbq * nextiocb; |
| 3720 | |
| 3721 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3722 | if (!nextiocb) { |
| 3723 | nextiocb = *piocb; |
| 3724 | *piocb = NULL; |
| 3725 | } |
| 3726 | |
| 3727 | return nextiocb; |
| 3728 | } |
| 3729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3730 | /** |
| 3731 | * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb. |
| 3732 | * @phba: Pointer to HBA context object. |
| 3733 | * @pring: Pointer to driver SLI ring object. |
| 3734 | * @piocb: Pointer to command iocb. |
| 3735 | * @flag: Flag indicating if this command can be put into txq. |
| 3736 | * |
| 3737 | * __lpfc_sli_issue_iocb is used by other functions in the driver |
| 3738 | * to issue an iocb command to the HBA. If the PCI slot is recovering |
| 3739 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3740 | * flag is turned on, the function returns IOCB_ERROR. |
| 3741 | * When the link is down, this function allows only iocbs for |
| 3742 | * posting buffers. |
| 3743 | * This function finds next available slot in the command ring and |
| 3744 | * posts the command to the available slot and writes the port |
| 3745 | * attention register to request HBA start processing new iocb. |
| 3746 | * If there is no slot available in the ring and |
| 3747 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the |
| 3748 | * txq, otherwise the function returns IOCB_BUSY. |
| 3749 | * |
| 3750 | * This function is called with hbalock held. |
| 3751 | * The function will return success after it successfully submit the |
| 3752 | * iocb to firmware or after adding to the txq. |
| 3753 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3754 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3755 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3757 | { |
| 3758 | struct lpfc_iocbq *nextiocb; |
| 3759 | IOCB_t *iocb; |
| 3760 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3761 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3762 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3763 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3764 | lpfc_printf_log(phba, KERN_ERR, |
| 3765 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3766 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3767 | piocb->iocb.ulpCommand); |
| 3768 | dump_stack(); |
| 3769 | return IOCB_ERROR; |
| 3770 | } |
| 3771 | |
| 3772 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3773 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3774 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3775 | return IOCB_ERROR; |
| 3776 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | /* |
| 3778 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3779 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | return IOCB_ERROR; |
| 3782 | |
| 3783 | /* |
| 3784 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3785 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3787 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | goto iocb_busy; |
| 3789 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3790 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3792 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | * can be issued if the link is not up. |
| 3794 | */ |
| 3795 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3796 | case CMD_GEN_REQUEST64_CR: |
| 3797 | case CMD_GEN_REQUEST64_CX: |
| 3798 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 3799 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 3800 | FC_FCP_CMND) || |
| 3801 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 3802 | MENLO_TRANSPORT_TYPE)) |
| 3803 | |
| 3804 | goto iocb_busy; |
| 3805 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | case CMD_QUE_RING_BUF_CN: |
| 3807 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | /* |
| 3809 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3810 | * completion, iocb_cmpl MUST be 0. |
| 3811 | */ |
| 3812 | if (piocb->iocb_cmpl) |
| 3813 | piocb->iocb_cmpl = NULL; |
| 3814 | /*FALLTHROUGH*/ |
| 3815 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3816 | case CMD_CLOSE_XRI_CN: |
| 3817 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3818 | break; |
| 3819 | default: |
| 3820 | goto iocb_busy; |
| 3821 | } |
| 3822 | |
| 3823 | /* |
| 3824 | * For FCP commands, we must be in a state where we can process link |
| 3825 | * attention events. |
| 3826 | */ |
| 3827 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3828 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3830 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3833 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3834 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3835 | |
| 3836 | if (iocb) |
| 3837 | lpfc_sli_update_ring(phba, pring); |
| 3838 | else |
| 3839 | lpfc_sli_update_full_ring(phba, pring); |
| 3840 | |
| 3841 | if (!piocb) |
| 3842 | return IOCB_SUCCESS; |
| 3843 | |
| 3844 | goto out_busy; |
| 3845 | |
| 3846 | iocb_busy: |
| 3847 | pring->stats.iocb_cmd_delay++; |
| 3848 | |
| 3849 | out_busy: |
| 3850 | |
| 3851 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | return IOCB_SUCCESS; |
| 3854 | } |
| 3855 | |
| 3856 | return IOCB_BUSY; |
| 3857 | } |
| 3858 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3860 | /** |
| 3861 | * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb. |
| 3862 | * @phba: Pointer to HBA context object. |
| 3863 | * @pring: Pointer to driver SLI ring object. |
| 3864 | * @piocb: Pointer to command iocb. |
| 3865 | * @flag: Flag indicating if this command can be put into txq. |
| 3866 | * |
| 3867 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 3868 | * function. This function gets the hbalock and calls |
| 3869 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 3870 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 3871 | * functions which do not hold hbalock. |
| 3872 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3873 | int |
| 3874 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3875 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3876 | { |
| 3877 | unsigned long iflags; |
| 3878 | int rc; |
| 3879 | |
| 3880 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 3881 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 3882 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 3883 | |
| 3884 | return rc; |
| 3885 | } |
| 3886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3887 | /** |
| 3888 | * lpfc_extra_ring_setup: Extra ring setup function. |
| 3889 | * @phba: Pointer to HBA context object. |
| 3890 | * |
| 3891 | * This function is called while driver attaches with the |
| 3892 | * HBA to setup the extra ring. The extra ring is used |
| 3893 | * only when driver needs to support target mode functionality |
| 3894 | * or IP over FC functionalities. |
| 3895 | * |
| 3896 | * This function is called with no lock held. |
| 3897 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3898 | static int |
| 3899 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 3900 | { |
| 3901 | struct lpfc_sli *psli; |
| 3902 | struct lpfc_sli_ring *pring; |
| 3903 | |
| 3904 | psli = &phba->sli; |
| 3905 | |
| 3906 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3907 | |
| 3908 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3909 | pring = &psli->ring[psli->fcp_ring]; |
| 3910 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3911 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3912 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3913 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3914 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3915 | /* and give them to the extra ring */ |
| 3916 | pring = &psli->ring[psli->extra_ring]; |
| 3917 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3918 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3919 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3920 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3921 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3922 | |
| 3923 | /* Setup default profile for this ring */ |
| 3924 | pring->iotag_max = 4096; |
| 3925 | pring->num_mask = 1; |
| 3926 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3927 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 3928 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3929 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 3930 | return 0; |
| 3931 | } |
| 3932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3933 | /** |
| 3934 | * lpfc_sli_async_event_handler: ASYNC iocb handler function. |
| 3935 | * @phba: Pointer to HBA context object. |
| 3936 | * @pring: Pointer to driver SLI ring object. |
| 3937 | * @iocbq: Pointer to iocb object. |
| 3938 | * |
| 3939 | * This function is called by the slow ring event handler |
| 3940 | * function when there is an ASYNC event iocb in the ring. |
| 3941 | * This function is called with no lock held. |
| 3942 | * Currently this function handles only temperature related |
| 3943 | * ASYNC events. The function decodes the temperature sensor |
| 3944 | * event message and posts events for the management applications. |
| 3945 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3946 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3947 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 3948 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 3949 | { |
| 3950 | IOCB_t *icmd; |
| 3951 | uint16_t evt_code; |
| 3952 | uint16_t temp; |
| 3953 | struct temp_event temp_event_data; |
| 3954 | struct Scsi_Host *shost; |
| 3955 | |
| 3956 | icmd = &iocbq->iocb; |
| 3957 | evt_code = icmd->un.asyncstat.evt_code; |
| 3958 | temp = icmd->ulpContext; |
| 3959 | |
| 3960 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 3961 | (evt_code != ASYNC_TEMP_SAFE)) { |
| 3962 | lpfc_printf_log(phba, |
| 3963 | KERN_ERR, |
| 3964 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3965 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3966 | " evt_code 0x%x\n", |
| 3967 | pring->ringno, |
| 3968 | icmd->un.asyncstat.evt_code); |
| 3969 | return; |
| 3970 | } |
| 3971 | temp_event_data.data = (uint32_t)temp; |
| 3972 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 3973 | if (evt_code == ASYNC_TEMP_WARN) { |
| 3974 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 3975 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3976 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3977 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3978 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3979 | "corrective action. temperature : %d Celsius\n", |
| 3980 | temp); |
| 3981 | } |
| 3982 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 3983 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 3984 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3985 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3986 | LOG_TEMP, |
| 3987 | "0340 Adapter temperature is OK now. " |
| 3988 | "temperature : %d Celsius\n", |
| 3989 | temp); |
| 3990 | } |
| 3991 | |
| 3992 | /* Send temperature change event to applications */ |
| 3993 | shost = lpfc_shost_from_vport(phba->pport); |
| 3994 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3995 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 3996 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 3997 | |
| 3998 | } |
| 3999 | |
| 4000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4001 | /** |
| 4002 | * lpfc_sli_setup: SLI ring setup function. |
| 4003 | * @phba: Pointer to HBA context object. |
| 4004 | * |
| 4005 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 4006 | * number of iocbs per ring and iotags. This function is |
| 4007 | * called while driver attach to the HBA and before the |
| 4008 | * interrupts are enabled. So there is no need for locking. |
| 4009 | * |
| 4010 | * This function always returns 0. |
| 4011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | int |
| 4013 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 4014 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4015 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | struct lpfc_sli *psli = &phba->sli; |
| 4017 | struct lpfc_sli_ring *pring; |
| 4018 | |
| 4019 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 4020 | psli->sli_flag = 0; |
| 4021 | psli->fcp_ring = LPFC_FCP_RING; |
| 4022 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4023 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4025 | psli->iocbq_lookup = NULL; |
| 4026 | psli->iocbq_lookup_len = 0; |
| 4027 | psli->last_iotag = 0; |
| 4028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | for (i = 0; i < psli->num_rings; i++) { |
| 4030 | pring = &psli->ring[i]; |
| 4031 | switch (i) { |
| 4032 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 4033 | /* numCiocb and numRiocb are used in config_port */ |
| 4034 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 4035 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 4036 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4037 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4038 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4039 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4040 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4041 | SLI3_IOCB_CMD_SIZE : |
| 4042 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4043 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | SLI3_IOCB_RSP_SIZE : |
| 4045 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | pring->iotag_ctr = 0; |
| 4047 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | pring->fast_iotag = pring->iotag_max; |
| 4050 | pring->num_mask = 0; |
| 4051 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4052 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | /* numCiocb and numRiocb are used in config_port */ |
| 4054 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 4055 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4056 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4057 | SLI3_IOCB_CMD_SIZE : |
| 4058 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4059 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | SLI3_IOCB_RSP_SIZE : |
| 4061 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4062 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | pring->num_mask = 0; |
| 4064 | break; |
| 4065 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 4066 | /* numCiocb and numRiocb are used in config_port */ |
| 4067 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 4068 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4069 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4070 | SLI3_IOCB_CMD_SIZE : |
| 4071 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4072 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | SLI3_IOCB_RSP_SIZE : |
| 4074 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | pring->fast_iotag = 0; |
| 4076 | pring->iotag_ctr = 0; |
| 4077 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4078 | pring->lpfc_sli_rcv_async_status = |
| 4079 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4080 | pring->num_mask = 4; |
| 4081 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 4082 | pring->prt[0].rctl = FC_ELS_REQ; |
| 4083 | pring->prt[0].type = FC_ELS_DATA; |
| 4084 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4085 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 4087 | pring->prt[1].rctl = FC_ELS_RSP; |
| 4088 | pring->prt[1].type = FC_ELS_DATA; |
| 4089 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4090 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 4092 | /* NameServer Inquiry */ |
| 4093 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 4094 | /* NameServer */ |
| 4095 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 4096 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4097 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 4099 | /* NameServer response */ |
| 4100 | pring->prt[3].rctl = FC_SOL_CTL; |
| 4101 | /* NameServer */ |
| 4102 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 4103 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4104 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | break; |
| 4106 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4107 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4108 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4110 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4111 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4112 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 4113 | "SLI2 SLIM Data: x%x x%lx\n", |
| 4114 | phba->brd_no, totiocbsize, |
| 4115 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4117 | if (phba->cfg_multi_ring_support == 2) |
| 4118 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | |
| 4120 | return 0; |
| 4121 | } |
| 4122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4123 | /** |
| 4124 | * lpfc_sli_queue_setup: Queue initialization function. |
| 4125 | * @phba: Pointer to HBA context object. |
| 4126 | * |
| 4127 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4128 | * ring. This function also initializes ring indices of each ring. |
| 4129 | * This function is called during the initialization of the SLI |
| 4130 | * interface of an HBA. |
| 4131 | * This function is called with no lock held and always returns |
| 4132 | * 1. |
| 4133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4135 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 | { |
| 4137 | struct lpfc_sli *psli; |
| 4138 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4139 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | |
| 4141 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4144 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4146 | for (i = 0; i < psli->num_rings; i++) { |
| 4147 | pring = &psli->ring[i]; |
| 4148 | pring->ringno = i; |
| 4149 | pring->next_cmdidx = 0; |
| 4150 | pring->local_getidx = 0; |
| 4151 | pring->cmdidx = 0; |
| 4152 | INIT_LIST_HEAD(&pring->txq); |
| 4153 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4154 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4155 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4158 | spin_unlock_irq(&phba->hbalock); |
| 4159 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | } |
| 4161 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4162 | /** |
| 4163 | * lpfc_sli_host_down: Vport cleanup function. |
| 4164 | * @vport: Pointer to virtual port object. |
| 4165 | * |
| 4166 | * lpfc_sli_host_down is called to clean up the resources |
| 4167 | * associated with a vport before destroying virtual |
| 4168 | * port data structures. |
| 4169 | * This function does following operations: |
| 4170 | * - Free discovery resources associated with this virtual |
| 4171 | * port. |
| 4172 | * - Free iocbs associated with this virtual port in |
| 4173 | * the txq. |
| 4174 | * - Send abort for all iocb commands associated with this |
| 4175 | * vport in txcmplq. |
| 4176 | * |
| 4177 | * This function is called with no lock held and always returns 1. |
| 4178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4180 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4181 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4182 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4183 | struct lpfc_hba *phba = vport->phba; |
| 4184 | struct lpfc_sli *psli = &phba->sli; |
| 4185 | struct lpfc_sli_ring *pring; |
| 4186 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | int i; |
| 4188 | unsigned long flags = 0; |
| 4189 | uint16_t prev_pring_flag; |
| 4190 | |
| 4191 | lpfc_cleanup_discovery_resources(vport); |
| 4192 | |
| 4193 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4194 | for (i = 0; i < psli->num_rings; i++) { |
| 4195 | pring = &psli->ring[i]; |
| 4196 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4197 | /* Only slow rings */ |
| 4198 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4199 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4200 | /* Set the lpfc data pending flag */ |
| 4201 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4202 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4203 | /* |
| 4204 | * Error everything on the txq since these iocbs have not been |
| 4205 | * given to the FW yet. |
| 4206 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4207 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4208 | if (iocb->vport != vport) |
| 4209 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4210 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4211 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | /* Next issue ABTS for everything on the txcmplq */ |
| 4215 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4216 | list) { |
| 4217 | if (iocb->vport != vport) |
| 4218 | continue; |
| 4219 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4220 | } |
| 4221 | |
| 4222 | pring->flag = prev_pring_flag; |
| 4223 | } |
| 4224 | |
| 4225 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4226 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4227 | while (!list_empty(&completions)) { |
| 4228 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
| 4229 | |
| 4230 | if (!iocb->iocb_cmpl) |
| 4231 | lpfc_sli_release_iocbq(phba, iocb); |
| 4232 | else { |
| 4233 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4234 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4235 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 4236 | } |
| 4237 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4238 | return 1; |
| 4239 | } |
| 4240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4241 | /** |
| 4242 | * lpfc_sli_hba_down: Resource cleanup function for the HBA. |
| 4243 | * @phba: Pointer to HBA context object. |
| 4244 | * |
| 4245 | * This function cleans up all iocb, buffers, mailbox commands |
| 4246 | * while shutting down the HBA. This function is called with no |
| 4247 | * lock held and always returns 1. |
| 4248 | * This function does the following to cleanup driver resources: |
| 4249 | * - Free discovery resources for each virtual port |
| 4250 | * - Cleanup any pending fabric iocbs |
| 4251 | * - Iterate through the iocb txq and free each entry |
| 4252 | * in the list. |
| 4253 | * - Free up any buffer posted to the HBA |
| 4254 | * - Free mailbox commands in the mailbox queue. |
| 4255 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4256 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4259 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4260 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4262 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4263 | LPFC_MBOXQ_t *pmb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4264 | struct lpfc_iocbq *iocb; |
| 4265 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | int i; |
| 4267 | unsigned long flags = 0; |
| 4268 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4269 | lpfc_hba_down_prep(phba); |
| 4270 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4271 | lpfc_fabric_abort_hba(phba); |
| 4272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | for (i = 0; i < psli->num_rings; i++) { |
| 4275 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4276 | /* Only slow rings */ |
| 4277 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4278 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4279 | /* Set the lpfc data pending flag */ |
| 4280 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4281 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
| 4283 | /* |
| 4284 | * Error everything on the txq since these iocbs have not been |
| 4285 | * given to the FW yet. |
| 4286 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4287 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | pring->txq_cnt = 0; |
| 4289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4290 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4293 | while (!list_empty(&completions)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4294 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4295 | cmd = &iocb->iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4296 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4297 | if (!iocb->iocb_cmpl) |
| 4298 | lpfc_sli_release_iocbq(phba, iocb); |
| 4299 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4300 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4301 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4302 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4303 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4304 | } |
| 4305 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4306 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4307 | list_splice_init(&phba->elsbuf, &completions); |
| 4308 | phba->elsbuf_cnt = 0; |
| 4309 | phba->elsbuf_prev_cnt = 0; |
| 4310 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4311 | |
| 4312 | while (!list_empty(&completions)) { |
| 4313 | list_remove_head(&completions, buf_ptr, |
| 4314 | struct lpfc_dmabuf, list); |
| 4315 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4316 | kfree(buf_ptr); |
| 4317 | } |
| 4318 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | /* Return any active mbox cmds */ |
| 4320 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4321 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4322 | |
| 4323 | spin_lock(&phba->pport->work_port_lock); |
| 4324 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4325 | spin_unlock(&phba->pport->work_port_lock); |
| 4326 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4327 | /* Return any pending or completed mbox cmds */ |
| 4328 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4329 | if (psli->mbox_active) { |
| 4330 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4331 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4334 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4335 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4336 | |
| 4337 | while (!list_empty(&completions)) { |
| 4338 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4340 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | return 1; |
| 4344 | } |
| 4345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4346 | /** |
| 4347 | * lpfc_sli_pcimem_bcopy: SLI memory copy function. |
| 4348 | * @srcp: Source memory pointer. |
| 4349 | * @destp: Destination memory pointer. |
| 4350 | * @cnt: Number of words required to be copied. |
| 4351 | * |
| 4352 | * This function is used for copying data between driver memory |
| 4353 | * and the SLI memory. This function also changes the endianness |
| 4354 | * of each word if native endianness is different from SLI |
| 4355 | * endianness. This function can be called with or without |
| 4356 | * lock. |
| 4357 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | void |
| 4359 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4360 | { |
| 4361 | uint32_t *src = srcp; |
| 4362 | uint32_t *dest = destp; |
| 4363 | uint32_t ldata; |
| 4364 | int i; |
| 4365 | |
| 4366 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4367 | ldata = *src; |
| 4368 | ldata = le32_to_cpu(ldata); |
| 4369 | *dest = ldata; |
| 4370 | src++; |
| 4371 | dest++; |
| 4372 | } |
| 4373 | } |
| 4374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4375 | |
| 4376 | /** |
| 4377 | * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq. |
| 4378 | * @phba: Pointer to HBA context object. |
| 4379 | * @pring: Pointer to driver SLI ring object. |
| 4380 | * @mp: Pointer to driver buffer object. |
| 4381 | * |
| 4382 | * This function is called with no lock held. |
| 4383 | * It always return zero after adding the buffer to the postbufq |
| 4384 | * buffer list. |
| 4385 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4388 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | { |
| 4390 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4391 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4394 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | return 0; |
| 4397 | } |
| 4398 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4399 | /** |
| 4400 | * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted |
| 4401 | * using CMD_QUE_XRI64_CX iocb. |
| 4402 | * @phba: Pointer to HBA context object. |
| 4403 | * |
| 4404 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4405 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4406 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4407 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4408 | * The function returns the allocated tag. The function is called with |
| 4409 | * no locks held. |
| 4410 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4411 | uint32_t |
| 4412 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4413 | { |
| 4414 | spin_lock_irq(&phba->hbalock); |
| 4415 | phba->buffer_tag_count++; |
| 4416 | /* |
| 4417 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4418 | * a tag assigned by HBQ. |
| 4419 | */ |
| 4420 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4421 | spin_unlock_irq(&phba->hbalock); |
| 4422 | return phba->buffer_tag_count; |
| 4423 | } |
| 4424 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4425 | /** |
| 4426 | * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with |
| 4427 | * posted using CMD_QUE_XRI64_CX iocb. |
| 4428 | * @phba: Pointer to HBA context object. |
| 4429 | * @pring: Pointer to driver SLI ring object. |
| 4430 | * @tag: Buffer tag. |
| 4431 | * |
| 4432 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4433 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4434 | * iocb is posted to the response ring with the tag of the buffer. |
| 4435 | * This function searches the pring->postbufq list using the tag |
| 4436 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4437 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4438 | * buffer is returned to the caller else NULL is returned. |
| 4439 | * This function is called with no lock held. |
| 4440 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4441 | struct lpfc_dmabuf * |
| 4442 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4443 | uint32_t tag) |
| 4444 | { |
| 4445 | struct lpfc_dmabuf *mp, *next_mp; |
| 4446 | struct list_head *slp = &pring->postbufq; |
| 4447 | |
| 4448 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4449 | spin_lock_irq(&phba->hbalock); |
| 4450 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4451 | if (mp->buffer_tag == tag) { |
| 4452 | list_del_init(&mp->list); |
| 4453 | pring->postbufq_cnt--; |
| 4454 | spin_unlock_irq(&phba->hbalock); |
| 4455 | return mp; |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | spin_unlock_irq(&phba->hbalock); |
| 4460 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4461 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4462 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4463 | pring->ringno, (unsigned long) tag, |
| 4464 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4465 | |
| 4466 | return NULL; |
| 4467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4469 | /** |
| 4470 | * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for |
| 4471 | * unsolicited ct and els events. |
| 4472 | * @phba: Pointer to HBA context object. |
| 4473 | * @pring: Pointer to driver SLI ring object. |
| 4474 | * @phys: DMA address of the buffer. |
| 4475 | * |
| 4476 | * This function searches the buffer list using the dma_address |
| 4477 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4478 | * corresponding to the dma_address. The function returns the |
| 4479 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4480 | * This function is called by the ct and els unsolicited event |
| 4481 | * handlers to get the buffer associated with the unsolicited |
| 4482 | * event. |
| 4483 | * |
| 4484 | * This function is called with no lock held. |
| 4485 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | struct lpfc_dmabuf * |
| 4487 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4488 | dma_addr_t phys) |
| 4489 | { |
| 4490 | struct lpfc_dmabuf *mp, *next_mp; |
| 4491 | struct list_head *slp = &pring->postbufq; |
| 4492 | |
| 4493 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4496 | if (mp->phys == phys) { |
| 4497 | list_del_init(&mp->list); |
| 4498 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4499 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4500 | return mp; |
| 4501 | } |
| 4502 | } |
| 4503 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4504 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4506 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4508 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4510 | return NULL; |
| 4511 | } |
| 4512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4513 | /** |
| 4514 | * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs. |
| 4515 | * @phba: Pointer to HBA context object. |
| 4516 | * @cmdiocb: Pointer to driver command iocb object. |
| 4517 | * @rspiocb: Pointer to driver response iocb object. |
| 4518 | * |
| 4519 | * This function is the completion handler for the abort iocbs for |
| 4520 | * ELS commands. This function is called from the ELS ring event |
| 4521 | * handler with no lock held. This function frees memory resources |
| 4522 | * associated with the abort iocb. |
| 4523 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4525 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4526 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4528 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4529 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4530 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4531 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4532 | |
| 4533 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4534 | |
| 4535 | if (irsp->ulpStatus) { |
| 4536 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4537 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4538 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4539 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4540 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4541 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4542 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4543 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4544 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4545 | "with tag %x context %x, abort status %x, " |
| 4546 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4547 | abort_iocb, abort_iotag, abort_context, |
| 4548 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4549 | |
| 4550 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4551 | * If the iocb is not found in Firmware queue the iocb |
| 4552 | * might have completed already. Do not free it again. |
| 4553 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4554 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4555 | spin_unlock_irq(&phba->hbalock); |
| 4556 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4557 | return; |
| 4558 | } |
| 4559 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4560 | * make sure we have the right iocbq before taking it |
| 4561 | * off the txcmplq and try to call completion routine. |
| 4562 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4563 | if (!abort_iocb || |
| 4564 | abort_iocb->iocb.ulpContext != abort_context || |
| 4565 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4566 | spin_unlock_irq(&phba->hbalock); |
| 4567 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4568 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4569 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4570 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4571 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4572 | /* Firmware could still be in progress of DMAing |
| 4573 | * payload, so don't free data buffer till after |
| 4574 | * a hbeat. |
| 4575 | */ |
| 4576 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4577 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4578 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4579 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4580 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4581 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4585 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4586 | return; |
| 4587 | } |
| 4588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4589 | /** |
| 4590 | * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command. |
| 4591 | * @phba: Pointer to HBA context object. |
| 4592 | * @cmdiocb: Pointer to driver command iocb object. |
| 4593 | * @rspiocb: Pointer to driver response iocb object. |
| 4594 | * |
| 4595 | * The function is called from SLI ring event handler with no |
| 4596 | * lock held. This function is the completion handler for ELS commands |
| 4597 | * which are aborted. The function frees memory resources used for |
| 4598 | * the aborted ELS commands. |
| 4599 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4600 | static void |
| 4601 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4602 | struct lpfc_iocbq *rspiocb) |
| 4603 | { |
| 4604 | IOCB_t *irsp = &rspiocb->iocb; |
| 4605 | |
| 4606 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4607 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4608 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4609 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4610 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4611 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4612 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4613 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4614 | else |
| 4615 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4616 | return; |
| 4617 | } |
| 4618 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4619 | /** |
| 4620 | * lpfc_sli_issue_abort_iotag: Abort function for a command iocb. |
| 4621 | * @phba: Pointer to HBA context object. |
| 4622 | * @pring: Pointer to driver SLI ring object. |
| 4623 | * @cmdiocb: Pointer to driver command iocb object. |
| 4624 | * |
| 4625 | * This function issues an abort iocb for the provided command |
| 4626 | * iocb. This function is called with hbalock held. |
| 4627 | * The function returns 0 when it fails due to memory allocation |
| 4628 | * failure or when the command iocb is an abort request. |
| 4629 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4632 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4634 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4635 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4636 | IOCB_t *icmd = NULL; |
| 4637 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4638 | int retval = IOCB_ERROR; |
| 4639 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4640 | /* |
| 4641 | * There are certain command types we don't want to abort. And we |
| 4642 | * don't want to abort commands that are already in the process of |
| 4643 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4644 | */ |
| 4645 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4647 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4648 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4649 | return 0; |
| 4650 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4651 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4652 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4653 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4654 | if ((vport->load_flag & FC_UNLOADING) && |
| 4655 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4656 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4657 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4658 | else |
| 4659 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4660 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4661 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4662 | |
| 4663 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4664 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | if (abtsiocbp == NULL) |
| 4666 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4667 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4668 | /* This signals the response to set the correct status |
| 4669 | * before calling the completion handler. |
| 4670 | */ |
| 4671 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4672 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4674 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4675 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4676 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4677 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4678 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4680 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4681 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4682 | else |
| 4683 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4684 | |
| 4685 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4686 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4687 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4688 | "0339 Abort xri x%x, original iotag x%x, " |
| 4689 | "abort cmd iotag x%x\n", |
| 4690 | iabt->un.acxri.abortContextTag, |
| 4691 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4692 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4693 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4694 | if (retval) |
| 4695 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4696 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4697 | /* |
| 4698 | * Caller to this routine should check for IOCB_ERROR |
| 4699 | * and handle it properly. This routine no longer removes |
| 4700 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4701 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4702 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | } |
| 4704 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4705 | /** |
| 4706 | * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands |
| 4707 | * associated with a vport/SCSI target/lun. |
| 4708 | * @iocbq: Pointer to driver iocb object. |
| 4709 | * @vport: Pointer to driver virtual port object. |
| 4710 | * @tgt_id: SCSI ID of the target. |
| 4711 | * @lun_id: LUN ID of the scsi device. |
| 4712 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4713 | * |
| 4714 | * This function acts as iocb filter for functions which abort or count |
| 4715 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4716 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4717 | * 1 if the filtering criteria is not met. |
| 4718 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4719 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4720 | * lun_id parameter. |
| 4721 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4722 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4723 | * parameters. |
| 4724 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4725 | * given iocb is for the SCSI host associated with the given vport. |
| 4726 | * This function is called with no locks held. |
| 4727 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4729 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4730 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4731 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4733 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | int rc = 1; |
| 4735 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4736 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4737 | return rc; |
| 4738 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4739 | if (iocbq->vport != vport) |
| 4740 | return rc; |
| 4741 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4742 | 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] | 4743 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4744 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | return rc; |
| 4746 | |
| 4747 | switch (ctx_cmd) { |
| 4748 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4749 | if ((lpfc_cmd->rdata->pnode) && |
| 4750 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4751 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | rc = 0; |
| 4753 | break; |
| 4754 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4755 | if ((lpfc_cmd->rdata->pnode) && |
| 4756 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4757 | rc = 0; |
| 4758 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | case LPFC_CTX_HOST: |
| 4760 | rc = 0; |
| 4761 | break; |
| 4762 | default: |
| 4763 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4764 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | |
| 4768 | return rc; |
| 4769 | } |
| 4770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4771 | /** |
| 4772 | * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending. |
| 4773 | * @vport: Pointer to virtual port. |
| 4774 | * @tgt_id: SCSI ID of the target. |
| 4775 | * @lun_id: LUN ID of the scsi device. |
| 4776 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4777 | * |
| 4778 | * This function returns number of FCP commands pending for the vport. |
| 4779 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4780 | * commands pending on the vport associated with SCSI device specified |
| 4781 | * by tgt_id and lun_id parameters. |
| 4782 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4783 | * commands pending on the vport associated with SCSI target specified |
| 4784 | * by tgt_id parameter. |
| 4785 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4786 | * commands pending on the vport. |
| 4787 | * This function returns the number of iocbs which satisfy the filter. |
| 4788 | * This function is called without any lock held. |
| 4789 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4791 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4792 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4793 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4794 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4795 | struct lpfc_iocbq *iocbq; |
| 4796 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4797 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4798 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4799 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4800 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4801 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4802 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4803 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4804 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4805 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4806 | return sum; |
| 4807 | } |
| 4808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4809 | /** |
| 4810 | * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted |
| 4811 | * FCP iocb. |
| 4812 | * @phba: Pointer to HBA context object |
| 4813 | * @cmdiocb: Pointer to command iocb object. |
| 4814 | * @rspiocb: Pointer to response iocb object. |
| 4815 | * |
| 4816 | * This function is called when an aborted FCP iocb completes. This |
| 4817 | * function is called by the ring event handler with no lock held. |
| 4818 | * This function frees the iocb. |
| 4819 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4820 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4821 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4822 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4823 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4824 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4825 | return; |
| 4826 | } |
| 4827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4828 | /** |
| 4829 | * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands |
| 4830 | * pending on a SCSI host(vport)/target/lun. |
| 4831 | * @vport: Pointer to virtual port. |
| 4832 | * @pring: Pointer to driver SLI ring object. |
| 4833 | * @tgt_id: SCSI ID of the target. |
| 4834 | * @lun_id: LUN ID of the scsi device. |
| 4835 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4836 | * |
| 4837 | * This function sends an abort command for every SCSI command |
| 4838 | * associated with the given virtual port pending on the ring |
| 4839 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 4840 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 4841 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 4842 | * parameters |
| 4843 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 4844 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 4845 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 4846 | * FCP iocbs associated with virtual port. |
| 4847 | * This function returns number of iocbs it failed to abort. |
| 4848 | * This function is called with no locks held. |
| 4849 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4850 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4851 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 4852 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4854 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4855 | struct lpfc_iocbq *iocbq; |
| 4856 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4859 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4861 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 4862 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4864 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4865 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | continue; |
| 4867 | |
| 4868 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4869 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | if (abtsiocb == NULL) { |
| 4871 | errcnt++; |
| 4872 | continue; |
| 4873 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4875 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4876 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4877 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 4878 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 4879 | abtsiocb->iocb.ulpLe = 1; |
| 4880 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4881 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4882 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4883 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 4885 | else |
| 4886 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 4887 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4888 | /* Setup callback routine and issue the command. */ |
| 4889 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 4891 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4892 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | errcnt++; |
| 4894 | continue; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | return errcnt; |
| 4899 | } |
| 4900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4901 | /** |
| 4902 | * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using |
| 4903 | * lpfc_sli_issue_iocb_wait. |
| 4904 | * @phba: Pointer to HBA context object. |
| 4905 | * @cmdiocbq: Pointer to command iocb. |
| 4906 | * @rspiocbq: Pointer to response iocb. |
| 4907 | * |
| 4908 | * This function is the completion handler for iocbs issued using |
| 4909 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 4910 | * ring event handler function without any lock held. This function |
| 4911 | * can be called from both worker thread context and interrupt |
| 4912 | * context. This function also can be called from other thread which |
| 4913 | * cleans up the SLI layer objects. |
| 4914 | * This function copy the contents of the response iocb to the |
| 4915 | * response iocb memory object provided by the caller of |
| 4916 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4917 | * sleeps for the iocb completion. |
| 4918 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4919 | static void |
| 4920 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 4921 | struct lpfc_iocbq *cmdiocbq, |
| 4922 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4923 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4924 | wait_queue_head_t *pdone_q; |
| 4925 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4926 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4927 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4928 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 4929 | if (cmdiocbq->context2 && rspiocbq) |
| 4930 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 4931 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 4932 | |
| 4933 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4934 | if (pdone_q) |
| 4935 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4936 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | return; |
| 4938 | } |
| 4939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4940 | /** |
| 4941 | * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands. |
| 4942 | * @phba: Pointer to HBA context object.. |
| 4943 | * @pring: Pointer to sli ring. |
| 4944 | * @piocb: Pointer to command iocb. |
| 4945 | * @prspiocbq: Pointer to response iocb. |
| 4946 | * @timeout: Timeout in number of seconds. |
| 4947 | * |
| 4948 | * This function issues the iocb to firmware and waits for the |
| 4949 | * iocb to complete. If the iocb command is not |
| 4950 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 4951 | * Caller should not free the iocb resources if this function |
| 4952 | * returns IOCB_TIMEDOUT. |
| 4953 | * The function waits for the iocb completion using an |
| 4954 | * non-interruptible wait. |
| 4955 | * This function will sleep while waiting for iocb completion. |
| 4956 | * So, this function should not be called from any context which |
| 4957 | * does not allow sleeping. Due to the same reason, this function |
| 4958 | * cannot be called with interrupt disabled. |
| 4959 | * This function assumes that the iocb completions occur while |
| 4960 | * this function sleep. So, this function cannot be called from |
| 4961 | * the thread which process iocb completion for this ring. |
| 4962 | * This function clears the iocb_flag of the iocb object before |
| 4963 | * issuing the iocb and the iocb completion handler sets this |
| 4964 | * flag and wakes this thread when the iocb completes. |
| 4965 | * The contents of the response iocb will be copied to prspiocbq |
| 4966 | * by the completion handler when the command completes. |
| 4967 | * This function returns IOCB_SUCCESS when success. |
| 4968 | * This function is called with no lock held. |
| 4969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4971 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 4972 | struct lpfc_sli_ring *pring, |
| 4973 | struct lpfc_iocbq *piocb, |
| 4974 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4975 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4977 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4978 | long timeleft, timeout_req = 0; |
| 4979 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4980 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4981 | |
| 4982 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4983 | * If the caller has provided a response iocbq buffer, then context2 |
| 4984 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4986 | if (prspiocbq) { |
| 4987 | if (piocb->context2) |
| 4988 | return IOCB_ERROR; |
| 4989 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | } |
| 4991 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4992 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 4993 | piocb->context_un.wait_queue = &done_q; |
| 4994 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4995 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4996 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4997 | creg_val = readl(phba->HCregaddr); |
| 4998 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 4999 | writel(creg_val, phba->HCregaddr); |
| 5000 | readl(phba->HCregaddr); /* flush */ |
| 5001 | } |
| 5002 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5003 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 5004 | if (retval == IOCB_SUCCESS) { |
| 5005 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5006 | timeleft = wait_event_timeout(done_q, |
| 5007 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 5008 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5010 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 5011 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5012 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5013 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5014 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5015 | "0338 IOCB wait timeout error - no " |
| 5016 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5017 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5018 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5019 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5020 | "0330 IOCB wake NOT set, " |
| 5021 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5022 | timeout, (timeleft / jiffies)); |
| 5023 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5025 | } else { |
| 5026 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5027 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5028 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5029 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | } |
| 5031 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5032 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5033 | creg_val = readl(phba->HCregaddr); |
| 5034 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 5035 | writel(creg_val, phba->HCregaddr); |
| 5036 | readl(phba->HCregaddr); /* flush */ |
| 5037 | } |
| 5038 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5039 | if (prspiocbq) |
| 5040 | piocb->context2 = NULL; |
| 5041 | |
| 5042 | piocb->context_un.wait_queue = NULL; |
| 5043 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5044 | return retval; |
| 5045 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5046 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5047 | /** |
| 5048 | * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox. |
| 5049 | * @phba: Pointer to HBA context object. |
| 5050 | * @pmboxq: Pointer to driver mailbox object. |
| 5051 | * @timeout: Timeout in number of seconds. |
| 5052 | * |
| 5053 | * This function issues the mailbox to firmware and waits for the |
| 5054 | * mailbox command to complete. If the mailbox command is not |
| 5055 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 5056 | * The function waits for the mailbox completion using an |
| 5057 | * interruptible wait. If the thread is woken up due to a |
| 5058 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 5059 | * should not free the mailbox resources, if this function returns |
| 5060 | * MBX_TIMEOUT. |
| 5061 | * This function will sleep while waiting for mailbox completion. |
| 5062 | * So, this function should not be called from any context which |
| 5063 | * does not allow sleeping. Due to the same reason, this function |
| 5064 | * cannot be called with interrupt disabled. |
| 5065 | * This function assumes that the mailbox completion occurs while |
| 5066 | * this function sleep. So, this function cannot be called from |
| 5067 | * the worker thread which processes mailbox completion. |
| 5068 | * This function is called in the context of HBA management |
| 5069 | * applications. |
| 5070 | * This function returns MBX_SUCCESS when successful. |
| 5071 | * This function is called with no lock held. |
| 5072 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5074 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5075 | uint32_t timeout) |
| 5076 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5077 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5078 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5079 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5080 | |
| 5081 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5082 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5083 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5085 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | /* setup wake call as IOCB callback */ |
| 5087 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 5088 | /* setup context field to pass wait_queue pointer to wake function */ |
| 5089 | pmboxq->context1 = &done_q; |
| 5090 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5091 | /* now issue the command */ |
| 5092 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 5093 | |
| 5094 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5095 | wait_event_interruptible_timeout(done_q, |
| 5096 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 5097 | timeout * HZ); |
| 5098 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5099 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5100 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5101 | /* |
| 5102 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 5103 | * else do not free the resources. |
| 5104 | */ |
| 5105 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5107 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5108 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5109 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5110 | } |
| 5111 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | } |
| 5113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | return retval; |
| 5115 | } |
| 5116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5117 | /** |
| 5118 | * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function. |
| 5119 | * @phba: Pointer to HBA context. |
| 5120 | * |
| 5121 | * This function is called to cleanup any pending mailbox |
| 5122 | * objects in the driver queue before bringing the HBA offline. |
| 5123 | * This function is called while resetting the HBA. |
| 5124 | * The function is called without any lock held. The function |
| 5125 | * takes hbalock to update SLI data structure. |
| 5126 | * This function returns 1 when there is an active mailbox |
| 5127 | * command pending else returns 0. |
| 5128 | **/ |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5129 | int |
| 5130 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 5131 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5132 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5133 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5134 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5136 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5137 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 5138 | return 1; |
| 5139 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5140 | /* |
| 5141 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 5142 | * did finish. This way we won't get the misleading |
| 5143 | * "Stray Mailbox Interrupt" message. |
| 5144 | */ |
| 5145 | spin_lock_irq(&phba->hbalock); |
| 5146 | ha_copy = phba->work_ha; |
| 5147 | phba->work_ha &= ~HA_MBATT; |
| 5148 | spin_unlock_irq(&phba->hbalock); |
| 5149 | |
| 5150 | if (ha_copy & HA_MBATT) |
| 5151 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 5152 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5153 | |
| 5154 | msleep(1); |
| 5155 | } |
| 5156 | |
| 5157 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 5158 | } |
| 5159 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5160 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5161 | * lpfc_sli_check_eratt: check error attention events |
| 5162 | * @phba: Pointer to HBA context. |
| 5163 | * |
| 5164 | * This function is called form timer soft interrupt context to check HBA's |
| 5165 | * error attention register bit for error attention events. |
| 5166 | * |
| 5167 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5168 | * Register and returns 0 otherwise. |
| 5169 | **/ |
| 5170 | int |
| 5171 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 5172 | { |
| 5173 | uint32_t ha_copy; |
| 5174 | |
| 5175 | /* If somebody is waiting to handle an eratt, don't process it |
| 5176 | * here. The brdkill function will do this. |
| 5177 | */ |
| 5178 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5179 | return 0; |
| 5180 | |
| 5181 | /* Check if interrupt handler handles this ERATT */ |
| 5182 | spin_lock_irq(&phba->hbalock); |
| 5183 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 5184 | /* Interrupt handler has handled ERATT */ |
| 5185 | spin_unlock_irq(&phba->hbalock); |
| 5186 | return 0; |
| 5187 | } |
| 5188 | |
| 5189 | /* Read chip Host Attention (HA) register */ |
| 5190 | ha_copy = readl(phba->HAregaddr); |
| 5191 | if (ha_copy & HA_ERATT) { |
| 5192 | /* Read host status register to retrieve error event */ |
| 5193 | lpfc_sli_read_hs(phba); |
| 5194 | /* Set the driver HA work bitmap */ |
| 5195 | phba->work_ha |= HA_ERATT; |
| 5196 | /* Indicate polling handles this ERATT */ |
| 5197 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5198 | spin_unlock_irq(&phba->hbalock); |
| 5199 | return 1; |
| 5200 | } |
| 5201 | spin_unlock_irq(&phba->hbalock); |
| 5202 | return 0; |
| 5203 | } |
| 5204 | |
| 5205 | /** |
| 5206 | * lpfc_sp_intr_handler: The slow-path interrupt handler of lpfc driver. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5207 | * @irq: Interrupt number. |
| 5208 | * @dev_id: The device context pointer. |
| 5209 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5210 | * This function is directly called from the PCI layer as an interrupt |
| 5211 | * service routine when the device is enabled with MSI-X multi-message |
| 5212 | * interrupt mode and there are slow-path events in the HBA. However, |
| 5213 | * when the device is enabled with either MSI or Pin-IRQ interrupt mode, |
| 5214 | * this function is called as part of the device-level interrupt handler. |
| 5215 | * When the PCI slot is in error recovery or the HBA is undergoing |
| 5216 | * initialization, the interrupt handler will not process the interrupt. |
| 5217 | * The link attention and ELS ring attention events are handled by the |
| 5218 | * worker thread. The interrupt handler signals the worker thread and |
| 5219 | * and returns for these events. This function is called without any |
| 5220 | * lock held. It gets the hbalock to access and update SLI data |
| 5221 | * structures. |
| 5222 | * |
| 5223 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5224 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5225 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | irqreturn_t |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5227 | lpfc_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | uint32_t ha_copy; |
| 5231 | uint32_t work_ha_copy; |
| 5232 | unsigned long status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | uint32_t control; |
| 5234 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5235 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5236 | struct lpfc_vport *vport; |
| 5237 | struct lpfc_nodelist *ndlp; |
| 5238 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5239 | LPFC_MBOXQ_t *pmb; |
| 5240 | int rc; |
| 5241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | /* |
| 5243 | * Get the driver's phba structure from the dev_id and |
| 5244 | * assume the HBA is not interrupting. |
| 5245 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5246 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5247 | |
| 5248 | if (unlikely(!phba)) |
| 5249 | return IRQ_NONE; |
| 5250 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5252 | * Stuff needs to be attented to when this function is invoked as an |
| 5253 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5255 | if (phba->intr_type == MSIX) { |
| 5256 | /* If the pci channel is offline, ignore all the interrupts */ |
| 5257 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5258 | return IRQ_NONE; |
| 5259 | /* Update device-level interrupt statistics */ |
| 5260 | phba->sli.slistat.sli_intr++; |
| 5261 | /* Ignore all interrupts during initialization. */ |
| 5262 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5263 | return IRQ_NONE; |
| 5264 | /* Need to read HA REG for slow-path events */ |
| 5265 | spin_lock(&phba->hbalock); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5266 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5267 | /* If somebody is waiting to handle an eratt don't process it |
| 5268 | * here. The brdkill function will do this. |
| 5269 | */ |
| 5270 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5271 | ha_copy &= ~HA_ERATT; |
| 5272 | /* Check the need for handling ERATT in interrupt handler */ |
| 5273 | if (ha_copy & HA_ERATT) { |
| 5274 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5275 | /* ERATT polling has handled ERATT */ |
| 5276 | ha_copy &= ~HA_ERATT; |
| 5277 | else |
| 5278 | /* Indicate interrupt handler handles ERATT */ |
| 5279 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5280 | } |
| 5281 | /* Clear up only attention source related to slow-path */ |
| 5282 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 5283 | phba->HAregaddr); |
| 5284 | readl(phba->HAregaddr); /* flush */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5285 | spin_unlock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5286 | } else |
| 5287 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5290 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5291 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5292 | if (work_ha_copy & HA_LATT) { |
| 5293 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5294 | /* |
| 5295 | * Turn off Link Attention interrupts |
| 5296 | * until CLEAR_LA done |
| 5297 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5298 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5300 | control = readl(phba->HCregaddr); |
| 5301 | control &= ~HC_LAINT_ENA; |
| 5302 | writel(control, phba->HCregaddr); |
| 5303 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5304 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5305 | } |
| 5306 | else |
| 5307 | work_ha_copy &= ~HA_LATT; |
| 5308 | } |
| 5309 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5310 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5311 | /* |
| 5312 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5313 | * the only slow ring. |
| 5314 | */ |
| 5315 | status = (work_ha_copy & |
| 5316 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5317 | status >>= (4*LPFC_ELS_RING); |
| 5318 | if (status & HA_RXMASK) { |
| 5319 | spin_lock(&phba->hbalock); |
| 5320 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5321 | |
| 5322 | lpfc_debugfs_slow_ring_trc(phba, |
| 5323 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5324 | control, status, |
| 5325 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5326 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5327 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5328 | lpfc_debugfs_slow_ring_trc(phba, |
| 5329 | "ISR Disable ring:" |
| 5330 | "pwork:x%x hawork:x%x wait:x%x", |
| 5331 | phba->work_ha, work_ha_copy, |
| 5332 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5333 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5334 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5335 | control &= |
| 5336 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5337 | writel(control, phba->HCregaddr); |
| 5338 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5339 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5340 | else { |
| 5341 | lpfc_debugfs_slow_ring_trc(phba, |
| 5342 | "ISR slow ring: pwork:" |
| 5343 | "x%x hawork:x%x wait:x%x", |
| 5344 | phba->work_ha, work_ha_copy, |
| 5345 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5346 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5347 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5348 | spin_unlock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5349 | } |
| 5350 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5351 | spin_lock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5352 | if (work_ha_copy & HA_ERATT) |
| 5353 | lpfc_sli_read_hs(phba); |
| 5354 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5355 | pmb = phba->sli.mbox_active; |
| 5356 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5357 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5358 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5359 | |
| 5360 | /* First check out the status word */ |
| 5361 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5362 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5363 | spin_unlock(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5364 | /* |
| 5365 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5366 | * mbxStatus <status> |
| 5367 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5368 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5369 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5370 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5371 | "Interrupt mbxCommand x%x " |
| 5372 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5373 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5374 | pmbox->mbxCommand, |
| 5375 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5376 | /* clear mailbox attention bit */ |
| 5377 | work_ha_copy &= ~HA_MBATT; |
| 5378 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5379 | phba->sli.mbox_active = NULL; |
| 5380 | spin_unlock(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5381 | phba->last_completion_time = jiffies; |
| 5382 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5383 | if (pmb->mbox_cmpl) { |
| 5384 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5385 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5386 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5387 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5388 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5389 | |
| 5390 | lpfc_debugfs_disc_trc(vport, |
| 5391 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5392 | "MBOX dflt rpi: : " |
| 5393 | "status:x%x rpi:x%x", |
| 5394 | (uint32_t)pmbox->mbxStatus, |
| 5395 | pmbox->un.varWords[0], 0); |
| 5396 | |
| 5397 | if (!pmbox->mbxStatus) { |
| 5398 | mp = (struct lpfc_dmabuf *) |
| 5399 | (pmb->context1); |
| 5400 | ndlp = (struct lpfc_nodelist *) |
| 5401 | pmb->context2; |
| 5402 | |
| 5403 | /* Reg_LOGIN of dflt RPI was |
| 5404 | * successful. new lets get |
| 5405 | * rid of the RPI using the |
| 5406 | * same mbox buffer. |
| 5407 | */ |
| 5408 | lpfc_unreg_login(phba, |
| 5409 | vport->vpi, |
| 5410 | pmbox->un.varWords[0], |
| 5411 | pmb); |
| 5412 | pmb->mbox_cmpl = |
| 5413 | lpfc_mbx_cmpl_dflt_rpi; |
| 5414 | pmb->context1 = mp; |
| 5415 | pmb->context2 = ndlp; |
| 5416 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5417 | rc = lpfc_sli_issue_mbox(phba, |
| 5418 | pmb, |
| 5419 | MBX_NOWAIT); |
| 5420 | if (rc != MBX_BUSY) |
| 5421 | lpfc_printf_log(phba, |
| 5422 | KERN_ERR, |
| 5423 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5424 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5425 | "been MBX_BUSY"); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5426 | goto send_current_mbox; |
| 5427 | } |
| 5428 | } |
| 5429 | spin_lock(&phba->pport->work_port_lock); |
| 5430 | phba->pport->work_port_events &= |
| 5431 | ~WORKER_MBOX_TMO; |
| 5432 | spin_unlock(&phba->pport->work_port_lock); |
| 5433 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5434 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5435 | } else |
| 5436 | spin_unlock(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5437 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5438 | if ((work_ha_copy & HA_MBATT) && |
| 5439 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5440 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5441 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5442 | do { |
| 5443 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5444 | MBX_NOWAIT); |
| 5445 | } while (rc == MBX_NOT_FINISHED); |
| 5446 | if (rc != MBX_SUCCESS) |
| 5447 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5448 | LOG_SLI, "0349 rc should be " |
| 5449 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5450 | } |
| 5451 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5452 | spin_lock(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | phba->work_ha |= work_ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5454 | spin_unlock(&phba->hbalock); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5455 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5457 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5459 | } /* lpfc_sp_intr_handler */ |
| 5460 | |
| 5461 | /** |
| 5462 | * lpfc_fp_intr_handler: The fast-path interrupt handler of lpfc driver. |
| 5463 | * @irq: Interrupt number. |
| 5464 | * @dev_id: The device context pointer. |
| 5465 | * |
| 5466 | * This function is directly called from the PCI layer as an interrupt |
| 5467 | * service routine when the device is enabled with MSI-X multi-message |
| 5468 | * interrupt mode and there is a fast-path FCP IOCB ring event in the |
| 5469 | * HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 5470 | * interrupt mode, this function is called as part of the device-level |
| 5471 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 5472 | * is undergoing initialization, the interrupt handler will not process |
| 5473 | * the interrupt. The SCSI FCP fast-path ring event are handled in the |
| 5474 | * intrrupt context. This function is called without any lock held. It |
| 5475 | * gets the hbalock to access and update SLI data structures. |
| 5476 | * |
| 5477 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5478 | * returns IRQ_NONE. |
| 5479 | **/ |
| 5480 | irqreturn_t |
| 5481 | lpfc_fp_intr_handler(int irq, void *dev_id) |
| 5482 | { |
| 5483 | struct lpfc_hba *phba; |
| 5484 | uint32_t ha_copy; |
| 5485 | unsigned long status; |
| 5486 | |
| 5487 | /* Get the driver's phba structure from the dev_id and |
| 5488 | * assume the HBA is not interrupting. |
| 5489 | */ |
| 5490 | phba = (struct lpfc_hba *) dev_id; |
| 5491 | |
| 5492 | if (unlikely(!phba)) |
| 5493 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5494 | |
| 5495 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5496 | * Stuff needs to be attented to when this function is invoked as an |
| 5497 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5499 | if (phba->intr_type == MSIX) { |
| 5500 | /* If pci channel is offline, ignore all the interrupts */ |
| 5501 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5502 | return IRQ_NONE; |
| 5503 | /* Update device-level interrupt statistics */ |
| 5504 | phba->sli.slistat.sli_intr++; |
| 5505 | /* Ignore all interrupts during initialization. */ |
| 5506 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5507 | return IRQ_NONE; |
| 5508 | /* Need to read HA REG for FCP ring and other ring events */ |
| 5509 | ha_copy = readl(phba->HAregaddr); |
| 5510 | /* Clear up only attention source related to fast-path */ |
| 5511 | spin_lock(&phba->hbalock); |
| 5512 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 5513 | phba->HAregaddr); |
| 5514 | readl(phba->HAregaddr); /* flush */ |
| 5515 | spin_unlock(&phba->hbalock); |
| 5516 | } else |
| 5517 | ha_copy = phba->ha_copy; |
| 5518 | |
| 5519 | /* |
| 5520 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 5521 | */ |
| 5522 | ha_copy &= ~(phba->work_ha_mask); |
| 5523 | |
| 5524 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5525 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5526 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | lpfc_sli_handle_fast_ring_event(phba, |
| 5528 | &phba->sli.ring[LPFC_FCP_RING], |
| 5529 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5530 | |
| 5531 | if (phba->cfg_multi_ring_support == 2) { |
| 5532 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5533 | * Process all events on extra ring. Take the optimized path |
| 5534 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5535 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5536 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5537 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5538 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5539 | lpfc_sli_handle_fast_ring_event(phba, |
| 5540 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5541 | status); |
| 5542 | } |
| 5543 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5545 | } /* lpfc_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame^] | 5547 | /** |
| 5548 | * lpfc_intr_handler: The device-level interrupt handler of lpfc driver. |
| 5549 | * @irq: Interrupt number. |
| 5550 | * @dev_id: The device context pointer. |
| 5551 | * |
| 5552 | * This function is the device-level interrupt handler called from the PCI |
| 5553 | * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is |
| 5554 | * an event in the HBA which requires driver attention. This function |
| 5555 | * invokes the slow-path interrupt attention handling function and fast-path |
| 5556 | * interrupt attention handling function in turn to process the relevant |
| 5557 | * HBA attention events. This function is called without any lock held. It |
| 5558 | * gets the hbalock to access and update SLI data structures. |
| 5559 | * |
| 5560 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 5561 | * returns IRQ_NONE. |
| 5562 | **/ |
| 5563 | irqreturn_t |
| 5564 | lpfc_intr_handler(int irq, void *dev_id) |
| 5565 | { |
| 5566 | struct lpfc_hba *phba; |
| 5567 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 5568 | unsigned long status1, status2; |
| 5569 | |
| 5570 | /* |
| 5571 | * Get the driver's phba structure from the dev_id and |
| 5572 | * assume the HBA is not interrupting. |
| 5573 | */ |
| 5574 | phba = (struct lpfc_hba *) dev_id; |
| 5575 | |
| 5576 | if (unlikely(!phba)) |
| 5577 | return IRQ_NONE; |
| 5578 | |
| 5579 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 5580 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5581 | return IRQ_NONE; |
| 5582 | |
| 5583 | /* Update device level interrupt statistics */ |
| 5584 | phba->sli.slistat.sli_intr++; |
| 5585 | |
| 5586 | /* Ignore all interrupts during initialization. */ |
| 5587 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5588 | return IRQ_NONE; |
| 5589 | |
| 5590 | spin_lock(&phba->hbalock); |
| 5591 | phba->ha_copy = readl(phba->HAregaddr); |
| 5592 | if (unlikely(!phba->ha_copy)) { |
| 5593 | spin_unlock(&phba->hbalock); |
| 5594 | return IRQ_NONE; |
| 5595 | } else if (phba->ha_copy & HA_ERATT) { |
| 5596 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5597 | /* ERATT polling has handled ERATT */ |
| 5598 | phba->ha_copy &= ~HA_ERATT; |
| 5599 | else |
| 5600 | /* Indicate interrupt handler handles ERATT */ |
| 5601 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5602 | } |
| 5603 | |
| 5604 | /* Clear attention sources except link and error attentions */ |
| 5605 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5606 | readl(phba->HAregaddr); /* flush */ |
| 5607 | spin_unlock(&phba->hbalock); |
| 5608 | |
| 5609 | /* |
| 5610 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 5611 | */ |
| 5612 | |
| 5613 | /* status of events with mailbox and link attention */ |
| 5614 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 5615 | |
| 5616 | /* status of events with ELS ring */ |
| 5617 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5618 | status2 >>= (4*LPFC_ELS_RING); |
| 5619 | |
| 5620 | if (status1 || (status2 & HA_RXMASK)) |
| 5621 | sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id); |
| 5622 | else |
| 5623 | sp_irq_rc = IRQ_NONE; |
| 5624 | |
| 5625 | /* |
| 5626 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 5627 | */ |
| 5628 | |
| 5629 | /* status of events with FCP ring */ |
| 5630 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5631 | status1 >>= (4*LPFC_FCP_RING); |
| 5632 | |
| 5633 | /* status of events with extra ring */ |
| 5634 | if (phba->cfg_multi_ring_support == 2) { |
| 5635 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5636 | status2 >>= (4*LPFC_EXTRA_RING); |
| 5637 | } else |
| 5638 | status2 = 0; |
| 5639 | |
| 5640 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
| 5641 | fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id); |
| 5642 | else |
| 5643 | fp_irq_rc = IRQ_NONE; |
| 5644 | |
| 5645 | /* Return device-level interrupt handling status */ |
| 5646 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
| 5647 | } /* lpfc_intr_handler */ |