|  | 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 | /** | 
|  | 1702 | * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode. | 
|  | 1703 | * @phba: Pointer to HBA context object. | 
|  | 1704 | * | 
|  | 1705 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, | 
|  | 1706 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING | 
|  | 1707 | * is enabled. | 
|  | 1708 | * | 
|  | 1709 | * The caller does not hold any lock. | 
|  | 1710 | * The function processes each response iocb in the response ring until it | 
|  | 1711 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | 
|  | 1712 | * LE bit set. The function will call the completion handler of the command iocb | 
|  | 1713 | * if the response iocb indicates a completion for a command iocb or it is | 
|  | 1714 | * an abort completion. | 
|  | 1715 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1716 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1717 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | struct lpfc_sli      *psli  = &phba->sli; | 
|  | 1719 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1720 | IOCB_t *irsp = NULL; | 
|  | 1721 | IOCB_t *entry = NULL; | 
|  | 1722 | struct lpfc_iocbq *cmdiocbq = NULL; | 
|  | 1723 | struct lpfc_iocbq rspiocbq; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1724 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1725 | uint32_t status; | 
|  | 1726 | uint32_t portRspPut, portRspMax; | 
|  | 1727 | int type; | 
|  | 1728 | uint32_t rsp_cmpl = 0; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1729 | uint32_t ha_copy; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | unsigned long iflags; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1731 |  | 
|  | 1732 | pring->stats.iocb_event++; | 
|  | 1733 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1734 | /* | 
|  | 1735 | * The next available response entry should never exceed the maximum | 
|  | 1736 | * entries.  If it does, treat it as an adapter hardware error. | 
|  | 1737 | */ | 
|  | 1738 | portRspMax = pring->numRiocb; | 
|  | 1739 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 1740 | if (unlikely(portRspPut >= portRspMax)) { | 
|  | 1741 | lpfc_sli_rsp_pointers_error(phba, pring); | 
|  | 1742 | return; | 
|  | 1743 | } | 
|  | 1744 |  | 
|  | 1745 | rmb(); | 
|  | 1746 | while (pring->rspidx != portRspPut) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1747 | entry = lpfc_resp_iocb(phba, pring); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1748 | if (++pring->rspidx >= portRspMax) | 
|  | 1749 | pring->rspidx = 0; | 
|  | 1750 |  | 
|  | 1751 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, | 
|  | 1752 | (uint32_t *) &rspiocbq.iocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1753 | phba->iocb_rsp_size); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1754 | irsp = &rspiocbq.iocb; | 
|  | 1755 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); | 
|  | 1756 | pring->stats.iocb_rsp++; | 
|  | 1757 | rsp_cmpl++; | 
|  | 1758 |  | 
|  | 1759 | if (unlikely(irsp->ulpStatus)) { | 
|  | 1760 | /* Rsp ring <ringno> error: IOCB */ | 
|  | 1761 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1762 | "0326 Rsp Ring %d error: IOCB Data: " | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1763 | "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] | 1764 | pring->ringno, | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1765 | irsp->un.ulpWord[0], | 
|  | 1766 | irsp->un.ulpWord[1], | 
|  | 1767 | irsp->un.ulpWord[2], | 
|  | 1768 | irsp->un.ulpWord[3], | 
|  | 1769 | irsp->un.ulpWord[4], | 
|  | 1770 | irsp->un.ulpWord[5], | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1771 | *(uint32_t *)&irsp->un1, | 
|  | 1772 | *((uint32_t *)&irsp->un1 + 1)); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1773 | } | 
|  | 1774 |  | 
|  | 1775 | switch (type) { | 
|  | 1776 | case LPFC_ABORT_IOCB: | 
|  | 1777 | case LPFC_SOL_IOCB: | 
|  | 1778 | /* | 
|  | 1779 | * Idle exchange closed via ABTS from port.  No iocb | 
|  | 1780 | * resources need to be recovered. | 
|  | 1781 | */ | 
|  | 1782 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | 
| James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1783 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1784 | "0314 IOCB cmd 0x%x " | 
|  | 1785 | "processed. Skipping " | 
|  | 1786 | "completion", | 
| James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1787 | irsp->ulpCommand); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1788 | break; | 
|  | 1789 | } | 
|  | 1790 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1791 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1792 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, | 
|  | 1793 | &rspiocbq); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1794 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1795 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { | 
|  | 1796 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | 
|  | 1797 | &rspiocbq); | 
|  | 1798 | } | 
|  | 1799 | break; | 
|  | 1800 | default: | 
|  | 1801 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | 
|  | 1802 | char adaptermsg[LPFC_MAX_ADPTMSG]; | 
|  | 1803 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | 
|  | 1804 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | 
|  | 1805 | MAX_MSG_DATA); | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1806 | dev_warn(&((phba->pcidev)->dev), | 
|  | 1807 | "lpfc%d: %s\n", | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1808 | phba->brd_no, adaptermsg); | 
|  | 1809 | } else { | 
|  | 1810 | /* Unknown IOCB command */ | 
|  | 1811 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1812 | "0321 Unknown IOCB command " | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1813 | "Data: x%x, x%x x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1814 | type, irsp->ulpCommand, | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1815 | irsp->ulpStatus, | 
|  | 1816 | irsp->ulpIoTag, | 
|  | 1817 | irsp->ulpContext); | 
|  | 1818 | } | 
|  | 1819 | break; | 
|  | 1820 | } | 
|  | 1821 |  | 
|  | 1822 | /* | 
|  | 1823 | * The response IOCB has been processed.  Update the ring | 
|  | 1824 | * pointer in SLIM.  If the port response put pointer has not | 
|  | 1825 | * been updated, sync the pgp->rspPutInx and fetch the new port | 
|  | 1826 | * response put pointer. | 
|  | 1827 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1828 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1829 |  | 
|  | 1830 | if (pring->rspidx == portRspPut) | 
|  | 1831 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 1832 | } | 
|  | 1833 |  | 
|  | 1834 | ha_copy = readl(phba->HAregaddr); | 
|  | 1835 | ha_copy >>= (LPFC_FCP_RING * 4); | 
|  | 1836 |  | 
|  | 1837 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1838 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1839 | pring->stats.iocb_rsp_full++; | 
|  | 1840 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); | 
|  | 1841 | writel(status, phba->CAregaddr); | 
|  | 1842 | readl(phba->CAregaddr); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1844 | } | 
|  | 1845 | if ((ha_copy & HA_R0CE_RSP) && | 
|  | 1846 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1847 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1848 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | 
|  | 1849 | pring->stats.iocb_cmd_empty++; | 
|  | 1850 |  | 
|  | 1851 | /* Force update of the local copy of cmdGetInx */ | 
|  | 1852 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | 
|  | 1853 | lpfc_sli_resume_iocb(phba, pring); | 
|  | 1854 |  | 
|  | 1855 | if ((pring->lpfc_sli_cmd_available)) | 
|  | 1856 | (pring->lpfc_sli_cmd_available) (phba, pring); | 
|  | 1857 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1859 | } | 
|  | 1860 |  | 
|  | 1861 | return; | 
|  | 1862 | } | 
|  | 1863 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1864 | /** | 
|  | 1865 | * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring. | 
|  | 1866 | * @phba: Pointer to HBA context object. | 
|  | 1867 | * @pring: Pointer to driver SLI ring object. | 
|  | 1868 | * @mask: Host attention register mask for this ring. | 
|  | 1869 | * | 
|  | 1870 | * This function is called from the interrupt context when there is a ring | 
|  | 1871 | * event for the fcp ring. The caller does not hold any lock. | 
|  | 1872 | * The function processes each response iocb in the response ring until it | 
|  | 1873 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | 
|  | 1874 | * LE bit set. The function will call the completion handler of the command iocb | 
|  | 1875 | * if the response iocb indicates a completion for a command iocb or it is | 
|  | 1876 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | 
|  | 1877 | * function if this is an unsolicited iocb. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | * This routine presumes LPFC_FCP_RING handling and doesn't bother | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1879 | * to check it explicitly. This function always returns 1. | 
|  | 1880 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1882 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, | 
|  | 1883 | struct lpfc_sli_ring *pring, uint32_t mask) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | { | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1885 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | IOCB_t *irsp = NULL; | 
| James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1887 | IOCB_t *entry = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | struct lpfc_iocbq *cmdiocbq = NULL; | 
|  | 1889 | struct lpfc_iocbq rspiocbq; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | uint32_t status; | 
|  | 1891 | uint32_t portRspPut, portRspMax; | 
|  | 1892 | int rc = 1; | 
|  | 1893 | lpfc_iocb_type type; | 
|  | 1894 | unsigned long iflag; | 
|  | 1895 | uint32_t rsp_cmpl = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1897 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | pring->stats.iocb_event++; | 
|  | 1899 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | /* | 
|  | 1901 | * The next available response entry should never exceed the maximum | 
|  | 1902 | * entries.  If it does, treat it as an adapter hardware error. | 
|  | 1903 | */ | 
|  | 1904 | portRspMax = pring->numRiocb; | 
|  | 1905 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 1906 | if (unlikely(portRspPut >= portRspMax)) { | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1907 | lpfc_sli_rsp_pointers_error(phba, pring); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1908 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | return 1; | 
|  | 1910 | } | 
|  | 1911 |  | 
|  | 1912 | rmb(); | 
|  | 1913 | while (pring->rspidx != portRspPut) { | 
| James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1914 | /* | 
|  | 1915 | * Fetch an entry off the ring and copy it into a local data | 
|  | 1916 | * structure.  The copy involves a byte-swap since the | 
|  | 1917 | * network byte order and pci byte orders are different. | 
|  | 1918 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1919 | entry = lpfc_resp_iocb(phba, pring); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1920 | phba->last_completion_time = jiffies; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1921 |  | 
|  | 1922 | if (++pring->rspidx >= portRspMax) | 
|  | 1923 | pring->rspidx = 0; | 
|  | 1924 |  | 
| James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1925 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, | 
|  | 1926 | (uint32_t *) &rspiocbq.iocb, | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1927 | phba->iocb_rsp_size); | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1928 | INIT_LIST_HEAD(&(rspiocbq.list)); | 
| James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1929 | irsp = &rspiocbq.iocb; | 
|  | 1930 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); | 
|  | 1932 | pring->stats.iocb_rsp++; | 
|  | 1933 | rsp_cmpl++; | 
|  | 1934 |  | 
|  | 1935 | if (unlikely(irsp->ulpStatus)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1936 | /* | 
|  | 1937 | * If resource errors reported from HBA, reduce | 
|  | 1938 | * queuedepths of the SCSI device. | 
|  | 1939 | */ | 
|  | 1940 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | 
|  | 1941 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | 
|  | 1942 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 1943 | lpfc_adjust_queue_depth(phba); | 
|  | 1944 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 1945 | } | 
|  | 1946 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | /* Rsp ring <ringno> error: IOCB */ | 
|  | 1948 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1949 | "0336 Rsp Ring %d error: IOCB Data: " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | "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] | 1951 | pring->ringno, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1952 | irsp->un.ulpWord[0], | 
|  | 1953 | irsp->un.ulpWord[1], | 
|  | 1954 | irsp->un.ulpWord[2], | 
|  | 1955 | irsp->un.ulpWord[3], | 
|  | 1956 | irsp->un.ulpWord[4], | 
|  | 1957 | irsp->un.ulpWord[5], | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1958 | *(uint32_t *)&irsp->un1, | 
|  | 1959 | *((uint32_t *)&irsp->un1 + 1)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | switch (type) { | 
|  | 1963 | case LPFC_ABORT_IOCB: | 
|  | 1964 | case LPFC_SOL_IOCB: | 
|  | 1965 | /* | 
|  | 1966 | * Idle exchange closed via ABTS from port.  No iocb | 
|  | 1967 | * resources need to be recovered. | 
|  | 1968 | */ | 
|  | 1969 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | 
| James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1970 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1971 | "0333 IOCB cmd 0x%x" | 
| James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1972 | " processed. Skipping" | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1973 | " completion\n", | 
| James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1974 | irsp->ulpCommand); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | break; | 
|  | 1976 | } | 
|  | 1977 |  | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1978 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, | 
|  | 1979 | &rspiocbq); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { | 
| Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1981 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { | 
|  | 1982 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | 
|  | 1983 | &rspiocbq); | 
|  | 1984 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1985 | spin_unlock_irqrestore(&phba->hbalock, | 
|  | 1986 | iflag); | 
| Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1987 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | 
|  | 1988 | &rspiocbq); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1989 | spin_lock_irqsave(&phba->hbalock, | 
| Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1990 | iflag); | 
|  | 1991 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | } | 
|  | 1993 | break; | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1994 | case LPFC_UNSOL_IOCB: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1995 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1996 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | spin_lock_irqsave(&phba->hbalock, iflag); | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1998 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | default: | 
|  | 2000 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | 
|  | 2001 | char adaptermsg[LPFC_MAX_ADPTMSG]; | 
|  | 2002 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | 
|  | 2003 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | 
|  | 2004 | MAX_MSG_DATA); | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2005 | dev_warn(&((phba->pcidev)->dev), | 
|  | 2006 | "lpfc%d: %s\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | phba->brd_no, adaptermsg); | 
|  | 2008 | } else { | 
|  | 2009 | /* Unknown IOCB command */ | 
|  | 2010 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2011 | "0334 Unknown IOCB command " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2012 | "Data: x%x, x%x x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2013 | type, irsp->ulpCommand, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2014 | irsp->ulpStatus, | 
|  | 2015 | irsp->ulpIoTag, | 
|  | 2016 | irsp->ulpContext); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | } | 
|  | 2018 | break; | 
|  | 2019 | } | 
|  | 2020 |  | 
|  | 2021 | /* | 
|  | 2022 | * The response IOCB has been processed.  Update the ring | 
|  | 2023 | * pointer in SLIM.  If the port response put pointer has not | 
|  | 2024 | * been updated, sync the pgp->rspPutInx and fetch the new port | 
|  | 2025 | * response put pointer. | 
|  | 2026 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2027 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 |  | 
|  | 2029 | if (pring->rspidx == portRspPut) | 
|  | 2030 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 2031 | } | 
|  | 2032 |  | 
|  | 2033 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | 
|  | 2034 | pring->stats.iocb_rsp_full++; | 
|  | 2035 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | 
|  | 2036 | writel(status, phba->CAregaddr); | 
|  | 2037 | readl(phba->CAregaddr); | 
|  | 2038 | } | 
|  | 2039 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | 
|  | 2040 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | 
|  | 2041 | pring->stats.iocb_cmd_empty++; | 
|  | 2042 |  | 
|  | 2043 | /* Force update of the local copy of cmdGetInx */ | 
|  | 2044 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | 
|  | 2045 | lpfc_sli_resume_iocb(phba, pring); | 
|  | 2046 |  | 
|  | 2047 | if ((pring->lpfc_sli_cmd_available)) | 
|  | 2048 | (pring->lpfc_sli_cmd_available) (phba, pring); | 
|  | 2049 |  | 
|  | 2050 | } | 
|  | 2051 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | return rc; | 
|  | 2054 | } | 
|  | 2055 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2056 | /** | 
|  | 2057 | * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings. | 
|  | 2058 | * @phba: Pointer to HBA context object. | 
|  | 2059 | * @pring: Pointer to driver SLI ring object. | 
|  | 2060 | * @mask: Host attention register mask for this ring. | 
|  | 2061 | * | 
|  | 2062 | * This function is called from the worker thread when there is a ring | 
|  | 2063 | * event for non-fcp rings. The caller does not hold any lock . | 
|  | 2064 | * The function processes each response iocb in the response ring until it | 
|  | 2065 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | 
|  | 2066 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the | 
|  | 2067 | * response iocb indicates a completion of a command iocb. The function | 
|  | 2068 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited | 
|  | 2069 | * iocb. The function frees the resources or calls the completion handler if | 
|  | 2070 | * this iocb is an abort completion. The function returns 0 when the allocated | 
|  | 2071 | * iocbs are not freed, otherwise returns 1. | 
|  | 2072 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, | 
|  | 2075 | struct lpfc_sli_ring *pring, uint32_t mask) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | { | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2077 | struct lpfc_pgp *pgp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | IOCB_t *entry; | 
|  | 2079 | IOCB_t *irsp = NULL; | 
|  | 2080 | struct lpfc_iocbq *rspiocbp = NULL; | 
|  | 2081 | struct lpfc_iocbq *next_iocb; | 
|  | 2082 | struct lpfc_iocbq *cmdiocbp; | 
|  | 2083 | struct lpfc_iocbq *saveq; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | uint8_t iocb_cmd_type; | 
|  | 2085 | lpfc_iocb_type type; | 
|  | 2086 | uint32_t status, free_saveq; | 
|  | 2087 | uint32_t portRspPut, portRspMax; | 
|  | 2088 | int rc = 1; | 
|  | 2089 | unsigned long iflag; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 |  | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2091 | pgp = &phba->port_gp[pring->ringno]; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2092 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | pring->stats.iocb_event++; | 
|  | 2094 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | /* | 
|  | 2096 | * The next available response entry should never exceed the maximum | 
|  | 2097 | * entries.  If it does, treat it as an adapter hardware error. | 
|  | 2098 | */ | 
|  | 2099 | portRspMax = pring->numRiocb; | 
|  | 2100 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 2101 | if (portRspPut >= portRspMax) { | 
|  | 2102 | /* | 
|  | 2103 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then | 
|  | 2104 | * rsp ring <portRspMax> | 
|  | 2105 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2106 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2107 | "0303 Ring %d handler: portRspPut %d " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | "is bigger then rsp ring %d\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2109 | pring->ringno, portRspPut, portRspMax); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2111 | phba->link_state = LPFC_HBA_ERROR; | 
|  | 2112 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 |  | 
|  | 2114 | phba->work_hs = HS_FFER3; | 
|  | 2115 | lpfc_handle_eratt(phba); | 
|  | 2116 |  | 
|  | 2117 | return 1; | 
|  | 2118 | } | 
|  | 2119 |  | 
|  | 2120 | rmb(); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | while (pring->rspidx != portRspPut) { | 
|  | 2122 | /* | 
|  | 2123 | * Build a completion list and call the appropriate handler. | 
|  | 2124 | * The process is to get the next available response iocb, get | 
|  | 2125 | * a free iocb from the list, copy the response data into the | 
|  | 2126 | * free iocb, insert to the continuation list, and update the | 
|  | 2127 | * next response index to slim.  This process makes response | 
|  | 2128 | * iocb's in the ring available to DMA as fast as possible but | 
|  | 2129 | * pays a penalty for a copy operation.  Since the iocb is | 
|  | 2130 | * only 32 bytes, this penalty is considered small relative to | 
|  | 2131 | * the PCI reads for register values and a slim write.  When | 
|  | 2132 | * the ulpLe field is set, the entire Command has been | 
|  | 2133 | * received. | 
|  | 2134 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2135 | entry = lpfc_resp_iocb(phba, pring); | 
|  | 2136 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2137 | phba->last_completion_time = jiffies; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | rspiocbp = __lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | if (rspiocbp == NULL) { | 
|  | 2140 | printk(KERN_ERR "%s: out of buffers! Failing " | 
| Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2141 | "completion.\n", __func__); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | break; | 
|  | 2143 | } | 
|  | 2144 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2145 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, | 
|  | 2146 | phba->iocb_rsp_size); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | irsp = &rspiocbp->iocb; | 
|  | 2148 |  | 
|  | 2149 | if (++pring->rspidx >= portRspMax) | 
|  | 2150 | pring->rspidx = 0; | 
|  | 2151 |  | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2152 | if (pring->ringno == LPFC_ELS_RING) { | 
|  | 2153 | lpfc_debugfs_slow_ring_trc(phba, | 
|  | 2154 | "IOCB rsp ring:   wd4:x%08x wd6:x%08x wd7:x%08x", | 
|  | 2155 | *(((uint32_t *) irsp) + 4), | 
|  | 2156 | *(((uint32_t *) irsp) + 6), | 
|  | 2157 | *(((uint32_t *) irsp) + 7)); | 
|  | 2158 | } | 
|  | 2159 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2160 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 |  | 
| James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2162 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 |  | 
|  | 2164 | pring->iocb_continueq_cnt++; | 
|  | 2165 | if (irsp->ulpLe) { | 
|  | 2166 | /* | 
|  | 2167 | * By default, the driver expects to free all resources | 
|  | 2168 | * associated with this iocb completion. | 
|  | 2169 | */ | 
|  | 2170 | free_saveq = 1; | 
|  | 2171 | saveq = list_get_first(&pring->iocb_continueq, | 
|  | 2172 | struct lpfc_iocbq, list); | 
|  | 2173 | irsp = &(saveq->iocb); | 
|  | 2174 | list_del_init(&pring->iocb_continueq); | 
|  | 2175 | pring->iocb_continueq_cnt = 0; | 
|  | 2176 |  | 
|  | 2177 | pring->stats.iocb_rsp++; | 
|  | 2178 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2179 | /* | 
|  | 2180 | * If resource errors reported from HBA, reduce | 
|  | 2181 | * queuedepths of the SCSI device. | 
|  | 2182 | */ | 
|  | 2183 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | 
|  | 2184 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | 
|  | 2185 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 2186 | lpfc_adjust_queue_depth(phba); | 
|  | 2187 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 2188 | } | 
|  | 2189 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | if (irsp->ulpStatus) { | 
|  | 2191 | /* Rsp ring <ringno> error: IOCB */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2192 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2193 | "0328 Rsp Ring %d error: " | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2194 | "IOCB Data: " | 
|  | 2195 | "x%x x%x x%x x%x " | 
|  | 2196 | "x%x x%x x%x x%x " | 
|  | 2197 | "x%x x%x x%x x%x " | 
|  | 2198 | "x%x x%x x%x x%x\n", | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2199 | pring->ringno, | 
|  | 2200 | irsp->un.ulpWord[0], | 
|  | 2201 | irsp->un.ulpWord[1], | 
|  | 2202 | irsp->un.ulpWord[2], | 
|  | 2203 | irsp->un.ulpWord[3], | 
|  | 2204 | irsp->un.ulpWord[4], | 
|  | 2205 | irsp->un.ulpWord[5], | 
|  | 2206 | *(((uint32_t *) irsp) + 6), | 
|  | 2207 | *(((uint32_t *) irsp) + 7), | 
|  | 2208 | *(((uint32_t *) irsp) + 8), | 
|  | 2209 | *(((uint32_t *) irsp) + 9), | 
|  | 2210 | *(((uint32_t *) irsp) + 10), | 
|  | 2211 | *(((uint32_t *) irsp) + 11), | 
|  | 2212 | *(((uint32_t *) irsp) + 12), | 
|  | 2213 | *(((uint32_t *) irsp) + 13), | 
|  | 2214 | *(((uint32_t *) irsp) + 14), | 
|  | 2215 | *(((uint32_t *) irsp) + 15)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | } | 
|  | 2217 |  | 
|  | 2218 | /* | 
|  | 2219 | * Fetch the IOCB command type and call the correct | 
|  | 2220 | * completion routine.  Solicited and Unsolicited | 
|  | 2221 | * IOCBs on the ELS ring get freed back to the | 
|  | 2222 | * lpfc_iocb_list by the discovery kernel thread. | 
|  | 2223 | */ | 
|  | 2224 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | 
|  | 2225 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | 
|  | 2226 | if (type == LPFC_SOL_IOCB) { | 
| James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2227 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | rc = lpfc_sli_process_sol_iocb(phba, pring, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2229 | saveq); | 
|  | 2230 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } else if (type == LPFC_UNSOL_IOCB) { | 
| James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2232 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | rc = lpfc_sli_process_unsol_iocb(phba, pring, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | saveq); | 
|  | 2235 | spin_lock_irqsave(&phba->hbalock, iflag); | 
| James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2236 | if (!rc) | 
|  | 2237 | free_saveq = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | } else if (type == LPFC_ABORT_IOCB) { | 
|  | 2239 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && | 
|  | 2240 | ((cmdiocbp = | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2241 | lpfc_sli_iocbq_lookup(phba, pring, | 
|  | 2242 | saveq)))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2243 | /* Call the specified completion | 
|  | 2244 | routine */ | 
|  | 2245 | if (cmdiocbp->iocb_cmpl) { | 
|  | 2246 | spin_unlock_irqrestore( | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2247 | &phba->hbalock, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | iflag); | 
|  | 2249 | (cmdiocbp->iocb_cmpl) (phba, | 
|  | 2250 | cmdiocbp, saveq); | 
|  | 2251 | spin_lock_irqsave( | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | &phba->hbalock, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | iflag); | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2254 | } else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2255 | __lpfc_sli_release_iocbq(phba, | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2256 | cmdiocbp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | } | 
|  | 2258 | } else if (type == LPFC_UNKNOWN_IOCB) { | 
|  | 2259 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | 
|  | 2260 |  | 
|  | 2261 | char adaptermsg[LPFC_MAX_ADPTMSG]; | 
|  | 2262 |  | 
|  | 2263 | memset(adaptermsg, 0, | 
|  | 2264 | LPFC_MAX_ADPTMSG); | 
|  | 2265 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | 
|  | 2266 | MAX_MSG_DATA); | 
|  | 2267 | dev_warn(&((phba->pcidev)->dev), | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2268 | "lpfc%d: %s\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2269 | phba->brd_no, adaptermsg); | 
|  | 2270 | } else { | 
|  | 2271 | /* Unknown IOCB command */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2272 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2273 | "0335 Unknown IOCB " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2274 | "command Data: x%x " | 
|  | 2275 | "x%x x%x x%x\n", | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2276 | irsp->ulpCommand, | 
|  | 2277 | irsp->ulpStatus, | 
|  | 2278 | irsp->ulpIoTag, | 
|  | 2279 | irsp->ulpContext); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | } | 
|  | 2281 | } | 
|  | 2282 |  | 
|  | 2283 | if (free_saveq) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | list_for_each_entry_safe(rspiocbp, next_iocb, | 
|  | 2285 | &saveq->list, list) { | 
|  | 2286 | list_del(&rspiocbp->list); | 
|  | 2287 | __lpfc_sli_release_iocbq(phba, | 
|  | 2288 | rspiocbp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2290 | __lpfc_sli_release_iocbq(phba, saveq); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | rspiocbp = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | } | 
|  | 2294 |  | 
|  | 2295 | /* | 
|  | 2296 | * If the port response put pointer has not been updated, sync | 
|  | 2297 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | 
|  | 2298 | * response put pointer. | 
|  | 2299 | */ | 
|  | 2300 | if (pring->rspidx == portRspPut) { | 
|  | 2301 | portRspPut = le32_to_cpu(pgp->rspPutInx); | 
|  | 2302 | } | 
|  | 2303 | } /* while (pring->rspidx != portRspPut) */ | 
|  | 2304 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | /* At least one response entry has been freed */ | 
|  | 2307 | pring->stats.iocb_rsp_full++; | 
|  | 2308 | /* SET RxRE_RSP in Chip Att register */ | 
|  | 2309 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | 
|  | 2310 | writel(status, phba->CAregaddr); | 
|  | 2311 | readl(phba->CAregaddr); /* flush */ | 
|  | 2312 | } | 
|  | 2313 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | 
|  | 2314 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | 
|  | 2315 | pring->stats.iocb_cmd_empty++; | 
|  | 2316 |  | 
|  | 2317 | /* Force update of the local copy of cmdGetInx */ | 
|  | 2318 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | 
|  | 2319 | lpfc_sli_resume_iocb(phba, pring); | 
|  | 2320 |  | 
|  | 2321 | if ((pring->lpfc_sli_cmd_available)) | 
|  | 2322 | (pring->lpfc_sli_cmd_available) (phba, pring); | 
|  | 2323 |  | 
|  | 2324 | } | 
|  | 2325 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2326 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | return rc; | 
|  | 2328 | } | 
|  | 2329 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2330 | /** | 
|  | 2331 | * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring. | 
|  | 2332 | * @phba: Pointer to HBA context object. | 
|  | 2333 | * @pring: Pointer to driver SLI ring object. | 
|  | 2334 | * | 
|  | 2335 | * This function aborts all iocbs in the given ring and frees all the iocb | 
|  | 2336 | * objects in txq. This function issues an abort iocb for all the iocb commands | 
|  | 2337 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | 
|  | 2338 | * the return of this function. The caller is not required to hold any locks. | 
|  | 2339 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2340 | void | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | 
|  | 2342 | { | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2343 | LIST_HEAD(completions); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | struct lpfc_iocbq *iocb, *next_iocb; | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2345 | IOCB_t *cmd = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | if (pring->ringno == LPFC_ELS_RING) { | 
|  | 2348 | lpfc_fabric_abort_hba(phba); | 
|  | 2349 | } | 
|  | 2350 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | /* Error everything on txq and txcmplq | 
|  | 2352 | * First do the txq. | 
|  | 2353 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2354 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2355 | list_splice_init(&pring->txq, &completions); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | pring->txq_cnt = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 |  | 
|  | 2358 | /* Next issue ABTS for everything on the txcmplq */ | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2359 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | 
|  | 2360 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | 
|  | 2361 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2363 |  | 
|  | 2364 | while (!list_empty(&completions)) { | 
|  | 2365 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | cmd = &iocb->iocb; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2367 | list_del_init(&iocb->list); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | if (!iocb->iocb_cmpl) | 
|  | 2370 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 2371 | else { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 2373 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2375 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | } | 
|  | 2378 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2379 | /** | 
| James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame^] | 2380 | * lpfc_sli_flush_fcp_rings: flush all iocbs in the fcp ring. | 
|  | 2381 | * @phba: Pointer to HBA context object. | 
|  | 2382 | * | 
|  | 2383 | * This function flushes all iocbs in the fcp ring and frees all the iocb | 
|  | 2384 | * objects in txq and txcmplq. This function will not issue abort iocbs | 
|  | 2385 | * for all the iocb commands in txcmplq, they will just be returned with | 
|  | 2386 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | 
|  | 2387 | * slot has been permanently disabled. | 
|  | 2388 | **/ | 
|  | 2389 | void | 
|  | 2390 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | 
|  | 2391 | { | 
|  | 2392 | LIST_HEAD(txq); | 
|  | 2393 | LIST_HEAD(txcmplq); | 
|  | 2394 | struct lpfc_iocbq *iocb; | 
|  | 2395 | IOCB_t *cmd = NULL; | 
|  | 2396 | struct lpfc_sli *psli = &phba->sli; | 
|  | 2397 | struct lpfc_sli_ring  *pring; | 
|  | 2398 |  | 
|  | 2399 | /* Currently, only one fcp ring */ | 
|  | 2400 | pring = &psli->ring[psli->fcp_ring]; | 
|  | 2401 |  | 
|  | 2402 | spin_lock_irq(&phba->hbalock); | 
|  | 2403 | /* Retrieve everything on txq */ | 
|  | 2404 | list_splice_init(&pring->txq, &txq); | 
|  | 2405 | pring->txq_cnt = 0; | 
|  | 2406 |  | 
|  | 2407 | /* Retrieve everything on the txcmplq */ | 
|  | 2408 | list_splice_init(&pring->txcmplq, &txcmplq); | 
|  | 2409 | pring->txcmplq_cnt = 0; | 
|  | 2410 | spin_unlock_irq(&phba->hbalock); | 
|  | 2411 |  | 
|  | 2412 | /* Flush the txq */ | 
|  | 2413 | while (!list_empty(&txq)) { | 
|  | 2414 | iocb = list_get_first(&txq, struct lpfc_iocbq, list); | 
|  | 2415 | cmd = &iocb->iocb; | 
|  | 2416 | list_del_init(&iocb->list); | 
|  | 2417 |  | 
|  | 2418 | if (!iocb->iocb_cmpl) | 
|  | 2419 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 2420 | else { | 
|  | 2421 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 2422 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; | 
|  | 2423 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
|  | 2424 | } | 
|  | 2425 | } | 
|  | 2426 |  | 
|  | 2427 | /* Flush the txcmpq */ | 
|  | 2428 | while (!list_empty(&txcmplq)) { | 
|  | 2429 | iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list); | 
|  | 2430 | cmd = &iocb->iocb; | 
|  | 2431 | list_del_init(&iocb->list); | 
|  | 2432 |  | 
|  | 2433 | if (!iocb->iocb_cmpl) | 
|  | 2434 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 2435 | else { | 
|  | 2436 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 2437 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; | 
|  | 2438 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
|  | 2439 | } | 
|  | 2440 | } | 
|  | 2441 | } | 
|  | 2442 |  | 
|  | 2443 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2444 | * lpfc_sli_brdready: Check for host status bits. | 
|  | 2445 | * @phba: Pointer to HBA context object. | 
|  | 2446 | * @mask: Bit mask to be checked. | 
|  | 2447 | * | 
|  | 2448 | * This function reads the host status register and compares | 
|  | 2449 | * with the provided bit mask to check if HBA completed | 
|  | 2450 | * the restart. This function will wait in a loop for the | 
|  | 2451 | * HBA to complete restart. If the HBA does not restart within | 
|  | 2452 | * 15 iterations, the function will reset the HBA again. The | 
|  | 2453 | * function returns 1 when HBA fail to restart otherwise returns | 
|  | 2454 | * zero. | 
|  | 2455 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2456 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2457 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2458 | { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2459 | uint32_t status; | 
|  | 2460 | int i = 0; | 
|  | 2461 | int retval = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2463 | /* Read the HBA Host Status Register */ | 
|  | 2464 | status = readl(phba->HSregaddr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2466 | /* | 
|  | 2467 | * Check status register every 100ms for 5 retries, then every | 
|  | 2468 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | 
|  | 2469 | * every 2.5 sec for 4. | 
|  | 2470 | * Break our of the loop if errors occurred during init. | 
|  | 2471 | */ | 
|  | 2472 | while (((status & mask) != mask) && | 
|  | 2473 | !(status & HS_FFERM) && | 
|  | 2474 | i++ < 20) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2476 | if (i <= 5) | 
|  | 2477 | msleep(10); | 
|  | 2478 | else if (i <= 10) | 
|  | 2479 | msleep(500); | 
|  | 2480 | else | 
|  | 2481 | msleep(2500); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2483 | if (i == 15) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | /* Do post */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2485 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2486 | lpfc_sli_brdrestart(phba); | 
|  | 2487 | } | 
|  | 2488 | /* Read the HBA Host Status Register */ | 
|  | 2489 | status = readl(phba->HSregaddr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2492 | /* Check to see if any errors occurred during init */ | 
|  | 2493 | if ((status & HS_FFERM) || (i >= 20)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | phba->link_state = LPFC_HBA_ERROR; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2495 | retval = 1; | 
|  | 2496 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2498 | return retval; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | } | 
|  | 2500 |  | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2501 | #define BARRIER_TEST_PATTERN (0xdeadbeef) | 
|  | 2502 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2503 | /** | 
|  | 2504 | * lpfc_reset_barrier: Make HBA ready for HBA reset. | 
|  | 2505 | * @phba: Pointer to HBA context object. | 
|  | 2506 | * | 
|  | 2507 | * This function is called before resetting an HBA. This | 
|  | 2508 | * function requests HBA to quiesce DMAs before a reset. | 
|  | 2509 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | void lpfc_reset_barrier(struct lpfc_hba *phba) | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2511 | { | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2512 | uint32_t __iomem *resp_buf; | 
|  | 2513 | uint32_t __iomem *mbox_buf; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2514 | volatile uint32_t mbox; | 
|  | 2515 | uint32_t hc_copy; | 
|  | 2516 | int  i; | 
|  | 2517 | uint8_t hdrtype; | 
|  | 2518 |  | 
|  | 2519 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | 
|  | 2520 | if (hdrtype != 0x80 || | 
|  | 2521 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | 
|  | 2522 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | 
|  | 2523 | return; | 
|  | 2524 |  | 
|  | 2525 | /* | 
|  | 2526 | * Tell the other part of the chip to suspend temporarily all | 
|  | 2527 | * its DMA activity. | 
|  | 2528 | */ | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2529 | resp_buf = phba->MBslimaddr; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2530 |  | 
|  | 2531 | /* Disable the error attention */ | 
|  | 2532 | hc_copy = readl(phba->HCregaddr); | 
|  | 2533 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); | 
|  | 2534 | readl(phba->HCregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2535 | phba->link_flag |= LS_IGNORE_ERATT; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2536 |  | 
|  | 2537 | if (readl(phba->HAregaddr) & HA_ERATT) { | 
|  | 2538 | /* Clear Chip error bit */ | 
|  | 2539 | writel(HA_ERATT, phba->HAregaddr); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2540 | phba->pport->stopped = 1; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2541 | } | 
|  | 2542 |  | 
|  | 2543 | mbox = 0; | 
|  | 2544 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | 
|  | 2545 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | 
|  | 2546 |  | 
|  | 2547 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2548 | mbox_buf = phba->MBslimaddr; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2549 | writel(mbox, mbox_buf); | 
|  | 2550 |  | 
|  | 2551 | for (i = 0; | 
|  | 2552 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) | 
|  | 2553 | mdelay(1); | 
|  | 2554 |  | 
|  | 2555 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | 
|  | 2556 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | phba->pport->stopped) | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2558 | goto restore_hc; | 
|  | 2559 | else | 
|  | 2560 | goto clear_errat; | 
|  | 2561 | } | 
|  | 2562 |  | 
|  | 2563 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | 
|  | 2564 | for (i = 0; readl(resp_buf) != mbox &&  i < 500; i++) | 
|  | 2565 | mdelay(1); | 
|  | 2566 |  | 
|  | 2567 | clear_errat: | 
|  | 2568 |  | 
|  | 2569 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) | 
|  | 2570 | mdelay(1); | 
|  | 2571 |  | 
|  | 2572 | if (readl(phba->HAregaddr) & HA_ERATT) { | 
|  | 2573 | writel(HA_ERATT, phba->HAregaddr); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | phba->pport->stopped = 1; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2575 | } | 
|  | 2576 |  | 
|  | 2577 | restore_hc: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2578 | phba->link_flag &= ~LS_IGNORE_ERATT; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2579 | writel(hc_copy, phba->HCregaddr); | 
|  | 2580 | readl(phba->HCregaddr); /* flush */ | 
|  | 2581 | } | 
|  | 2582 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2583 | /** | 
|  | 2584 | * lpfc_sli_brdkill: Issue a kill_board mailbox command. | 
|  | 2585 | * @phba: Pointer to HBA context object. | 
|  | 2586 | * | 
|  | 2587 | * This function issues a kill_board mailbox command and waits for | 
|  | 2588 | * the error attention interrupt. This function is called for stopping | 
|  | 2589 | * the firmware processing. The caller is not required to hold any | 
|  | 2590 | * locks. This function calls lpfc_hba_down_post function to free | 
|  | 2591 | * any pending commands after the kill. The function will return 1 when it | 
|  | 2592 | * fails to kill the board else will return 0. | 
|  | 2593 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2594 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | lpfc_sli_brdkill(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2597 | struct lpfc_sli *psli; | 
|  | 2598 | LPFC_MBOXQ_t *pmb; | 
|  | 2599 | uint32_t status; | 
|  | 2600 | uint32_t ha_copy; | 
|  | 2601 | int retval; | 
|  | 2602 | int i = 0; | 
|  | 2603 |  | 
|  | 2604 | psli = &phba->sli; | 
|  | 2605 |  | 
|  | 2606 | /* Kill HBA */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2607 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2608 | "0329 Kill HBA Data: x%x x%x\n", | 
|  | 2609 | phba->pport->port_state, psli->sli_flag); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2610 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2611 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 2612 | if (!pmb) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2613 | return 1; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2614 |  | 
|  | 2615 | /* Disable the error attention */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | spin_lock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2617 | status = readl(phba->HCregaddr); | 
|  | 2618 | status &= ~HC_ERINT_ENA; | 
|  | 2619 | writel(status, phba->HCregaddr); | 
|  | 2620 | readl(phba->HCregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2621 | phba->link_flag |= LS_IGNORE_ERATT; | 
|  | 2622 | spin_unlock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2623 |  | 
|  | 2624 | lpfc_kill_board(phba, pmb); | 
|  | 2625 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
|  | 2626 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 
|  | 2627 |  | 
|  | 2628 | if (retval != MBX_SUCCESS) { | 
|  | 2629 | if (retval != MBX_BUSY) | 
|  | 2630 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | spin_lock_irq(&phba->hbalock); | 
|  | 2632 | phba->link_flag &= ~LS_IGNORE_ERATT; | 
|  | 2633 | spin_unlock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2634 | return 1; | 
|  | 2635 | } | 
|  | 2636 |  | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2637 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
|  | 2638 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2639 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 2640 |  | 
|  | 2641 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | 
|  | 2642 | * attention every 100ms for 3 seconds. If we don't get ERATT after | 
|  | 2643 | * 3 seconds we still set HBA_ERROR state because the status of the | 
|  | 2644 | * board is now undefined. | 
|  | 2645 | */ | 
|  | 2646 | ha_copy = readl(phba->HAregaddr); | 
|  | 2647 |  | 
|  | 2648 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { | 
|  | 2649 | mdelay(100); | 
|  | 2650 | ha_copy = readl(phba->HAregaddr); | 
|  | 2651 | } | 
|  | 2652 |  | 
|  | 2653 | del_timer_sync(&psli->mbox_tmo); | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2654 | if (ha_copy & HA_ERATT) { | 
|  | 2655 | writel(HA_ERATT, phba->HAregaddr); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | phba->pport->stopped = 1; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2657 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | spin_lock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2659 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2660 | phba->link_flag &= ~LS_IGNORE_ERATT; | 
|  | 2661 | spin_unlock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2662 |  | 
|  | 2663 | psli->mbox_active = NULL; | 
|  | 2664 | lpfc_hba_down_post(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | phba->link_state = LPFC_HBA_ERROR; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2666 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2667 | return ha_copy & HA_ERATT ? 0 : 1; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2668 | } | 
|  | 2669 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2670 | /** | 
|  | 2671 | * lpfc_sli_brdreset: Reset the HBA. | 
|  | 2672 | * @phba: Pointer to HBA context object. | 
|  | 2673 | * | 
|  | 2674 | * This function resets the HBA by writing HC_INITFF to the control | 
|  | 2675 | * register. After the HBA resets, this function resets all the iocb ring | 
|  | 2676 | * indices. This function disables PCI layer parity checking during | 
|  | 2677 | * the reset. | 
|  | 2678 | * This function returns 0 always. | 
|  | 2679 | * The caller is not required to hold any locks. | 
|  | 2680 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2681 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2682 | lpfc_sli_brdreset(struct lpfc_hba *phba) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2683 | { | 
|  | 2684 | struct lpfc_sli *psli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | struct lpfc_sli_ring *pring; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2686 | uint16_t cfg_value; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2689 | psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2691 | /* Reset HBA */ | 
|  | 2692 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2693 | "0325 Reset HBA Data: x%x x%x\n", | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2694 | phba->pport->port_state, psli->sli_flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 |  | 
|  | 2696 | /* perform board reset */ | 
|  | 2697 | phba->fc_eventTag = 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | phba->pport->fc_myDID = 0; | 
|  | 2699 | phba->pport->fc_prevDID = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2701 | /* Turn off parity checking and serr during the physical reset */ | 
|  | 2702 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | 
|  | 2703 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | 
|  | 2704 | (cfg_value & | 
|  | 2705 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | 
|  | 2706 |  | 
| James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2707 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2708 | /* Now toggle INITFF bit in the Host Control Register */ | 
|  | 2709 | writel(HC_INITFF, phba->HCregaddr); | 
|  | 2710 | mdelay(1); | 
|  | 2711 | readl(phba->HCregaddr); /* flush */ | 
|  | 2712 | writel(0, phba->HCregaddr); | 
|  | 2713 | readl(phba->HCregaddr); /* flush */ | 
|  | 2714 |  | 
|  | 2715 | /* Restore PCI cmd register */ | 
|  | 2716 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 |  | 
|  | 2718 | /* Initialize relevant SLI info */ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2719 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 2720 | pring = &psli->ring[i]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | pring->flag = 0; | 
|  | 2722 | pring->rspidx = 0; | 
|  | 2723 | pring->next_cmdidx  = 0; | 
|  | 2724 | pring->local_getidx = 0; | 
|  | 2725 | pring->cmdidx = 0; | 
|  | 2726 | pring->missbufcnt = 0; | 
|  | 2727 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | phba->link_state = LPFC_WARM_START; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2730 | return 0; | 
|  | 2731 | } | 
|  | 2732 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2733 | /** | 
|  | 2734 | * lpfc_sli_brdrestart: Restart the HBA. | 
|  | 2735 | * @phba: Pointer to HBA context object. | 
|  | 2736 | * | 
|  | 2737 | * This function is called in the SLI initialization code path to | 
|  | 2738 | * restart the HBA. The caller is not required to hold any lock. | 
|  | 2739 | * This function writes MBX_RESTART mailbox command to the SLIM and | 
|  | 2740 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | 
|  | 2741 | * function to free any pending commands. The function enables | 
|  | 2742 | * POST only during the first initialization. The function returns zero. | 
|  | 2743 | * The function does not guarantee completion of MBX_RESTART mailbox | 
|  | 2744 | * command before the return of this function. | 
|  | 2745 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2746 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2747 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2748 | { | 
|  | 2749 | MAILBOX_t *mb; | 
|  | 2750 | struct lpfc_sli *psli; | 
|  | 2751 | uint16_t skip_post; | 
|  | 2752 | volatile uint32_t word0; | 
|  | 2753 | void __iomem *to_slim; | 
|  | 2754 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | spin_lock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2756 |  | 
|  | 2757 | psli = &phba->sli; | 
|  | 2758 |  | 
|  | 2759 | /* Restart HBA */ | 
|  | 2760 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2761 | "0337 Restart HBA Data: x%x x%x\n", | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | phba->pport->port_state, psli->sli_flag); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2763 |  | 
|  | 2764 | word0 = 0; | 
|  | 2765 | mb = (MAILBOX_t *) &word0; | 
|  | 2766 | mb->mbxCommand = MBX_RESTART; | 
|  | 2767 | mb->mbxHc = 1; | 
|  | 2768 |  | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2769 | lpfc_reset_barrier(phba); | 
|  | 2770 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2771 | to_slim = phba->MBslimaddr; | 
|  | 2772 | writel(*(uint32_t *) mb, to_slim); | 
|  | 2773 | readl(to_slim); /* flush */ | 
|  | 2774 |  | 
|  | 2775 | /* Only skip post after fc_ffinit is completed */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2776 | if (phba->pport->port_state) { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2777 | skip_post = 1; | 
|  | 2778 | word0 = 1;	/* This is really setting up word1 */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | } else { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2780 | skip_post = 0; | 
|  | 2781 | word0 = 0;	/* This is really setting up word1 */ | 
|  | 2782 | } | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2783 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2784 | writel(*(uint32_t *) mb, to_slim); | 
|  | 2785 | readl(to_slim); /* flush */ | 
|  | 2786 |  | 
|  | 2787 | lpfc_sli_brdreset(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2788 | phba->pport->stopped = 0; | 
|  | 2789 | phba->link_state = LPFC_INIT_START; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2790 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2791 | spin_unlock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2792 |  | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2793 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | 
|  | 2794 | psli->stats_start = get_seconds(); | 
|  | 2795 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2796 | if (skip_post) | 
|  | 2797 | mdelay(100); | 
|  | 2798 | else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | mdelay(2000); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2800 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2801 | lpfc_hba_down_post(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2802 |  | 
|  | 2803 | return 0; | 
|  | 2804 | } | 
|  | 2805 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2806 | /** | 
|  | 2807 | * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart. | 
|  | 2808 | * @phba: Pointer to HBA context object. | 
|  | 2809 | * | 
|  | 2810 | * This function is called after a HBA restart to wait for successful | 
|  | 2811 | * restart of the HBA. Successful restart of the HBA is indicated by | 
|  | 2812 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | 
|  | 2813 | * iteration, the function will restart the HBA again. The function returns | 
|  | 2814 | * zero if HBA successfully restarted else returns negative error code. | 
|  | 2815 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | static int | 
|  | 2817 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | 
|  | 2818 | { | 
|  | 2819 | uint32_t status, i = 0; | 
|  | 2820 |  | 
|  | 2821 | /* Read the HBA Host Status Register */ | 
|  | 2822 | status = readl(phba->HSregaddr); | 
|  | 2823 |  | 
|  | 2824 | /* Check status register to see what current state is */ | 
|  | 2825 | i = 0; | 
|  | 2826 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | 
|  | 2827 |  | 
|  | 2828 | /* Check every 100ms for 5 retries, then every 500ms for 5, then | 
|  | 2829 | * every 2.5 sec for 5, then reset board and every 2.5 sec for | 
|  | 2830 | * 4. | 
|  | 2831 | */ | 
|  | 2832 | if (i++ >= 20) { | 
|  | 2833 | /* Adapter failed to init, timeout, status reg | 
|  | 2834 | <status> */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2835 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2836 | "0436 Adapter failed to init, " | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2837 | "timeout, status reg x%x, " | 
|  | 2838 | "FW Data: A8 x%x AC x%x\n", status, | 
|  | 2839 | readl(phba->MBslimaddr + 0xa8), | 
|  | 2840 | readl(phba->MBslimaddr + 0xac)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2841 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2842 | return -ETIMEDOUT; | 
|  | 2843 | } | 
|  | 2844 |  | 
|  | 2845 | /* Check to see if any errors occurred during init */ | 
|  | 2846 | if (status & HS_FFERM) { | 
|  | 2847 | /* ERROR: During chipset initialization */ | 
|  | 2848 | /* Adapter failed to init, chipset, status reg | 
|  | 2849 | <status> */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2851 | "0437 Adapter failed to init, " | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2852 | "chipset, status reg x%x, " | 
|  | 2853 | "FW Data: A8 x%x AC x%x\n", status, | 
|  | 2854 | readl(phba->MBslimaddr + 0xa8), | 
|  | 2855 | readl(phba->MBslimaddr + 0xac)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2856 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | return -EIO; | 
|  | 2858 | } | 
|  | 2859 |  | 
|  | 2860 | if (i <= 5) { | 
|  | 2861 | msleep(10); | 
|  | 2862 | } else if (i <= 10) { | 
|  | 2863 | msleep(500); | 
|  | 2864 | } else { | 
|  | 2865 | msleep(2500); | 
|  | 2866 | } | 
|  | 2867 |  | 
|  | 2868 | if (i == 15) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2869 | /* Do post */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2870 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2871 | lpfc_sli_brdrestart(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | } | 
|  | 2873 | /* Read the HBA Host Status Register */ | 
|  | 2874 | status = readl(phba->HSregaddr); | 
|  | 2875 | } | 
|  | 2876 |  | 
|  | 2877 | /* Check to see if any errors occurred during init */ | 
|  | 2878 | if (status & HS_FFERM) { | 
|  | 2879 | /* ERROR: During chipset initialization */ | 
|  | 2880 | /* Adapter failed to init, chipset, status reg <status> */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2882 | "0438 Adapter failed to init, chipset, " | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2883 | "status reg x%x, " | 
|  | 2884 | "FW Data: A8 x%x AC x%x\n", status, | 
|  | 2885 | readl(phba->MBslimaddr + 0xa8), | 
|  | 2886 | readl(phba->MBslimaddr + 0xac)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2887 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | return -EIO; | 
|  | 2889 | } | 
|  | 2890 |  | 
|  | 2891 | /* Clear all interrupt enable conditions */ | 
|  | 2892 | writel(0, phba->HCregaddr); | 
|  | 2893 | readl(phba->HCregaddr); /* flush */ | 
|  | 2894 |  | 
|  | 2895 | /* setup host attn register */ | 
|  | 2896 | writel(0xffffffff, phba->HAregaddr); | 
|  | 2897 | readl(phba->HAregaddr); /* flush */ | 
|  | 2898 | return 0; | 
|  | 2899 | } | 
|  | 2900 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2901 | /** | 
|  | 2902 | * lpfc_sli_hbq_count: Get the number of HBQs to be configured. | 
|  | 2903 | * | 
|  | 2904 | * This function calculates and returns the number of HBQs required to be | 
|  | 2905 | * configured. | 
|  | 2906 | **/ | 
| James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2907 | int | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2908 | lpfc_sli_hbq_count(void) | 
|  | 2909 | { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2910 | return ARRAY_SIZE(lpfc_hbq_defs); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2911 | } | 
|  | 2912 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2913 | /** | 
|  | 2914 | * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries. | 
|  | 2915 | * | 
|  | 2916 | * This function adds the number of hbq entries in every HBQ to get | 
|  | 2917 | * the total number of hbq entries required for the HBA and returns | 
|  | 2918 | * the total count. | 
|  | 2919 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2920 | static int | 
|  | 2921 | lpfc_sli_hbq_entry_count(void) | 
|  | 2922 | { | 
|  | 2923 | int  hbq_count = lpfc_sli_hbq_count(); | 
|  | 2924 | int  count = 0; | 
|  | 2925 | int  i; | 
|  | 2926 |  | 
|  | 2927 | for (i = 0; i < hbq_count; ++i) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2928 | count += lpfc_hbq_defs[i]->entry_count; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2929 | return count; | 
|  | 2930 | } | 
|  | 2931 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2932 | /** | 
|  | 2933 | * lpfc_sli_hbq_size: Calculate memory required for all hbq entries. | 
|  | 2934 | * | 
|  | 2935 | * This function calculates amount of memory required for all hbq entries | 
|  | 2936 | * to be configured and returns the total memory required. | 
|  | 2937 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | int | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2939 | lpfc_sli_hbq_size(void) | 
|  | 2940 | { | 
|  | 2941 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | 
|  | 2942 | } | 
|  | 2943 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2944 | /** | 
|  | 2945 | * lpfc_sli_hbq_setup: configure and initialize HBQs. | 
|  | 2946 | * @phba: Pointer to HBA context object. | 
|  | 2947 | * | 
|  | 2948 | * This function is called during the SLI initialization to configure | 
|  | 2949 | * all the HBQs and post buffers to the HBQ. The caller is not | 
|  | 2950 | * required to hold any locks. This function will return zero if successful | 
|  | 2951 | * else it will return negative error code. | 
|  | 2952 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2953 | static int | 
|  | 2954 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | 
|  | 2955 | { | 
|  | 2956 | int  hbq_count = lpfc_sli_hbq_count(); | 
|  | 2957 | LPFC_MBOXQ_t *pmb; | 
|  | 2958 | MAILBOX_t *pmbox; | 
|  | 2959 | uint32_t hbqno; | 
|  | 2960 | uint32_t hbq_entry_index; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2961 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2962 | /* Get a Mailbox buffer to setup mailbox | 
|  | 2963 | * commands for HBA initialization | 
|  | 2964 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2965 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 2966 |  | 
|  | 2967 | if (!pmb) | 
|  | 2968 | return -ENOMEM; | 
|  | 2969 |  | 
|  | 2970 | pmbox = &pmb->mb; | 
|  | 2971 |  | 
|  | 2972 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | 
|  | 2973 | phba->link_state = LPFC_INIT_MBX_CMDS; | 
| James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2974 | phba->hbq_in_use = 1; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2975 |  | 
|  | 2976 | hbq_entry_index = 0; | 
|  | 2977 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | 
|  | 2978 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | 
|  | 2979 | phba->hbqs[hbqno].hbqPutIdx      = 0; | 
|  | 2980 | phba->hbqs[hbqno].local_hbqGetIdx   = 0; | 
|  | 2981 | phba->hbqs[hbqno].entry_count = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2982 | lpfc_hbq_defs[hbqno]->entry_count; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2983 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], | 
|  | 2984 | hbq_entry_index, pmb); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2985 | hbq_entry_index += phba->hbqs[hbqno].entry_count; | 
|  | 2986 |  | 
|  | 2987 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | 
|  | 2988 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | 
|  | 2989 | mbxStatus <status>, ring <num> */ | 
|  | 2990 |  | 
|  | 2991 | lpfc_printf_log(phba, KERN_ERR, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2992 | LOG_SLI | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2993 | "1805 Adapter failed to init. " | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2994 | "Data: x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2995 | pmbox->mbxCommand, | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2996 | pmbox->mbxStatus, hbqno); | 
|  | 2997 |  | 
|  | 2998 | phba->link_state = LPFC_HBA_ERROR; | 
|  | 2999 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3000 | return ENXIO; | 
|  | 3001 | } | 
|  | 3002 | } | 
|  | 3003 | phba->hbq_count = hbq_count; | 
|  | 3004 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3005 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 3006 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3007 | /* Initially populate or replenish the HBQs */ | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3008 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) | 
|  | 3009 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3010 | return 0; | 
|  | 3011 | } | 
|  | 3012 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3013 | /** | 
|  | 3014 | * lpfc_do_config_port: Issue config port mailbox command. | 
|  | 3015 | * @phba: Pointer to HBA context object. | 
|  | 3016 | * @sli_mode: sli mode - 2/3 | 
|  | 3017 | * | 
|  | 3018 | * This function is called by the sli intialization code path | 
|  | 3019 | * to issue config_port mailbox command. This function restarts the | 
|  | 3020 | * HBA firmware and issues a config_port mailbox command to configure | 
|  | 3021 | * the SLI interface in the sli mode specified by sli_mode | 
|  | 3022 | * variable. The caller is not required to hold any locks. | 
|  | 3023 | * The function returns 0 if successful, else returns negative error | 
|  | 3024 | * code. | 
|  | 3025 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3026 | static int | 
|  | 3027 | lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | { | 
|  | 3029 | LPFC_MBOXQ_t *pmb; | 
|  | 3030 | uint32_t resetcount = 0, rc = 0, done = 0; | 
|  | 3031 |  | 
|  | 3032 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 3033 | if (!pmb) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3034 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | return -ENOMEM; | 
|  | 3036 | } | 
|  | 3037 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3038 | phba->sli_rev = sli_mode; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | while (resetcount < 2 && !done) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3040 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3041 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3044 | lpfc_sli_brdrestart(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | msleep(2500); | 
|  | 3046 | rc = lpfc_sli_chipset_init(phba); | 
|  | 3047 | if (rc) | 
|  | 3048 | break; | 
|  | 3049 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3050 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3051 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | resetcount++; | 
|  | 3054 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3055 | /* Call pre CONFIG_PORT mailbox command initialization.  A | 
|  | 3056 | * value of 0 means the call was successful.  Any other | 
|  | 3057 | * nonzero value is a failure, but if ERESTART is returned, | 
|  | 3058 | * the driver may reset the HBA and try again. | 
|  | 3059 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | rc = lpfc_config_port_prep(phba); | 
|  | 3061 | if (rc == -ERESTART) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3062 | phba->link_state = LPFC_LINK_UNKNOWN; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | continue; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3064 | } else if (rc) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | break; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3066 | phba->link_state = LPFC_INIT_MBX_CMDS; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | lpfc_config_port(phba, pmb); | 
|  | 3068 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3069 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | | 
|  | 3070 | LPFC_SLI3_HBQ_ENABLED | | 
|  | 3071 | LPFC_SLI3_CRP_ENABLED | | 
|  | 3072 | LPFC_SLI3_INB_ENABLED); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3073 | if (rc != MBX_SUCCESS) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3075 | "0442 Adapter failed to init, mbxCmd x%x " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3076 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3077 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3078 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3080 | spin_unlock_irq(&phba->hbalock); | 
|  | 3081 | rc = -ENXIO; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3082 | } else | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3083 | done = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3085 | if (!done) { | 
|  | 3086 | rc = -EINVAL; | 
|  | 3087 | goto do_prep_failed; | 
|  | 3088 | } | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3089 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { | 
|  | 3090 | if (!pmb->mb.un.varCfgPort.cMA) { | 
|  | 3091 | rc = -ENXIO; | 
|  | 3092 | goto do_prep_failed; | 
|  | 3093 | } | 
|  | 3094 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { | 
|  | 3095 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; | 
|  | 3096 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; | 
|  | 3097 | } else | 
|  | 3098 | phba->max_vpi = 0; | 
|  | 3099 | if (pmb->mb.un.varCfgPort.gerbm) | 
|  | 3100 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; | 
|  | 3101 | if (pmb->mb.un.varCfgPort.gcrp) | 
|  | 3102 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; | 
|  | 3103 | if (pmb->mb.un.varCfgPort.ginb) { | 
|  | 3104 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; | 
|  | 3105 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; | 
|  | 3106 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; | 
|  | 3107 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; | 
|  | 3108 | phba->inb_last_counter = | 
|  | 3109 | phba->mbox->us.s3_inb_pgp.counter; | 
|  | 3110 | } else { | 
|  | 3111 | phba->port_gp = phba->mbox->us.s3_pgp.port; | 
|  | 3112 | phba->inb_ha_copy = NULL; | 
|  | 3113 | phba->inb_counter = NULL; | 
|  | 3114 | } | 
|  | 3115 | } else { | 
|  | 3116 | phba->port_gp = phba->mbox->us.s2.port; | 
|  | 3117 | phba->inb_ha_copy = NULL; | 
|  | 3118 | phba->inb_counter = NULL; | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3119 | phba->max_vpi = 0; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3120 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3121 | do_prep_failed: | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3122 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 3123 | return rc; | 
|  | 3124 | } | 
|  | 3125 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3126 |  | 
|  | 3127 | /** | 
|  | 3128 | * lpfc_sli_hba_setup: SLI intialization function. | 
|  | 3129 | * @phba: Pointer to HBA context object. | 
|  | 3130 | * | 
|  | 3131 | * This function is the main SLI intialization function. This function | 
|  | 3132 | * is called by the HBA intialization code, HBA reset code and HBA | 
|  | 3133 | * error attention handler code. Caller is not required to hold any | 
|  | 3134 | * locks. This function issues config_port mailbox command to configure | 
|  | 3135 | * the SLI, setup iocb rings and HBQ rings. In the end the function | 
|  | 3136 | * calls the config_port_post function to issue init_link mailbox | 
|  | 3137 | * command and to start the discovery. The function will return zero | 
|  | 3138 | * if successful, else it will return negative error code. | 
|  | 3139 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3140 | int | 
|  | 3141 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | 
|  | 3142 | { | 
|  | 3143 | uint32_t rc; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3144 | int  mode = 3; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3145 |  | 
|  | 3146 | switch (lpfc_sli_mode) { | 
|  | 3147 | case 2: | 
| James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3148 | if (phba->cfg_enable_npiv) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3150 | "1824 NPIV enabled: Override lpfc_sli_mode " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | "parameter (%d) to auto (0).\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3152 | lpfc_sli_mode); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3153 | break; | 
|  | 3154 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3155 | mode = 2; | 
|  | 3156 | break; | 
|  | 3157 | case 0: | 
|  | 3158 | case 3: | 
|  | 3159 | break; | 
|  | 3160 | default: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3162 | "1819 Unrecognized lpfc_sli_mode " | 
|  | 3163 | "parameter: %d.\n", lpfc_sli_mode); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3164 |  | 
|  | 3165 | break; | 
|  | 3166 | } | 
|  | 3167 |  | 
|  | 3168 | rc = lpfc_do_config_port(phba, mode); | 
|  | 3169 | if (rc && lpfc_sli_mode == 3) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3170 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3171 | "1820 Unable to select SLI-3.  " | 
|  | 3172 | "Not supported by adapter.\n"); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3173 | if (rc && mode != 2) | 
|  | 3174 | rc = lpfc_do_config_port(phba, 2); | 
|  | 3175 | if (rc) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | goto lpfc_sli_hba_setup_error; | 
|  | 3177 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3178 | if (phba->sli_rev == 3) { | 
|  | 3179 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | 
|  | 3180 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3181 | } else { | 
|  | 3182 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | 
|  | 3183 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3184 | phba->sli3_options = 0; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3185 | } | 
|  | 3186 |  | 
|  | 3187 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3188 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", | 
|  | 3189 | phba->sli_rev, phba->max_vpi); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3190 | rc = lpfc_sli_ring_map(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 |  | 
|  | 3192 | if (rc) | 
|  | 3193 | goto lpfc_sli_hba_setup_error; | 
|  | 3194 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3195 | /* Init HBQs */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3196 |  | 
|  | 3197 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | 
|  | 3198 | rc = lpfc_sli_hbq_setup(phba); | 
|  | 3199 | if (rc) | 
|  | 3200 | goto lpfc_sli_hba_setup_error; | 
|  | 3201 | } | 
|  | 3202 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | phba->sli.sli_flag |= LPFC_PROCESS_LA; | 
|  | 3204 |  | 
|  | 3205 | rc = lpfc_config_port_post(phba); | 
|  | 3206 | if (rc) | 
|  | 3207 | goto lpfc_sli_hba_setup_error; | 
|  | 3208 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3209 | return rc; | 
|  | 3210 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3211 | lpfc_sli_hba_setup_error: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3212 | phba->link_state = LPFC_HBA_ERROR; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3213 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3214 | "0445 Firmware initialization failed\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | return rc; | 
|  | 3216 | } | 
|  | 3217 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3218 |  | 
|  | 3219 | /** | 
|  | 3220 | * lpfc_mbox_timeout: Timeout call back function for mbox timer. | 
|  | 3221 | * @ptr: context object - pointer to hba structure. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | * | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3223 | * This is the callback function for mailbox timer. The mailbox | 
|  | 3224 | * timer is armed when a new mailbox command is issued and the timer | 
|  | 3225 | * is deleted when the mailbox complete. The function is called by | 
|  | 3226 | * the kernel timer code when a mailbox does not complete within | 
|  | 3227 | * expected time. This function wakes up the worker thread to | 
|  | 3228 | * process the mailbox timeout and returns. All the processing is | 
|  | 3229 | * done by the worker thread function lpfc_mbox_timeout_handler. | 
|  | 3230 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | void | 
|  | 3232 | lpfc_mbox_timeout(unsigned long ptr) | 
|  | 3233 | { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3234 | struct lpfc_hba  *phba = (struct lpfc_hba *) ptr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | unsigned long iflag; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3236 | uint32_t tmo_posted; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3238 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3239 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | if (!tmo_posted) | 
|  | 3241 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | 
|  | 3242 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | 
|  | 3243 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3244 | if (!tmo_posted) | 
|  | 3245 | lpfc_worker_wake_up(phba); | 
|  | 3246 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | } | 
|  | 3248 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3249 |  | 
|  | 3250 | /** | 
|  | 3251 | * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout. | 
|  | 3252 | * @phba: Pointer to HBA context object. | 
|  | 3253 | * | 
|  | 3254 | * This function is called from worker thread when a mailbox command times out. | 
|  | 3255 | * The caller is not required to hold any locks. This function will reset the | 
|  | 3256 | * HBA and recover all the pending commands. | 
|  | 3257 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | void | 
|  | 3259 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | 
|  | 3260 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3261 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | 
|  | 3262 | MAILBOX_t *mb = &pmbox->mb; | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3263 | struct lpfc_sli *psli = &phba->sli; | 
|  | 3264 | struct lpfc_sli_ring *pring; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | return; | 
|  | 3268 | } | 
|  | 3269 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | /* Mbox cmd <mbxCommand> timeout */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3271 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3272 | "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] | 3273 | mb->mbxCommand, | 
|  | 3274 | phba->pport->port_state, | 
|  | 3275 | phba->sli.sli_flag, | 
|  | 3276 | phba->sli.mbox_active); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3278 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | 
|  | 3279 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | 
|  | 3280 | * it to fail all oustanding SCSI IO. | 
|  | 3281 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3282 | spin_lock_irq(&phba->pport->work_port_lock); | 
|  | 3283 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | 
|  | 3284 | spin_unlock_irq(&phba->pport->work_port_lock); | 
|  | 3285 | spin_lock_irq(&phba->hbalock); | 
|  | 3286 | phba->link_state = LPFC_LINK_UNKNOWN; | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3287 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3288 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3289 |  | 
|  | 3290 | pring = &psli->ring[psli->fcp_ring]; | 
|  | 3291 | lpfc_sli_abort_iocb_ring(phba, pring); | 
|  | 3292 |  | 
|  | 3293 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3294 | "0345 Resetting board due to mailbox timeout\n"); | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3295 | /* | 
|  | 3296 | * lpfc_offline calls lpfc_sli_hba_down which will clean up | 
|  | 3297 | * on oustanding mailbox commands. | 
|  | 3298 | */ | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3299 | /* If resets are disabled then set error state and return. */ | 
|  | 3300 | if (!phba->cfg_enable_hba_reset) { | 
|  | 3301 | phba->link_state = LPFC_HBA_ERROR; | 
|  | 3302 | return; | 
|  | 3303 | } | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3304 | lpfc_offline_prep(phba); | 
|  | 3305 | lpfc_offline(phba); | 
|  | 3306 | lpfc_sli_brdrestart(phba); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3307 | lpfc_online(phba); | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3308 | lpfc_unblock_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | return; | 
|  | 3310 | } | 
|  | 3311 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3312 | /** | 
|  | 3313 | * lpfc_sli_issue_mbox: Issue a mailbox command to firmware. | 
|  | 3314 | * @phba: Pointer to HBA context object. | 
|  | 3315 | * @pmbox: Pointer to mailbox object. | 
|  | 3316 | * @flag: Flag indicating how the mailbox need to be processed. | 
|  | 3317 | * | 
|  | 3318 | * This function is called by discovery code and HBA management code | 
|  | 3319 | * to submit a mailbox command to firmware. This function gets the | 
|  | 3320 | * hbalock to protect the data structures. | 
|  | 3321 | * The mailbox command can be submitted in polling mode, in which case | 
|  | 3322 | * this function will wait in a polling loop for the completion of the | 
|  | 3323 | * mailbox. | 
|  | 3324 | * If the mailbox is submitted in no_wait mode (not polling) the | 
|  | 3325 | * function will submit the command and returns immediately without waiting | 
|  | 3326 | * for the mailbox completion. The no_wait is supported only when HBA | 
|  | 3327 | * is in SLI2/SLI3 mode - interrupts are enabled. | 
|  | 3328 | * The SLI interface allows only one mailbox pending at a time. If the | 
|  | 3329 | * mailbox is issued in polling mode and there is already a mailbox | 
|  | 3330 | * pending, then the function will return an error. If the mailbox is issued | 
|  | 3331 | * in NO_WAIT mode and there is a mailbox pending already, the function | 
|  | 3332 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | 
|  | 3333 | * The sli layer owns the mailbox object until the completion of mailbox | 
|  | 3334 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | 
|  | 3335 | * return codes the caller owns the mailbox command after the return of | 
|  | 3336 | * the function. | 
|  | 3337 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | 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] | 3340 | { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | MAILBOX_t *mb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3342 | struct lpfc_sli *psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | uint32_t status, evtctr; | 
|  | 3344 | uint32_t ha_copy; | 
|  | 3345 | int i; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3346 | unsigned long timeout; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | unsigned long drvr_flag = 0; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3348 | uint32_t word0, ldata; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | void __iomem *to_slim; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3350 | int processing_queue = 0; | 
|  | 3351 |  | 
|  | 3352 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | 
|  | 3353 | if (!pmbox) { | 
|  | 3354 | /* processing mbox queue from intr_handler */ | 
|  | 3355 | processing_queue = 1; | 
|  | 3356 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
|  | 3357 | pmbox = lpfc_mbox_get(phba); | 
|  | 3358 | if (!pmbox) { | 
|  | 3359 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | 3360 | return MBX_SUCCESS; | 
|  | 3361 | } | 
|  | 3362 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3364 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3365 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3366 | if(!pmbox->vport) { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3367 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3368 | lpfc_printf_log(phba, KERN_ERR, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3369 | LOG_MBOX | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3370 | "1806 Mbox x%x failed. No vport\n", | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3371 | pmbox->mb.mbxCommand); | 
|  | 3372 | dump_stack(); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3373 | goto out_not_finished; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3374 | } | 
|  | 3375 | } | 
|  | 3376 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3377 | /* If the PCI channel is in offline state, do not post mbox. */ | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3378 | if (unlikely(pci_channel_offline(phba->pcidev))) { | 
|  | 3379 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | 3380 | goto out_not_finished; | 
|  | 3381 | } | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3382 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | psli = &phba->sli; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3384 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | mb = &pmbox->mb; | 
|  | 3386 | status = MBX_SUCCESS; | 
|  | 3387 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | if (phba->link_state == LPFC_HBA_ERROR) { | 
|  | 3389 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3390 |  | 
|  | 3391 | /* Mbox command <mbxCommand> cannot issue */ | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3392 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3393 | goto out_not_finished; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3394 | } | 
|  | 3395 |  | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3396 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && | 
|  | 3397 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3398 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3399 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3400 | goto out_not_finished; | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3401 | } | 
|  | 3402 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | 
|  | 3404 | /* Polling for a mbox command when another one is already active | 
|  | 3405 | * is not allowed in SLI. Also, the driver must have established | 
|  | 3406 | * SLI2 mode to queue and process multiple mbox commands. | 
|  | 3407 | */ | 
|  | 3408 |  | 
|  | 3409 | if (flag & MBX_POLL) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 |  | 
|  | 3412 | /* Mbox command <mbxCommand> cannot issue */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3413 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3414 | goto out_not_finished; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | } | 
|  | 3416 |  | 
|  | 3417 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3418 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | /* Mbox command <mbxCommand> cannot issue */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3420 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3421 | goto out_not_finished; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | } | 
|  | 3423 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | /* Another mailbox command is still being processed, queue this | 
|  | 3425 | * command to be processed later. | 
|  | 3426 | */ | 
|  | 3427 | lpfc_mbox_put(phba, pmbox); | 
|  | 3428 |  | 
|  | 3429 | /* Mbox cmd issue - BUSY */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3430 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3431 | "(%d):0308 Mbox cmd issue - BUSY Data: " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3432 | "x%x x%x x%x x%x\n", | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3433 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, | 
|  | 3434 | mb->mbxCommand, phba->pport->port_state, | 
|  | 3435 | psli->sli_flag, flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3436 |  | 
|  | 3437 | psli->slistat.mbox_busy++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3438 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3440 | if (pmbox->vport) { | 
|  | 3441 | lpfc_debugfs_disc_trc(pmbox->vport, | 
|  | 3442 | LPFC_DISC_TRC_MBOX_VPORT, | 
|  | 3443 | "MBOX Bsy vport:  cmd:x%x mb:x%x x%x", | 
|  | 3444 | (uint32_t)mb->mbxCommand, | 
|  | 3445 | mb->un.varWords[0], mb->un.varWords[1]); | 
|  | 3446 | } | 
|  | 3447 | else { | 
|  | 3448 | lpfc_debugfs_disc_trc(phba->pport, | 
|  | 3449 | LPFC_DISC_TRC_MBOX, | 
|  | 3450 | "MBOX Bsy:        cmd:x%x mb:x%x x%x", | 
|  | 3451 | (uint32_t)mb->mbxCommand, | 
|  | 3452 | mb->un.varWords[0], mb->un.varWords[1]); | 
|  | 3453 | } | 
|  | 3454 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3455 | return MBX_BUSY; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | } | 
|  | 3457 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | 
|  | 3459 |  | 
|  | 3460 | /* If we are not polling, we MUST be in SLI2 mode */ | 
|  | 3461 | if (flag != MBX_POLL) { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3462 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && | 
|  | 3463 | (mb->mbxCommand != MBX_KILL_BOARD)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3464 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3465 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | /* Mbox command <mbxCommand> cannot issue */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3467 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3468 | goto out_not_finished; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | } | 
|  | 3470 | /* timeout active mbox command */ | 
| James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3471 | mod_timer(&psli->mbox_tmo, (jiffies + | 
|  | 3472 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | } | 
|  | 3474 |  | 
|  | 3475 | /* Mailbox cmd <cmd> issue */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3476 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3477 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | "x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3479 | pmbox->vport ? pmbox->vport->vpi : 0, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3480 | mb->mbxCommand, phba->pport->port_state, | 
|  | 3481 | psli->sli_flag, flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3483 | if (mb->mbxCommand != MBX_HEARTBEAT) { | 
|  | 3484 | if (pmbox->vport) { | 
|  | 3485 | lpfc_debugfs_disc_trc(pmbox->vport, | 
|  | 3486 | LPFC_DISC_TRC_MBOX_VPORT, | 
|  | 3487 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | 
|  | 3488 | (uint32_t)mb->mbxCommand, | 
|  | 3489 | mb->un.varWords[0], mb->un.varWords[1]); | 
|  | 3490 | } | 
|  | 3491 | else { | 
|  | 3492 | lpfc_debugfs_disc_trc(phba->pport, | 
|  | 3493 | LPFC_DISC_TRC_MBOX, | 
|  | 3494 | "MBOX Send:       cmd:x%x mb:x%x x%x", | 
|  | 3495 | (uint32_t)mb->mbxCommand, | 
|  | 3496 | mb->un.varWords[0], mb->un.varWords[1]); | 
|  | 3497 | } | 
|  | 3498 | } | 
|  | 3499 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | psli->slistat.mbox_cmd++; | 
|  | 3501 | evtctr = psli->slistat.mbox_event; | 
|  | 3502 |  | 
|  | 3503 | /* next set own bit for the adapter and copy over command word */ | 
|  | 3504 | mb->mbxOwner = OWN_CHIP; | 
|  | 3505 |  | 
|  | 3506 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | /* First copy command data to host SLIM area */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3508 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | } else { | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3510 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3511 | /* copy command data into host mbox for cmpl */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3512 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | } | 
|  | 3514 |  | 
|  | 3515 | /* First copy mbox command data to HBA SLIM, skip past first | 
|  | 3516 | word */ | 
|  | 3517 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | 
|  | 3518 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | 
|  | 3519 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | 
|  | 3520 |  | 
|  | 3521 | /* Next copy over first word, with mbxOwner set */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3522 | ldata = *((uint32_t *)mb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | to_slim = phba->MBslimaddr; | 
|  | 3524 | writel(ldata, to_slim); | 
|  | 3525 | readl(to_slim); /* flush */ | 
|  | 3526 |  | 
|  | 3527 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | 
|  | 3528 | /* switch over to host mailbox */ | 
|  | 3529 | psli->sli_flag |= LPFC_SLI2_ACTIVE; | 
|  | 3530 | } | 
|  | 3531 | } | 
|  | 3532 |  | 
|  | 3533 | wmb(); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 |  | 
|  | 3535 | switch (flag) { | 
|  | 3536 | case MBX_NOWAIT: | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3537 | /* Set up reference to mailbox command */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | psli->mbox_active = pmbox; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3539 | /* Interrupt board to do it */ | 
|  | 3540 | writel(CA_MBATT, phba->CAregaddr); | 
|  | 3541 | readl(phba->CAregaddr); /* flush */ | 
|  | 3542 | /* Don't wait for it to finish, just return */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | break; | 
|  | 3544 |  | 
|  | 3545 | case MBX_POLL: | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3546 | /* Set up null reference to mailbox command */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | psli->mbox_active = NULL; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3548 | /* Interrupt board to do it */ | 
|  | 3549 | writel(CA_MBATT, phba->CAregaddr); | 
|  | 3550 | readl(phba->CAregaddr); /* flush */ | 
|  | 3551 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 
|  | 3553 | /* First read mbox status word */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3554 | word0 = *((uint32_t *)phba->mbox); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | word0 = le32_to_cpu(word0); | 
|  | 3556 | } else { | 
|  | 3557 | /* First read mbox status word */ | 
|  | 3558 | word0 = readl(phba->MBslimaddr); | 
|  | 3559 | } | 
|  | 3560 |  | 
|  | 3561 | /* Read the HBA Host Attention Register */ | 
|  | 3562 | ha_copy = readl(phba->HAregaddr); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3563 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | 
|  | 3564 | mb->mbxCommand) * | 
|  | 3565 | 1000) + jiffies; | 
|  | 3566 | i = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3567 | /* Wait for command to complete */ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3568 | while (((word0 & OWN_CHIP) == OWN_CHIP) || | 
|  | 3569 | (!(ha_copy & HA_MBATT) && | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3570 | (phba->link_state > LPFC_WARM_START))) { | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3571 | if (time_after(jiffies, timeout)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3573 | spin_unlock_irqrestore(&phba->hbalock, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | drvr_flag); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3575 | goto out_not_finished; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | } | 
|  | 3577 |  | 
|  | 3578 | /* Check if we took a mbox interrupt while we were | 
|  | 3579 | polling */ | 
|  | 3580 | if (((word0 & OWN_CHIP) != OWN_CHIP) | 
|  | 3581 | && (evtctr != psli->slistat.mbox_event)) | 
|  | 3582 | break; | 
|  | 3583 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3584 | if (i++ > 10) { | 
|  | 3585 | spin_unlock_irqrestore(&phba->hbalock, | 
|  | 3586 | drvr_flag); | 
|  | 3587 | msleep(1); | 
|  | 3588 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | 
|  | 3589 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 |  | 
|  | 3591 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 
|  | 3592 | /* First copy command data */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3593 | word0 = *((uint32_t *)phba->mbox); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | word0 = le32_to_cpu(word0); | 
|  | 3595 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | 
|  | 3596 | MAILBOX_t *slimmb; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3597 | uint32_t slimword0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | /* Check real SLIM for any errors */ | 
|  | 3599 | slimword0 = readl(phba->MBslimaddr); | 
|  | 3600 | slimmb = (MAILBOX_t *) & slimword0; | 
|  | 3601 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | 
|  | 3602 | && slimmb->mbxStatus) { | 
|  | 3603 | psli->sli_flag &= | 
|  | 3604 | ~LPFC_SLI2_ACTIVE; | 
|  | 3605 | word0 = slimword0; | 
|  | 3606 | } | 
|  | 3607 | } | 
|  | 3608 | } else { | 
|  | 3609 | /* First copy command data */ | 
|  | 3610 | word0 = readl(phba->MBslimaddr); | 
|  | 3611 | } | 
|  | 3612 | /* Read the HBA Host Attention Register */ | 
|  | 3613 | ha_copy = readl(phba->HAregaddr); | 
|  | 3614 | } | 
|  | 3615 |  | 
|  | 3616 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3617 | /* copy results back to user */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3618 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | } else { | 
|  | 3620 | /* First copy command data */ | 
|  | 3621 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | 
|  | 3622 | MAILBOX_CMD_SIZE); | 
|  | 3623 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && | 
|  | 3624 | pmbox->context2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3625 | lpfc_memcpy_from_slim((void *)pmbox->context2, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3626 | phba->MBslimaddr + DMP_RSP_OFFSET, | 
|  | 3627 | mb->un.varDmp.word_cnt); | 
|  | 3628 | } | 
|  | 3629 | } | 
|  | 3630 |  | 
|  | 3631 | writel(HA_MBATT, phba->HAregaddr); | 
|  | 3632 | readl(phba->HAregaddr); /* flush */ | 
|  | 3633 |  | 
|  | 3634 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
|  | 3635 | status = mb->mbxStatus; | 
|  | 3636 | } | 
|  | 3637 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3638 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | 3639 | return status; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3640 |  | 
|  | 3641 | out_not_finished: | 
|  | 3642 | if (processing_queue) { | 
|  | 3643 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; | 
|  | 3644 | lpfc_mbox_cmpl_put(phba, pmbox); | 
|  | 3645 | } | 
|  | 3646 | return MBX_NOT_FINISHED; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | } | 
|  | 3648 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3649 | /** | 
|  | 3650 | * __lpfc_sli_ringtx_put: Add an iocb to the txq. | 
|  | 3651 | * @phba: Pointer to HBA context object. | 
|  | 3652 | * @pring: Pointer to driver SLI ring object. | 
|  | 3653 | * @piocb: Pointer to address of newly added command iocb. | 
|  | 3654 | * | 
|  | 3655 | * This function is called with hbalock held to add a command | 
|  | 3656 | * iocb to the txq when SLI layer cannot submit the command iocb | 
|  | 3657 | * to the ring. | 
|  | 3658 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3659 | static void | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3660 | __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] | 3661 | struct lpfc_iocbq *piocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | { | 
|  | 3663 | /* Insert the caller's iocb in the txq tail for later processing. */ | 
|  | 3664 | list_add_tail(&piocb->list, &pring->txq); | 
|  | 3665 | pring->txq_cnt++; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | } | 
|  | 3667 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3668 | /** | 
|  | 3669 | * lpfc_sli_next_iocb: Get the next iocb in the txq. | 
|  | 3670 | * @phba: Pointer to HBA context object. | 
|  | 3671 | * @pring: Pointer to driver SLI ring object. | 
|  | 3672 | * @piocb: Pointer to address of newly added command iocb. | 
|  | 3673 | * | 
|  | 3674 | * This function is called with hbalock held before a new | 
|  | 3675 | * iocb is submitted to the firmware. This function checks | 
|  | 3676 | * txq to flush the iocbs in txq to Firmware before | 
|  | 3677 | * submitting new iocbs to the Firmware. | 
|  | 3678 | * If there are iocbs in the txq which need to be submitted | 
|  | 3679 | * to firmware, lpfc_sli_next_iocb returns the first element | 
|  | 3680 | * of the txq after dequeuing it from txq. | 
|  | 3681 | * If there is no iocb in the txq then the function will return | 
|  | 3682 | * *piocb and *piocb is set to NULL. Caller needs to check | 
|  | 3683 | * *piocb to find if there are more commands in the txq. | 
|  | 3684 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | static struct lpfc_iocbq * | 
|  | 3686 | 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] | 3687 | struct lpfc_iocbq **piocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | { | 
|  | 3689 | struct lpfc_iocbq * nextiocb; | 
|  | 3690 |  | 
|  | 3691 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | 
|  | 3692 | if (!nextiocb) { | 
|  | 3693 | nextiocb = *piocb; | 
|  | 3694 | *piocb = NULL; | 
|  | 3695 | } | 
|  | 3696 |  | 
|  | 3697 | return nextiocb; | 
|  | 3698 | } | 
|  | 3699 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3700 | /** | 
|  | 3701 | * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb. | 
|  | 3702 | * @phba: Pointer to HBA context object. | 
|  | 3703 | * @pring: Pointer to driver SLI ring object. | 
|  | 3704 | * @piocb: Pointer to command iocb. | 
|  | 3705 | * @flag: Flag indicating if this command can be put into txq. | 
|  | 3706 | * | 
|  | 3707 | * __lpfc_sli_issue_iocb is used by other functions in the driver | 
|  | 3708 | * to issue an iocb command to the HBA. If the PCI slot is recovering | 
|  | 3709 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT | 
|  | 3710 | * flag is turned on, the function returns IOCB_ERROR. | 
|  | 3711 | * When the link is down, this function allows only iocbs for | 
|  | 3712 | * posting buffers. | 
|  | 3713 | * This function finds next available slot in the command ring and | 
|  | 3714 | * posts the command to the available slot and writes the port | 
|  | 3715 | * attention register to request HBA start processing new iocb. | 
|  | 3716 | * If there is no slot available in the ring and | 
|  | 3717 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the | 
|  | 3718 | * txq, otherwise the function returns IOCB_BUSY. | 
|  | 3719 | * | 
|  | 3720 | * This function is called with hbalock held. | 
|  | 3721 | * The function will return success after it successfully submit the | 
|  | 3722 | * iocb to firmware or after adding to the txq. | 
|  | 3723 | **/ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3724 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3725 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | struct lpfc_iocbq *piocb, uint32_t flag) | 
|  | 3727 | { | 
|  | 3728 | struct lpfc_iocbq *nextiocb; | 
|  | 3729 | IOCB_t *iocb; | 
|  | 3730 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3731 | if (piocb->iocb_cmpl && (!piocb->vport) && | 
|  | 3732 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | 
|  | 3733 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | 
|  | 3734 | lpfc_printf_log(phba, KERN_ERR, | 
|  | 3735 | LOG_SLI | LOG_VPORT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3736 | "1807 IOCB x%x failed. No vport\n", | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3737 | piocb->iocb.ulpCommand); | 
|  | 3738 | dump_stack(); | 
|  | 3739 | return IOCB_ERROR; | 
|  | 3740 | } | 
|  | 3741 |  | 
|  | 3742 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3743 | /* If the PCI channel is in offline state, do not post iocbs. */ | 
|  | 3744 | if (unlikely(pci_channel_offline(phba->pcidev))) | 
|  | 3745 | return IOCB_ERROR; | 
|  | 3746 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | /* | 
|  | 3748 | * We should never get an IOCB if we are in a < LINK_DOWN state | 
|  | 3749 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3750 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | return IOCB_ERROR; | 
|  | 3752 |  | 
|  | 3753 | /* | 
|  | 3754 | * Check to see if we are blocking IOCB processing because of a | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3755 | * outstanding event. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | */ | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3757 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | goto iocb_busy; | 
|  | 3759 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3760 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | /* | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3762 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | * can be issued if the link is not up. | 
|  | 3764 | */ | 
|  | 3765 | switch (piocb->iocb.ulpCommand) { | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3766 | case CMD_GEN_REQUEST64_CR: | 
|  | 3767 | case CMD_GEN_REQUEST64_CX: | 
|  | 3768 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | 
|  | 3769 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | 
|  | 3770 | FC_FCP_CMND) || | 
|  | 3771 | (piocb->iocb.un.genreq64.w5.hcsw.Type != | 
|  | 3772 | MENLO_TRANSPORT_TYPE)) | 
|  | 3773 |  | 
|  | 3774 | goto iocb_busy; | 
|  | 3775 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | case CMD_QUE_RING_BUF_CN: | 
|  | 3777 | case CMD_QUE_RING_BUF64_CN: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | /* | 
|  | 3779 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | 
|  | 3780 | * completion, iocb_cmpl MUST be 0. | 
|  | 3781 | */ | 
|  | 3782 | if (piocb->iocb_cmpl) | 
|  | 3783 | piocb->iocb_cmpl = NULL; | 
|  | 3784 | /*FALLTHROUGH*/ | 
|  | 3785 | case CMD_CREATE_XRI_CR: | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3786 | case CMD_CLOSE_XRI_CN: | 
|  | 3787 | case CMD_CLOSE_XRI_CX: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | break; | 
|  | 3789 | default: | 
|  | 3790 | goto iocb_busy; | 
|  | 3791 | } | 
|  | 3792 |  | 
|  | 3793 | /* | 
|  | 3794 | * For FCP commands, we must be in a state where we can process link | 
|  | 3795 | * attention events. | 
|  | 3796 | */ | 
|  | 3797 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3798 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | goto iocb_busy; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3800 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | 
|  | 3803 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | 
|  | 3804 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | 
|  | 3805 |  | 
|  | 3806 | if (iocb) | 
|  | 3807 | lpfc_sli_update_ring(phba, pring); | 
|  | 3808 | else | 
|  | 3809 | lpfc_sli_update_full_ring(phba, pring); | 
|  | 3810 |  | 
|  | 3811 | if (!piocb) | 
|  | 3812 | return IOCB_SUCCESS; | 
|  | 3813 |  | 
|  | 3814 | goto out_busy; | 
|  | 3815 |  | 
|  | 3816 | iocb_busy: | 
|  | 3817 | pring->stats.iocb_cmd_delay++; | 
|  | 3818 |  | 
|  | 3819 | out_busy: | 
|  | 3820 |  | 
|  | 3821 | if (!(flag & SLI_IOCB_RET_IOCB)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3822 | __lpfc_sli_ringtx_put(phba, pring, piocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | return IOCB_SUCCESS; | 
|  | 3824 | } | 
|  | 3825 |  | 
|  | 3826 | return IOCB_BUSY; | 
|  | 3827 | } | 
|  | 3828 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3829 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3830 | /** | 
|  | 3831 | * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb. | 
|  | 3832 | * @phba: Pointer to HBA context object. | 
|  | 3833 | * @pring: Pointer to driver SLI ring object. | 
|  | 3834 | * @piocb: Pointer to command iocb. | 
|  | 3835 | * @flag: Flag indicating if this command can be put into txq. | 
|  | 3836 | * | 
|  | 3837 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | 
|  | 3838 | * function. This function gets the hbalock and calls | 
|  | 3839 | * __lpfc_sli_issue_iocb function and will return the error returned | 
|  | 3840 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | 
|  | 3841 | * functions which do not hold hbalock. | 
|  | 3842 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3843 | int | 
|  | 3844 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 3845 | struct lpfc_iocbq *piocb, uint32_t flag) | 
|  | 3846 | { | 
|  | 3847 | unsigned long iflags; | 
|  | 3848 | int rc; | 
|  | 3849 |  | 
|  | 3850 | spin_lock_irqsave(&phba->hbalock, iflags); | 
|  | 3851 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); | 
|  | 3852 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 3853 |  | 
|  | 3854 | return rc; | 
|  | 3855 | } | 
|  | 3856 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3857 | /** | 
|  | 3858 | * lpfc_extra_ring_setup: Extra ring setup function. | 
|  | 3859 | * @phba: Pointer to HBA context object. | 
|  | 3860 | * | 
|  | 3861 | * This function is called while driver attaches with the | 
|  | 3862 | * HBA to setup the extra ring. The extra ring is used | 
|  | 3863 | * only when driver needs to support target mode functionality | 
|  | 3864 | * or IP over FC functionalities. | 
|  | 3865 | * | 
|  | 3866 | * This function is called with no lock held. | 
|  | 3867 | **/ | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3868 | static int | 
|  | 3869 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | 
|  | 3870 | { | 
|  | 3871 | struct lpfc_sli *psli; | 
|  | 3872 | struct lpfc_sli_ring *pring; | 
|  | 3873 |  | 
|  | 3874 | psli = &phba->sli; | 
|  | 3875 |  | 
|  | 3876 | /* Adjust cmd/rsp ring iocb entries more evenly */ | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3877 |  | 
|  | 3878 | /* Take some away from the FCP ring */ | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3879 | pring = &psli->ring[psli->fcp_ring]; | 
|  | 3880 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | 
|  | 3881 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | 
|  | 3882 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | 
|  | 3883 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | 
|  | 3884 |  | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3885 | /* and give them to the extra ring */ | 
|  | 3886 | pring = &psli->ring[psli->extra_ring]; | 
|  | 3887 |  | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3888 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | 
|  | 3889 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | 
|  | 3890 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | 
|  | 3891 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | 
|  | 3892 |  | 
|  | 3893 | /* Setup default profile for this ring */ | 
|  | 3894 | pring->iotag_max = 4096; | 
|  | 3895 | pring->num_mask = 1; | 
|  | 3896 | pring->prt[0].profile = 0;      /* Mask 0 */ | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3897 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; | 
|  | 3898 | pring->prt[0].type = phba->cfg_multi_ring_type; | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3899 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; | 
|  | 3900 | return 0; | 
|  | 3901 | } | 
|  | 3902 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3903 | /** | 
|  | 3904 | * lpfc_sli_async_event_handler: ASYNC iocb handler function. | 
|  | 3905 | * @phba: Pointer to HBA context object. | 
|  | 3906 | * @pring: Pointer to driver SLI ring object. | 
|  | 3907 | * @iocbq: Pointer to iocb object. | 
|  | 3908 | * | 
|  | 3909 | * This function is called by the slow ring event handler | 
|  | 3910 | * function when there is an ASYNC event iocb in the ring. | 
|  | 3911 | * This function is called with no lock held. | 
|  | 3912 | * Currently this function handles only temperature related | 
|  | 3913 | * ASYNC events. The function decodes the temperature sensor | 
|  | 3914 | * event message and posts events for the management applications. | 
|  | 3915 | **/ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3916 | static void | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3917 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, | 
|  | 3918 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | 
|  | 3919 | { | 
|  | 3920 | IOCB_t *icmd; | 
|  | 3921 | uint16_t evt_code; | 
|  | 3922 | uint16_t temp; | 
|  | 3923 | struct temp_event temp_event_data; | 
|  | 3924 | struct Scsi_Host *shost; | 
|  | 3925 |  | 
|  | 3926 | icmd = &iocbq->iocb; | 
|  | 3927 | evt_code = icmd->un.asyncstat.evt_code; | 
|  | 3928 | temp = icmd->ulpContext; | 
|  | 3929 |  | 
|  | 3930 | if ((evt_code != ASYNC_TEMP_WARN) && | 
|  | 3931 | (evt_code != ASYNC_TEMP_SAFE)) { | 
|  | 3932 | lpfc_printf_log(phba, | 
|  | 3933 | KERN_ERR, | 
|  | 3934 | LOG_SLI, | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3935 | "0346 Ring %d handler: unexpected ASYNC_STATUS" | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3936 | " evt_code 0x%x\n", | 
|  | 3937 | pring->ringno, | 
|  | 3938 | icmd->un.asyncstat.evt_code); | 
|  | 3939 | return; | 
|  | 3940 | } | 
|  | 3941 | temp_event_data.data = (uint32_t)temp; | 
|  | 3942 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | 
|  | 3943 | if (evt_code == ASYNC_TEMP_WARN) { | 
|  | 3944 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | 
|  | 3945 | lpfc_printf_log(phba, | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3946 | KERN_ERR, | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3947 | LOG_TEMP, | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3948 | "0347 Adapter is very hot, please take " | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3949 | "corrective action. temperature : %d Celsius\n", | 
|  | 3950 | temp); | 
|  | 3951 | } | 
|  | 3952 | if (evt_code == ASYNC_TEMP_SAFE) { | 
|  | 3953 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | 
|  | 3954 | lpfc_printf_log(phba, | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3955 | KERN_ERR, | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3956 | LOG_TEMP, | 
|  | 3957 | "0340 Adapter temperature is OK now. " | 
|  | 3958 | "temperature : %d Celsius\n", | 
|  | 3959 | temp); | 
|  | 3960 | } | 
|  | 3961 |  | 
|  | 3962 | /* Send temperature change event to applications */ | 
|  | 3963 | shost = lpfc_shost_from_vport(phba->pport); | 
|  | 3964 | fc_host_post_vendor_event(shost, fc_get_event_number(), | 
|  | 3965 | sizeof(temp_event_data), (char *) &temp_event_data, | 
|  | 3966 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | 
|  | 3967 |  | 
|  | 3968 | } | 
|  | 3969 |  | 
|  | 3970 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3971 | /** | 
|  | 3972 | * lpfc_sli_setup: SLI ring setup function. | 
|  | 3973 | * @phba: Pointer to HBA context object. | 
|  | 3974 | * | 
|  | 3975 | * lpfc_sli_setup sets up rings of the SLI interface with | 
|  | 3976 | * number of iocbs per ring and iotags. This function is | 
|  | 3977 | * called while driver attach to the HBA and before the | 
|  | 3978 | * interrupts are enabled. So there is no need for locking. | 
|  | 3979 | * | 
|  | 3980 | * This function always returns 0. | 
|  | 3981 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | int | 
|  | 3983 | lpfc_sli_setup(struct lpfc_hba *phba) | 
|  | 3984 | { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3985 | int i, totiocbsize = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | struct lpfc_sli *psli = &phba->sli; | 
|  | 3987 | struct lpfc_sli_ring *pring; | 
|  | 3988 |  | 
|  | 3989 | psli->num_rings = MAX_CONFIGURED_RINGS; | 
|  | 3990 | psli->sli_flag = 0; | 
|  | 3991 | psli->fcp_ring = LPFC_FCP_RING; | 
|  | 3992 | psli->next_ring = LPFC_FCP_NEXT_RING; | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3993 | psli->extra_ring = LPFC_EXTRA_RING; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 |  | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3995 | psli->iocbq_lookup = NULL; | 
|  | 3996 | psli->iocbq_lookup_len = 0; | 
|  | 3997 | psli->last_iotag = 0; | 
|  | 3998 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 4000 | pring = &psli->ring[i]; | 
|  | 4001 | switch (i) { | 
|  | 4002 | case LPFC_FCP_RING:	/* ring 0 - FCP */ | 
|  | 4003 | /* numCiocb and numRiocb are used in config_port */ | 
|  | 4004 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | 
|  | 4005 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | 
|  | 4006 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | 
|  | 4007 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | 
|  | 4008 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | 
|  | 4009 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4010 | pring->sizeCiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4011 | SLI3_IOCB_CMD_SIZE : | 
|  | 4012 | SLI2_IOCB_CMD_SIZE; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4013 | pring->sizeRiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4014 | SLI3_IOCB_RSP_SIZE : | 
|  | 4015 | SLI2_IOCB_RSP_SIZE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | pring->iotag_ctr = 0; | 
|  | 4017 | pring->iotag_max = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4018 | (phba->cfg_hba_queue_depth * 2); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4019 | pring->fast_iotag = pring->iotag_max; | 
|  | 4020 | pring->num_mask = 0; | 
|  | 4021 | break; | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4022 | case LPFC_EXTRA_RING:	/* ring 1 - EXTRA */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | /* numCiocb and numRiocb are used in config_port */ | 
|  | 4024 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | 
|  | 4025 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4026 | pring->sizeCiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4027 | SLI3_IOCB_CMD_SIZE : | 
|  | 4028 | SLI2_IOCB_CMD_SIZE; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4029 | pring->sizeRiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4030 | SLI3_IOCB_RSP_SIZE : | 
|  | 4031 | SLI2_IOCB_RSP_SIZE; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4032 | pring->iotag_max = phba->cfg_hba_queue_depth; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | pring->num_mask = 0; | 
|  | 4034 | break; | 
|  | 4035 | case LPFC_ELS_RING:	/* ring 2 - ELS / CT */ | 
|  | 4036 | /* numCiocb and numRiocb are used in config_port */ | 
|  | 4037 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | 
|  | 4038 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4039 | pring->sizeCiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4040 | SLI3_IOCB_CMD_SIZE : | 
|  | 4041 | SLI2_IOCB_CMD_SIZE; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4042 | pring->sizeRiocb = (phba->sli_rev == 3) ? | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4043 | SLI3_IOCB_RSP_SIZE : | 
|  | 4044 | SLI2_IOCB_RSP_SIZE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | pring->fast_iotag = 0; | 
|  | 4046 | pring->iotag_ctr = 0; | 
|  | 4047 | pring->iotag_max = 4096; | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4048 | pring->lpfc_sli_rcv_async_status = | 
|  | 4049 | lpfc_sli_async_event_handler; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | pring->num_mask = 4; | 
|  | 4051 | pring->prt[0].profile = 0;	/* Mask 0 */ | 
|  | 4052 | pring->prt[0].rctl = FC_ELS_REQ; | 
|  | 4053 | pring->prt[0].type = FC_ELS_DATA; | 
|  | 4054 | pring->prt[0].lpfc_sli_rcv_unsol_event = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4055 | lpfc_els_unsol_event; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | pring->prt[1].profile = 0;	/* Mask 1 */ | 
|  | 4057 | pring->prt[1].rctl = FC_ELS_RSP; | 
|  | 4058 | pring->prt[1].type = FC_ELS_DATA; | 
|  | 4059 | pring->prt[1].lpfc_sli_rcv_unsol_event = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | lpfc_els_unsol_event; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 | pring->prt[2].profile = 0;	/* Mask 2 */ | 
|  | 4062 | /* NameServer Inquiry */ | 
|  | 4063 | pring->prt[2].rctl = FC_UNSOL_CTL; | 
|  | 4064 | /* NameServer */ | 
|  | 4065 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; | 
|  | 4066 | pring->prt[2].lpfc_sli_rcv_unsol_event = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4067 | lpfc_ct_unsol_event; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | pring->prt[3].profile = 0;	/* Mask 3 */ | 
|  | 4069 | /* NameServer response */ | 
|  | 4070 | pring->prt[3].rctl = FC_SOL_CTL; | 
|  | 4071 | /* NameServer */ | 
|  | 4072 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; | 
|  | 4073 | pring->prt[3].lpfc_sli_rcv_unsol_event = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4074 | lpfc_ct_unsol_event; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | break; | 
|  | 4076 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4077 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4078 | (pring->numRiocb * pring->sizeRiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4080 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4082 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " | 
|  | 4083 | "SLI2 SLIM Data: x%x x%lx\n", | 
|  | 4084 | phba->brd_no, totiocbsize, | 
|  | 4085 | (unsigned long) MAX_SLIM_IOCB_SIZE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | } | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4087 | if (phba->cfg_multi_ring_support == 2) | 
|  | 4088 | lpfc_extra_ring_setup(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 |  | 
|  | 4090 | return 0; | 
|  | 4091 | } | 
|  | 4092 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4093 | /** | 
|  | 4094 | * lpfc_sli_queue_setup: Queue initialization function. | 
|  | 4095 | * @phba: Pointer to HBA context object. | 
|  | 4096 | * | 
|  | 4097 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | 
|  | 4098 | * ring. This function also initializes ring indices of each ring. | 
|  | 4099 | * This function is called during the initialization of the SLI | 
|  | 4100 | * interface of an HBA. | 
|  | 4101 | * This function is called with no lock held and always returns | 
|  | 4102 | * 1. | 
|  | 4103 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4105 | lpfc_sli_queue_setup(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | { | 
|  | 4107 | struct lpfc_sli *psli; | 
|  | 4108 | struct lpfc_sli_ring *pring; | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4109 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 |  | 
|  | 4111 | psli = &phba->sli; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4112 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | INIT_LIST_HEAD(&psli->mboxq); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4114 | INIT_LIST_HEAD(&psli->mboxq_cmpl); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | /* Initialize list headers for txq and txcmplq as double linked lists */ | 
|  | 4116 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 4117 | pring = &psli->ring[i]; | 
|  | 4118 | pring->ringno = i; | 
|  | 4119 | pring->next_cmdidx  = 0; | 
|  | 4120 | pring->local_getidx = 0; | 
|  | 4121 | pring->cmdidx = 0; | 
|  | 4122 | INIT_LIST_HEAD(&pring->txq); | 
|  | 4123 | INIT_LIST_HEAD(&pring->txcmplq); | 
|  | 4124 | INIT_LIST_HEAD(&pring->iocb_continueq); | 
| James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4125 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | INIT_LIST_HEAD(&pring->postbufq); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | spin_unlock_irq(&phba->hbalock); | 
|  | 4129 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | } | 
|  | 4131 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4132 | /** | 
|  | 4133 | * lpfc_sli_host_down: Vport cleanup function. | 
|  | 4134 | * @vport: Pointer to virtual port object. | 
|  | 4135 | * | 
|  | 4136 | * lpfc_sli_host_down is called to clean up the resources | 
|  | 4137 | * associated with a vport before destroying virtual | 
|  | 4138 | * port data structures. | 
|  | 4139 | * This function does following operations: | 
|  | 4140 | * - Free discovery resources associated with this virtual | 
|  | 4141 | *   port. | 
|  | 4142 | * - Free iocbs associated with this virtual port in | 
|  | 4143 | *   the txq. | 
|  | 4144 | * - Send abort for all iocb commands associated with this | 
|  | 4145 | *   vport in txcmplq. | 
|  | 4146 | * | 
|  | 4147 | * This function is called with no lock held and always returns 1. | 
|  | 4148 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4150 | lpfc_sli_host_down(struct lpfc_vport *vport) | 
|  | 4151 | { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4152 | LIST_HEAD(completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4153 | struct lpfc_hba *phba = vport->phba; | 
|  | 4154 | struct lpfc_sli *psli = &phba->sli; | 
|  | 4155 | struct lpfc_sli_ring *pring; | 
|  | 4156 | struct lpfc_iocbq *iocb, *next_iocb; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4157 | int i; | 
|  | 4158 | unsigned long flags = 0; | 
|  | 4159 | uint16_t prev_pring_flag; | 
|  | 4160 |  | 
|  | 4161 | lpfc_cleanup_discovery_resources(vport); | 
|  | 4162 |  | 
|  | 4163 | spin_lock_irqsave(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4164 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 4165 | pring = &psli->ring[i]; | 
|  | 4166 | prev_pring_flag = pring->flag; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4167 | /* Only slow rings */ | 
|  | 4168 | if (pring->ringno == LPFC_ELS_RING) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4169 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4170 | /* Set the lpfc data pending flag */ | 
|  | 4171 | set_bit(LPFC_DATA_READY, &phba->data_flags); | 
|  | 4172 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4173 | /* | 
|  | 4174 | * Error everything on the txq since these iocbs have not been | 
|  | 4175 | * given to the FW yet. | 
|  | 4176 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4177 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { | 
|  | 4178 | if (iocb->vport != vport) | 
|  | 4179 | continue; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4180 | list_move_tail(&iocb->list, &completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4181 | pring->txq_cnt--; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4182 | } | 
|  | 4183 |  | 
|  | 4184 | /* Next issue ABTS for everything on the txcmplq */ | 
|  | 4185 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | 
|  | 4186 | list) { | 
|  | 4187 | if (iocb->vport != vport) | 
|  | 4188 | continue; | 
|  | 4189 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | 
|  | 4190 | } | 
|  | 4191 |  | 
|  | 4192 | pring->flag = prev_pring_flag; | 
|  | 4193 | } | 
|  | 4194 |  | 
|  | 4195 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | 4196 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4197 | while (!list_empty(&completions)) { | 
|  | 4198 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); | 
|  | 4199 |  | 
|  | 4200 | if (!iocb->iocb_cmpl) | 
|  | 4201 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 4202 | else { | 
|  | 4203 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 4204 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; | 
|  | 4205 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
|  | 4206 | } | 
|  | 4207 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4208 | return 1; | 
|  | 4209 | } | 
|  | 4210 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4211 | /** | 
|  | 4212 | * lpfc_sli_hba_down: Resource cleanup function for the HBA. | 
|  | 4213 | * @phba: Pointer to HBA context object. | 
|  | 4214 | * | 
|  | 4215 | * This function cleans up all iocb, buffers, mailbox commands | 
|  | 4216 | * while shutting down the HBA. This function is called with no | 
|  | 4217 | * lock held and always returns 1. | 
|  | 4218 | * This function does the following to cleanup driver resources: | 
|  | 4219 | * - Free discovery resources for each virtual port | 
|  | 4220 | * - Cleanup any pending fabric iocbs | 
|  | 4221 | * - Iterate through the iocb txq and free each entry | 
|  | 4222 | *   in the list. | 
|  | 4223 | * - Free up any buffer posted to the HBA | 
|  | 4224 | * - Free mailbox commands in the mailbox queue. | 
|  | 4225 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4226 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | lpfc_sli_hba_down(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | { | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4229 | LIST_HEAD(completions); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4230 | struct lpfc_sli *psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | struct lpfc_sli_ring *pring; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4232 | struct lpfc_dmabuf *buf_ptr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | LPFC_MBOXQ_t *pmb; | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4234 | struct lpfc_iocbq *iocb; | 
|  | 4235 | IOCB_t *cmd = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | int i; | 
|  | 4237 | unsigned long flags = 0; | 
|  | 4238 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4239 | lpfc_hba_down_prep(phba); | 
|  | 4240 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4241 | lpfc_fabric_abort_hba(phba); | 
|  | 4242 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | spin_lock_irqsave(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 4245 | pring = &psli->ring[i]; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4246 | /* Only slow rings */ | 
|  | 4247 | if (pring->ringno == LPFC_ELS_RING) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4248 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4249 | /* Set the lpfc data pending flag */ | 
|  | 4250 | set_bit(LPFC_DATA_READY, &phba->data_flags); | 
|  | 4251 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 |  | 
|  | 4253 | /* | 
|  | 4254 | * Error everything on the txq since these iocbs have not been | 
|  | 4255 | * given to the FW yet. | 
|  | 4256 | */ | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4257 | list_splice_init(&pring->txq, &completions); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | pring->txq_cnt = 0; | 
|  | 4259 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 |  | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4263 | while (!list_empty(&completions)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4264 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4265 | cmd = &iocb->iocb; | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4266 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4267 | if (!iocb->iocb_cmpl) | 
|  | 4268 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 4269 | else { | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4270 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 4271 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; | 
|  | 4272 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | } | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4274 | } | 
|  | 4275 |  | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4276 | spin_lock_irqsave(&phba->hbalock, flags); | 
|  | 4277 | list_splice_init(&phba->elsbuf, &completions); | 
|  | 4278 | phba->elsbuf_cnt = 0; | 
|  | 4279 | phba->elsbuf_prev_cnt = 0; | 
|  | 4280 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | 4281 |  | 
|  | 4282 | while (!list_empty(&completions)) { | 
|  | 4283 | list_remove_head(&completions, buf_ptr, | 
|  | 4284 | struct lpfc_dmabuf, list); | 
|  | 4285 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 4286 | kfree(buf_ptr); | 
|  | 4287 | } | 
|  | 4288 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | /* Return any active mbox cmds */ | 
|  | 4290 | del_timer_sync(&psli->mbox_tmo); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4291 | spin_lock_irqsave(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4292 |  | 
|  | 4293 | spin_lock(&phba->pport->work_port_lock); | 
|  | 4294 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | 
|  | 4295 | spin_unlock(&phba->pport->work_port_lock); | 
|  | 4296 |  | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4297 | /* Return any pending or completed mbox cmds */ | 
|  | 4298 | list_splice_init(&phba->sli.mboxq, &completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4299 | if (psli->mbox_active) { | 
|  | 4300 | list_add_tail(&psli->mbox_active->list, &completions); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | psli->mbox_active = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4302 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4304 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4305 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | 4306 |  | 
|  | 4307 | while (!list_empty(&completions)) { | 
|  | 4308 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4310 | if (pmb->mbox_cmpl) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | pmb->mbox_cmpl(phba,pmb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | return 1; | 
|  | 4314 | } | 
|  | 4315 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4316 | /** | 
|  | 4317 | * lpfc_sli_pcimem_bcopy: SLI memory copy function. | 
|  | 4318 | * @srcp: Source memory pointer. | 
|  | 4319 | * @destp: Destination memory pointer. | 
|  | 4320 | * @cnt: Number of words required to be copied. | 
|  | 4321 | * | 
|  | 4322 | * This function is used for copying data between driver memory | 
|  | 4323 | * and the SLI memory. This function also changes the endianness | 
|  | 4324 | * of each word if native endianness is different from SLI | 
|  | 4325 | * endianness. This function can be called with or without | 
|  | 4326 | * lock. | 
|  | 4327 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | void | 
|  | 4329 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | 
|  | 4330 | { | 
|  | 4331 | uint32_t *src = srcp; | 
|  | 4332 | uint32_t *dest = destp; | 
|  | 4333 | uint32_t ldata; | 
|  | 4334 | int i; | 
|  | 4335 |  | 
|  | 4336 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | 
|  | 4337 | ldata = *src; | 
|  | 4338 | ldata = le32_to_cpu(ldata); | 
|  | 4339 | *dest = ldata; | 
|  | 4340 | src++; | 
|  | 4341 | dest++; | 
|  | 4342 | } | 
|  | 4343 | } | 
|  | 4344 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4345 |  | 
|  | 4346 | /** | 
|  | 4347 | * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq. | 
|  | 4348 | * @phba: Pointer to HBA context object. | 
|  | 4349 | * @pring: Pointer to driver SLI ring object. | 
|  | 4350 | * @mp: Pointer to driver buffer object. | 
|  | 4351 | * | 
|  | 4352 | * This function is called with no lock held. | 
|  | 4353 | * It always return zero after adding the buffer to the postbufq | 
|  | 4354 | * buffer list. | 
|  | 4355 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 4358 | struct lpfc_dmabuf *mp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | { | 
|  | 4360 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | 
|  | 4361 | later */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | list_add_tail(&mp->list, &pring->postbufq); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | pring->postbufq_cnt++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4365 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | return 0; | 
|  | 4367 | } | 
|  | 4368 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4369 | /** | 
|  | 4370 | * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted | 
|  | 4371 | *          using CMD_QUE_XRI64_CX iocb. | 
|  | 4372 | * @phba: Pointer to HBA context object. | 
|  | 4373 | * | 
|  | 4374 | * When HBQ is enabled, buffers are searched based on tags. This function | 
|  | 4375 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | 
|  | 4376 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | 
|  | 4377 | * does not conflict with tags of buffer posted for unsolicited events. | 
|  | 4378 | * The function returns the allocated tag. The function is called with | 
|  | 4379 | * no locks held. | 
|  | 4380 | **/ | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4381 | uint32_t | 
|  | 4382 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | 
|  | 4383 | { | 
|  | 4384 | spin_lock_irq(&phba->hbalock); | 
|  | 4385 | phba->buffer_tag_count++; | 
|  | 4386 | /* | 
|  | 4387 | * Always set the QUE_BUFTAG_BIT to distiguish between | 
|  | 4388 | * a tag assigned by HBQ. | 
|  | 4389 | */ | 
|  | 4390 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | 
|  | 4391 | spin_unlock_irq(&phba->hbalock); | 
|  | 4392 | return phba->buffer_tag_count; | 
|  | 4393 | } | 
|  | 4394 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4395 | /** | 
|  | 4396 | * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with | 
|  | 4397 | *              posted using CMD_QUE_XRI64_CX iocb. | 
|  | 4398 | * @phba: Pointer to HBA context object. | 
|  | 4399 | * @pring: Pointer to driver SLI ring object. | 
|  | 4400 | * @tag: Buffer tag. | 
|  | 4401 | * | 
|  | 4402 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | 
|  | 4403 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | 
|  | 4404 | * iocb is posted to the response ring with the tag of the buffer. | 
|  | 4405 | * This function searches the pring->postbufq list using the tag | 
|  | 4406 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | 
|  | 4407 | * iocb. If the buffer is found then lpfc_dmabuf object of the | 
|  | 4408 | * buffer is returned to the caller else NULL is returned. | 
|  | 4409 | * This function is called with no lock held. | 
|  | 4410 | **/ | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4411 | struct lpfc_dmabuf * | 
|  | 4412 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 4413 | uint32_t tag) | 
|  | 4414 | { | 
|  | 4415 | struct lpfc_dmabuf *mp, *next_mp; | 
|  | 4416 | struct list_head *slp = &pring->postbufq; | 
|  | 4417 |  | 
|  | 4418 | /* Search postbufq, from the begining, looking for a match on tag */ | 
|  | 4419 | spin_lock_irq(&phba->hbalock); | 
|  | 4420 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | 
|  | 4421 | if (mp->buffer_tag == tag) { | 
|  | 4422 | list_del_init(&mp->list); | 
|  | 4423 | pring->postbufq_cnt--; | 
|  | 4424 | spin_unlock_irq(&phba->hbalock); | 
|  | 4425 | return mp; | 
|  | 4426 | } | 
|  | 4427 | } | 
|  | 4428 |  | 
|  | 4429 | spin_unlock_irq(&phba->hbalock); | 
|  | 4430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4431 | "0402 Cannot find virtual addr for buffer tag on " | 
| James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4432 | "ring %d Data x%lx x%p x%p x%x\n", | 
|  | 4433 | pring->ringno, (unsigned long) tag, | 
|  | 4434 | slp->next, slp->prev, pring->postbufq_cnt); | 
|  | 4435 |  | 
|  | 4436 | return NULL; | 
|  | 4437 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4439 | /** | 
|  | 4440 | * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for | 
|  | 4441 | *      unsolicited ct and els events. | 
|  | 4442 | * @phba: Pointer to HBA context object. | 
|  | 4443 | * @pring: Pointer to driver SLI ring object. | 
|  | 4444 | * @phys: DMA address of the buffer. | 
|  | 4445 | * | 
|  | 4446 | * This function searches the buffer list using the dma_address | 
|  | 4447 | * of unsolicited event to find the driver's lpfc_dmabuf object | 
|  | 4448 | * corresponding to the dma_address. The function returns the | 
|  | 4449 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | 
|  | 4450 | * This function is called by the ct and els unsolicited event | 
|  | 4451 | * handlers to get the buffer associated with the unsolicited | 
|  | 4452 | * event. | 
|  | 4453 | * | 
|  | 4454 | * This function is called with no lock held. | 
|  | 4455 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | struct lpfc_dmabuf * | 
|  | 4457 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 4458 | dma_addr_t phys) | 
|  | 4459 | { | 
|  | 4460 | struct lpfc_dmabuf *mp, *next_mp; | 
|  | 4461 | struct list_head *slp = &pring->postbufq; | 
|  | 4462 |  | 
|  | 4463 | /* Search postbufq, from the begining, looking for a match on phys */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4464 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | 
|  | 4466 | if (mp->phys == phys) { | 
|  | 4467 | list_del_init(&mp->list); | 
|  | 4468 | pring->postbufq_cnt--; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4469 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | return mp; | 
|  | 4471 | } | 
|  | 4472 | } | 
|  | 4473 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4474 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4476 | "0410 Cannot find virtual addr for mapped buf on " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | "ring %d Data x%llx x%p x%p x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4478 | pring->ringno, (unsigned long long)phys, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | slp->next, slp->prev, pring->postbufq_cnt); | 
|  | 4480 | return NULL; | 
|  | 4481 | } | 
|  | 4482 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4483 | /** | 
|  | 4484 | * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs. | 
|  | 4485 | * @phba: Pointer to HBA context object. | 
|  | 4486 | * @cmdiocb: Pointer to driver command iocb object. | 
|  | 4487 | * @rspiocb: Pointer to driver response iocb object. | 
|  | 4488 | * | 
|  | 4489 | * This function is the completion handler for the abort iocbs for | 
|  | 4490 | * ELS commands. This function is called from the ELS ring event | 
|  | 4491 | * handler with no lock held. This function frees memory resources | 
|  | 4492 | * associated with the abort iocb. | 
|  | 4493 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4494 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4495 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 4496 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | IOCB_t *irsp = &rspiocb->iocb; | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4499 | uint16_t abort_iotag, abort_context; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4500 | struct lpfc_iocbq *abort_iocb; | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4501 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 4502 |  | 
|  | 4503 | abort_iocb = NULL; | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4504 |  | 
|  | 4505 | if (irsp->ulpStatus) { | 
|  | 4506 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | 
|  | 4507 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | 
|  | 4508 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4509 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4510 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) | 
|  | 4511 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; | 
|  | 4512 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4513 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4514 | "0327 Cannot abort els iocb %p " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4515 | "with tag %x context %x, abort status %x, " | 
|  | 4516 | "abort code %x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4517 | abort_iocb, abort_iotag, abort_context, | 
|  | 4518 | irsp->ulpStatus, irsp->un.ulpWord[4]); | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4519 |  | 
|  | 4520 | /* | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4521 | *  If the iocb is not found in Firmware queue the iocb | 
|  | 4522 | *  might have completed already. Do not free it again. | 
|  | 4523 | */ | 
| James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4524 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4525 | spin_unlock_irq(&phba->hbalock); | 
|  | 4526 | lpfc_sli_release_iocbq(phba, cmdiocb); | 
|  | 4527 | return; | 
|  | 4528 | } | 
|  | 4529 | /* | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4530 | * make sure we have the right iocbq before taking it | 
|  | 4531 | * off the txcmplq and try to call completion routine. | 
|  | 4532 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | if (!abort_iocb || | 
|  | 4534 | abort_iocb->iocb.ulpContext != abort_context || | 
|  | 4535 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | 
|  | 4536 | spin_unlock_irq(&phba->hbalock); | 
|  | 4537 | else { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4538 | list_del_init(&abort_iocb->list); | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4539 | pring->txcmplq_cnt--; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4541 |  | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4542 | /* Firmware could still be in progress of DMAing | 
|  | 4543 | * payload, so don't free data buffer till after | 
|  | 4544 | * a hbeat. | 
|  | 4545 | */ | 
|  | 4546 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | 
|  | 4547 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4548 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; | 
|  | 4549 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 4550 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; | 
|  | 4551 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4552 | } | 
|  | 4553 | } | 
|  | 4554 |  | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4555 | lpfc_sli_release_iocbq(phba, cmdiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | return; | 
|  | 4557 | } | 
|  | 4558 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4559 | /** | 
|  | 4560 | * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command. | 
|  | 4561 | * @phba: Pointer to HBA context object. | 
|  | 4562 | * @cmdiocb: Pointer to driver command iocb object. | 
|  | 4563 | * @rspiocb: Pointer to driver response iocb object. | 
|  | 4564 | * | 
|  | 4565 | * The function is called from SLI ring event handler with no | 
|  | 4566 | * lock held. This function is the completion handler for ELS commands | 
|  | 4567 | * which are aborted. The function frees memory resources used for | 
|  | 4568 | * the aborted ELS commands. | 
|  | 4569 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4570 | static void | 
|  | 4571 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 4572 | struct lpfc_iocbq *rspiocb) | 
|  | 4573 | { | 
|  | 4574 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 4575 |  | 
|  | 4576 | /* ELS cmd tag <ulpIoTag> completes */ | 
|  | 4577 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4578 | "0139 Ignoring ELS cmd tag x%x completion Data: " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4579 | "x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4580 | irsp->ulpIoTag, irsp->ulpStatus, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4581 | irsp->un.ulpWord[4], irsp->ulpTimeout); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4582 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) | 
|  | 4583 | lpfc_ct_free_iocb(phba, cmdiocb); | 
|  | 4584 | else | 
|  | 4585 | lpfc_els_free_iocb(phba, cmdiocb); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4586 | return; | 
|  | 4587 | } | 
|  | 4588 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4589 | /** | 
|  | 4590 | * lpfc_sli_issue_abort_iotag: Abort function for a command iocb. | 
|  | 4591 | * @phba: Pointer to HBA context object. | 
|  | 4592 | * @pring: Pointer to driver SLI ring object. | 
|  | 4593 | * @cmdiocb: Pointer to driver command iocb object. | 
|  | 4594 | * | 
|  | 4595 | * This function issues an abort iocb for the provided command | 
|  | 4596 | * iocb. This function is called with hbalock held. | 
|  | 4597 | * The function returns 0 when it fails due to memory allocation | 
|  | 4598 | * failure or when the command iocb is an abort request. | 
|  | 4599 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4600 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4601 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 4602 | struct lpfc_iocbq *cmdiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4603 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4604 | struct lpfc_vport *vport = cmdiocb->vport; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4605 | struct lpfc_iocbq *abtsiocbp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | IOCB_t *icmd = NULL; | 
|  | 4607 | IOCB_t *iabt = NULL; | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4608 | int retval = IOCB_ERROR; | 
|  | 4609 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4610 | /* | 
|  | 4611 | * There are certain command types we don't want to abort.  And we | 
|  | 4612 | * don't want to abort commands that are already in the process of | 
|  | 4613 | * being aborted. | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4614 | */ | 
|  | 4615 | icmd = &cmdiocb->iocb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4616 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4617 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | 
|  | 4618 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4619 | return 0; | 
|  | 4620 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4621 | /* If we're unloading, don't abort iocb on the ELS ring, but change the | 
|  | 4622 | * callback so that nothing happens when it finishes. | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4623 | */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4624 | if ((vport->load_flag & FC_UNLOADING) && | 
|  | 4625 | (pring->ringno == LPFC_ELS_RING)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4626 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | 
|  | 4627 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | 
|  | 4628 | else | 
|  | 4629 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4630 | goto abort_iotag_exit; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4631 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 |  | 
|  | 4633 | /* issue ABTS for this IOCB based on iotag */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4634 | abtsiocbp = __lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | if (abtsiocbp == NULL) | 
|  | 4636 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 |  | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4638 | /* This signals the response to set the correct status | 
|  | 4639 | * before calling the completion handler. | 
|  | 4640 | */ | 
|  | 4641 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | 
|  | 4642 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | iabt = &abtsiocbp->iocb; | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4644 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; | 
|  | 4645 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | 
|  | 4646 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | iabt->ulpLe = 1; | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4648 | iabt->ulpClass = icmd->ulpClass; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4649 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4650 | if (phba->link_state >= LPFC_LINK_UP) | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4651 | iabt->ulpCommand = CMD_ABORT_XRI_CN; | 
|  | 4652 | else | 
|  | 4653 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | 
|  | 4654 |  | 
|  | 4655 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4656 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4657 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, | 
|  | 4658 | "0339 Abort xri x%x, original iotag x%x, " | 
|  | 4659 | "abort cmd iotag x%x\n", | 
|  | 4660 | iabt->un.acxri.abortContextTag, | 
|  | 4661 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4662 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4663 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4664 | if (retval) | 
|  | 4665 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4666 | abort_iotag_exit: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4667 | /* | 
|  | 4668 | * Caller to this routine should check for IOCB_ERROR | 
|  | 4669 | * and handle it properly.  This routine no longer removes | 
|  | 4670 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4671 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4672 | return retval; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | } | 
|  | 4674 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4675 | /** | 
|  | 4676 | * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands | 
|  | 4677 | *                    associated with a vport/SCSI target/lun. | 
|  | 4678 | * @iocbq: Pointer to driver iocb object. | 
|  | 4679 | * @vport: Pointer to driver virtual port object. | 
|  | 4680 | * @tgt_id: SCSI ID of the target. | 
|  | 4681 | * @lun_id: LUN ID of the scsi device. | 
|  | 4682 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | 
|  | 4683 | * | 
|  | 4684 | * This function acts as iocb filter for functions which abort or count | 
|  | 4685 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return | 
|  | 4686 | * 0 if the filtering criteria is met for the given iocb and will return | 
|  | 4687 | * 1 if the filtering criteria is not met. | 
|  | 4688 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | 
|  | 4689 | * given iocb is for the SCSI device specified by vport, tgt_id and | 
|  | 4690 | * lun_id parameter. | 
|  | 4691 | * If ctx_cmd == LPFC_CTX_TGT,  the function returns 0 only if the | 
|  | 4692 | * given iocb is for the SCSI target specified by vport and tgt_id | 
|  | 4693 | * parameters. | 
|  | 4694 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | 
|  | 4695 | * given iocb is for the SCSI host associated with the given vport. | 
|  | 4696 | * This function is called with no locks held. | 
|  | 4697 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | static int | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4699 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, | 
|  | 4700 | uint16_t tgt_id, uint64_t lun_id, | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4701 | lpfc_ctx_cmd ctx_cmd) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | { | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4703 | struct lpfc_scsi_buf *lpfc_cmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | int rc = 1; | 
|  | 4705 |  | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4706 | if (!(iocbq->iocb_flag &  LPFC_IO_FCP)) | 
|  | 4707 | return rc; | 
|  | 4708 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4709 | if (iocbq->vport != vport) | 
|  | 4710 | return rc; | 
|  | 4711 |  | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4712 | 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] | 4713 |  | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4714 | if (lpfc_cmd->pCmd == NULL) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | return rc; | 
|  | 4716 |  | 
|  | 4717 | switch (ctx_cmd) { | 
|  | 4718 | case LPFC_CTX_LUN: | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4719 | if ((lpfc_cmd->rdata->pnode) && | 
|  | 4720 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | 
|  | 4721 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | rc = 0; | 
|  | 4723 | break; | 
|  | 4724 | case LPFC_CTX_TGT: | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4725 | if ((lpfc_cmd->rdata->pnode) && | 
|  | 4726 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | rc = 0; | 
|  | 4728 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | case LPFC_CTX_HOST: | 
|  | 4730 | rc = 0; | 
|  | 4731 | break; | 
|  | 4732 | default: | 
|  | 4733 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | 
| Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4734 | __func__, ctx_cmd); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | break; | 
|  | 4736 | } | 
|  | 4737 |  | 
|  | 4738 | return rc; | 
|  | 4739 | } | 
|  | 4740 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4741 | /** | 
|  | 4742 | * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending. | 
|  | 4743 | * @vport: Pointer to virtual port. | 
|  | 4744 | * @tgt_id: SCSI ID of the target. | 
|  | 4745 | * @lun_id: LUN ID of the scsi device. | 
|  | 4746 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | 
|  | 4747 | * | 
|  | 4748 | * This function returns number of FCP commands pending for the vport. | 
|  | 4749 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | 
|  | 4750 | * commands pending on the vport associated with SCSI device specified | 
|  | 4751 | * by tgt_id and lun_id parameters. | 
|  | 4752 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | 
|  | 4753 | * commands pending on the vport associated with SCSI target specified | 
|  | 4754 | * by tgt_id parameter. | 
|  | 4755 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | 
|  | 4756 | * commands pending on the vport. | 
|  | 4757 | * This function returns the number of iocbs which satisfy the filter. | 
|  | 4758 | * This function is called without any lock held. | 
|  | 4759 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | int | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4761 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, | 
|  | 4762 | lpfc_ctx_cmd ctx_cmd) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4764 | struct lpfc_hba *phba = vport->phba; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4765 | struct lpfc_iocbq *iocbq; | 
|  | 4766 | int sum, i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 |  | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4768 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { | 
|  | 4769 | iocbq = phba->sli.iocbq_lookup[i]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4771 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, | 
|  | 4772 | ctx_cmd) == 0) | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4773 | sum++; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | } | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4775 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | return sum; | 
|  | 4777 | } | 
|  | 4778 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4779 | /** | 
|  | 4780 | * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted | 
|  | 4781 | *       FCP iocb. | 
|  | 4782 | * @phba: Pointer to HBA context object | 
|  | 4783 | * @cmdiocb: Pointer to command iocb object. | 
|  | 4784 | * @rspiocb: Pointer to response iocb object. | 
|  | 4785 | * | 
|  | 4786 | * This function is called when an aborted FCP iocb completes. This | 
|  | 4787 | * function is called by the ring event handler with no lock held. | 
|  | 4788 | * This function frees the iocb. | 
|  | 4789 | **/ | 
| James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4790 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4791 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 4792 | struct lpfc_iocbq *rspiocb) | 
| James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4793 | { | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4794 | lpfc_sli_release_iocbq(phba, cmdiocb); | 
| James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4795 | return; | 
|  | 4796 | } | 
|  | 4797 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4798 | /** | 
|  | 4799 | * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands | 
|  | 4800 | *          pending on a SCSI host(vport)/target/lun. | 
|  | 4801 | * @vport: Pointer to virtual port. | 
|  | 4802 | * @pring: Pointer to driver SLI ring object. | 
|  | 4803 | * @tgt_id: SCSI ID of the target. | 
|  | 4804 | * @lun_id: LUN ID of the scsi device. | 
|  | 4805 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | 
|  | 4806 | * | 
|  | 4807 | * This function sends an abort command for every SCSI command | 
|  | 4808 | * associated with the given virtual port pending on the ring | 
|  | 4809 | * filtered by lpfc_sli_validate_fcp_iocb function. | 
|  | 4810 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | 
|  | 4811 | * FCP iocbs associated with lun specified by tgt_id and lun_id | 
|  | 4812 | * parameters | 
|  | 4813 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | 
|  | 4814 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | 
|  | 4815 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | 
|  | 4816 | * FCP iocbs associated with virtual port. | 
|  | 4817 | * This function returns number of iocbs it failed to abort. | 
|  | 4818 | * This function is called with no locks held. | 
|  | 4819 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | int | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4821 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | 
|  | 4822 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4823 | { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4824 | struct lpfc_hba *phba = vport->phba; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4825 | struct lpfc_iocbq *iocbq; | 
|  | 4826 | struct lpfc_iocbq *abtsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4827 | IOCB_t *cmd = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | int errcnt = 0, ret_val = 0; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4829 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 |  | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4831 | for (i = 1; i <= phba->sli.last_iotag; i++) { | 
|  | 4832 | iocbq = phba->sli.iocbq_lookup[i]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4833 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4834 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4835 | abort_cmd) != 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | continue; | 
|  | 4837 |  | 
|  | 4838 | /* issue ABTS for this IOCB based on iotag */ | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4839 | abtsiocb = lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | if (abtsiocb == NULL) { | 
|  | 4841 | errcnt++; | 
|  | 4842 | continue; | 
|  | 4843 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4844 |  | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4845 | cmd = &iocbq->iocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4846 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; | 
|  | 4847 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | 
|  | 4848 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | 
|  | 4849 | abtsiocb->iocb.ulpLe = 1; | 
|  | 4850 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | abtsiocb->vport = phba->pport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4853 | if (lpfc_is_link_up(phba)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; | 
|  | 4855 | else | 
|  | 4856 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | 
|  | 4857 |  | 
| James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4858 | /* Setup callback routine and issue the command. */ | 
|  | 4859 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); | 
|  | 4861 | if (ret_val == IOCB_ERROR) { | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4862 | lpfc_sli_release_iocbq(phba, abtsiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | errcnt++; | 
|  | 4864 | continue; | 
|  | 4865 | } | 
|  | 4866 | } | 
|  | 4867 |  | 
|  | 4868 | return errcnt; | 
|  | 4869 | } | 
|  | 4870 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4871 | /** | 
|  | 4872 | * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using | 
|  | 4873 | *                          lpfc_sli_issue_iocb_wait. | 
|  | 4874 | * @phba: Pointer to HBA context object. | 
|  | 4875 | * @cmdiocbq: Pointer to command iocb. | 
|  | 4876 | * @rspiocbq: Pointer to response iocb. | 
|  | 4877 | * | 
|  | 4878 | * This function is the completion handler for iocbs issued using | 
|  | 4879 | * lpfc_sli_issue_iocb_wait function. This function is called by the | 
|  | 4880 | * ring event handler function without any lock held. This function | 
|  | 4881 | * can be called from both worker thread context and interrupt | 
|  | 4882 | * context. This function also can be called from other thread which | 
|  | 4883 | * cleans up the SLI layer objects. | 
|  | 4884 | * This function copy the contents of the response iocb to the | 
|  | 4885 | * response iocb memory object provided by the caller of | 
|  | 4886 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | 
|  | 4887 | * sleeps for the iocb completion. | 
|  | 4888 | **/ | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4889 | static void | 
|  | 4890 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | 
|  | 4891 | struct lpfc_iocbq *cmdiocbq, | 
|  | 4892 | struct lpfc_iocbq *rspiocbq) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | { | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4894 | wait_queue_head_t *pdone_q; | 
|  | 4895 | unsigned long iflags; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4896 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4897 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4898 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; | 
|  | 4899 | if (cmdiocbq->context2 && rspiocbq) | 
|  | 4900 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | 
|  | 4901 | &rspiocbq->iocb, sizeof(IOCB_t)); | 
|  | 4902 |  | 
|  | 4903 | pdone_q = cmdiocbq->context_un.wait_queue; | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4904 | if (pdone_q) | 
|  | 4905 | wake_up(pdone_q); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4906 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | return; | 
|  | 4908 | } | 
|  | 4909 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4910 | /** | 
|  | 4911 | * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands. | 
|  | 4912 | * @phba: Pointer to HBA context object.. | 
|  | 4913 | * @pring: Pointer to sli ring. | 
|  | 4914 | * @piocb: Pointer to command iocb. | 
|  | 4915 | * @prspiocbq: Pointer to response iocb. | 
|  | 4916 | * @timeout: Timeout in number of seconds. | 
|  | 4917 | * | 
|  | 4918 | * This function issues the iocb to firmware and waits for the | 
|  | 4919 | * iocb to complete. If the iocb command is not | 
|  | 4920 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | 
|  | 4921 | * Caller should not free the iocb resources if this function | 
|  | 4922 | * returns IOCB_TIMEDOUT. | 
|  | 4923 | * The function waits for the iocb completion using an | 
|  | 4924 | * non-interruptible wait. | 
|  | 4925 | * This function will sleep while waiting for iocb completion. | 
|  | 4926 | * So, this function should not be called from any context which | 
|  | 4927 | * does not allow sleeping. Due to the same reason, this function | 
|  | 4928 | * cannot be called with interrupt disabled. | 
|  | 4929 | * This function assumes that the iocb completions occur while | 
|  | 4930 | * this function sleep. So, this function cannot be called from | 
|  | 4931 | * the thread which process iocb completion for this ring. | 
|  | 4932 | * This function clears the iocb_flag of the iocb object before | 
|  | 4933 | * issuing the iocb and the iocb completion handler sets this | 
|  | 4934 | * flag and wakes this thread when the iocb completes. | 
|  | 4935 | * The contents of the response iocb will be copied to prspiocbq | 
|  | 4936 | * by the completion handler when the command completes. | 
|  | 4937 | * This function returns IOCB_SUCCESS when success. | 
|  | 4938 | * This function is called with no lock held. | 
|  | 4939 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4940 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4941 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, | 
|  | 4942 | struct lpfc_sli_ring *pring, | 
|  | 4943 | struct lpfc_iocbq *piocb, | 
|  | 4944 | struct lpfc_iocbq *prspiocbq, | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4945 | uint32_t timeout) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | { | 
| Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4947 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4948 | long timeleft, timeout_req = 0; | 
|  | 4949 | int retval = IOCB_SUCCESS; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4950 | uint32_t creg_val; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4951 |  | 
|  | 4952 | /* | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4953 | * If the caller has provided a response iocbq buffer, then context2 | 
|  | 4954 | * is NULL or its an error. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | */ | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4956 | if (prspiocbq) { | 
|  | 4957 | if (piocb->context2) | 
|  | 4958 | return IOCB_ERROR; | 
|  | 4959 | piocb->context2 = prspiocbq; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | } | 
|  | 4961 |  | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4962 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; | 
|  | 4963 | piocb->context_un.wait_queue = &done_q; | 
|  | 4964 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4966 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | 
|  | 4967 | creg_val = readl(phba->HCregaddr); | 
|  | 4968 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | 
|  | 4969 | writel(creg_val, phba->HCregaddr); | 
|  | 4970 | readl(phba->HCregaddr); /* flush */ | 
|  | 4971 | } | 
|  | 4972 |  | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4973 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); | 
|  | 4974 | if (retval == IOCB_SUCCESS) { | 
|  | 4975 | timeout_req = timeout * HZ; | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4976 | timeleft = wait_event_timeout(done_q, | 
|  | 4977 | piocb->iocb_flag & LPFC_IO_WAKE, | 
|  | 4978 | timeout_req); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 |  | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4980 | if (piocb->iocb_flag & LPFC_IO_WAKE) { | 
|  | 4981 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4982 | "0331 IOCB wake signaled\n"); | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4983 | } else if (timeleft == 0) { | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4985 | "0338 IOCB wait timeout error - no " | 
|  | 4986 | "wake response Data x%x\n", timeout); | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4987 | retval = IOCB_TIMEDOUT; | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4988 | } else { | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4989 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4990 | "0330 IOCB wake NOT set, " | 
|  | 4991 | "Data x%x x%lx\n", | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4992 | timeout, (timeleft / jiffies)); | 
|  | 4993 | retval = IOCB_TIMEDOUT; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | } | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4995 | } else { | 
|  | 4996 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4997 | "0332 IOCB wait issue failed, Data x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4998 | retval); | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4999 | retval = IOCB_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5000 | } | 
|  | 5001 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5002 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | 
|  | 5003 | creg_val = readl(phba->HCregaddr); | 
|  | 5004 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | 
|  | 5005 | writel(creg_val, phba->HCregaddr); | 
|  | 5006 | readl(phba->HCregaddr); /* flush */ | 
|  | 5007 | } | 
|  | 5008 |  | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5009 | if (prspiocbq) | 
|  | 5010 | piocb->context2 = NULL; | 
|  | 5011 |  | 
|  | 5012 | piocb->context_un.wait_queue = NULL; | 
|  | 5013 | piocb->iocb_cmpl = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5014 | return retval; | 
|  | 5015 | } | 
| James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5016 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5017 | /** | 
|  | 5018 | * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox. | 
|  | 5019 | * @phba: Pointer to HBA context object. | 
|  | 5020 | * @pmboxq: Pointer to driver mailbox object. | 
|  | 5021 | * @timeout: Timeout in number of seconds. | 
|  | 5022 | * | 
|  | 5023 | * This function issues the mailbox to firmware and waits for the | 
|  | 5024 | * mailbox command to complete. If the mailbox command is not | 
|  | 5025 | * completed within timeout seconds, it returns MBX_TIMEOUT. | 
|  | 5026 | * The function waits for the mailbox completion using an | 
|  | 5027 | * interruptible wait. If the thread is woken up due to a | 
|  | 5028 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | 
|  | 5029 | * should not free the mailbox resources, if this function returns | 
|  | 5030 | * MBX_TIMEOUT. | 
|  | 5031 | * This function will sleep while waiting for mailbox completion. | 
|  | 5032 | * So, this function should not be called from any context which | 
|  | 5033 | * does not allow sleeping. Due to the same reason, this function | 
|  | 5034 | * cannot be called with interrupt disabled. | 
|  | 5035 | * This function assumes that the mailbox completion occurs while | 
|  | 5036 | * this function sleep. So, this function cannot be called from | 
|  | 5037 | * the worker thread which processes mailbox completion. | 
|  | 5038 | * This function is called in the context of HBA management | 
|  | 5039 | * applications. | 
|  | 5040 | * This function returns MBX_SUCCESS when successful. | 
|  | 5041 | * This function is called with no lock held. | 
|  | 5042 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5044 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | uint32_t timeout) | 
|  | 5046 | { | 
| Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5047 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | int retval; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5049 | unsigned long flag; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 |  | 
|  | 5051 | /* The caller must leave context1 empty. */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5052 | if (pmboxq->context1) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5053 | return MBX_NOT_FINISHED; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 |  | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5055 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | /* setup wake call as IOCB callback */ | 
|  | 5057 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | 
|  | 5058 | /* setup context field to pass wait_queue pointer to wake function  */ | 
|  | 5059 | pmboxq->context1 = &done_q; | 
|  | 5060 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | /* now issue the command */ | 
|  | 5062 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | 
|  | 5063 |  | 
|  | 5064 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5065 | wait_event_interruptible_timeout(done_q, | 
|  | 5066 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | 
|  | 5067 | timeout * HZ); | 
|  | 5068 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5069 | spin_lock_irqsave(&phba->hbalock, flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5070 | pmboxq->context1 = NULL; | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5071 | /* | 
|  | 5072 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | 
|  | 5073 | * else do not free the resources. | 
|  | 5074 | */ | 
|  | 5075 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | retval = MBX_SUCCESS; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5077 | else { | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5078 | retval = MBX_TIMEOUT; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5079 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
|  | 5080 | } | 
|  | 5081 | spin_unlock_irqrestore(&phba->hbalock, flag); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5082 | } | 
|  | 5083 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | return retval; | 
|  | 5085 | } | 
|  | 5086 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5087 | /** | 
|  | 5088 | * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function. | 
|  | 5089 | * @phba: Pointer to HBA context. | 
|  | 5090 | * | 
|  | 5091 | * This function is called to cleanup any pending mailbox | 
|  | 5092 | * objects in the driver queue before bringing the HBA offline. | 
|  | 5093 | * This function is called while resetting the HBA. | 
|  | 5094 | * The function is called without any lock held. The function | 
|  | 5095 | * takes hbalock to update SLI data structure. | 
|  | 5096 | * This function returns 1 when there is an active mailbox | 
|  | 5097 | * command pending else returns 0. | 
|  | 5098 | **/ | 
| James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5099 | int | 
|  | 5100 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) | 
|  | 5101 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5102 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5103 | int i = 0; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5104 | uint32_t ha_copy; | 
| James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5105 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5106 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { | 
| James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5107 | if (i++ > LPFC_MBOX_TMO * 1000) | 
|  | 5108 | return 1; | 
|  | 5109 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5110 | /* | 
|  | 5111 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd | 
|  | 5112 | * did finish. This way we won't get the misleading | 
|  | 5113 | * "Stray Mailbox Interrupt" message. | 
|  | 5114 | */ | 
|  | 5115 | spin_lock_irq(&phba->hbalock); | 
|  | 5116 | ha_copy = phba->work_ha; | 
|  | 5117 | phba->work_ha &= ~HA_MBATT; | 
|  | 5118 | spin_unlock_irq(&phba->hbalock); | 
|  | 5119 |  | 
|  | 5120 | if (ha_copy & HA_MBATT) | 
|  | 5121 | if (lpfc_sli_handle_mb_event(phba) == 0) | 
|  | 5122 | i = 0; | 
| James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5123 |  | 
|  | 5124 | msleep(1); | 
|  | 5125 | } | 
|  | 5126 |  | 
|  | 5127 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; | 
|  | 5128 | } | 
|  | 5129 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5130 | /** | 
|  | 5131 | * lpfc_intr_handler: The interrupt handler of lpfc driver. | 
|  | 5132 | * @irq: Interrupt number. | 
|  | 5133 | * @dev_id: The device context pointer. | 
|  | 5134 | * | 
|  | 5135 | * This function is called from the PCI layer when there is | 
|  | 5136 | * an event in the HBA which requires driver attention. When | 
|  | 5137 | * the PCI slot is in error recovery or the HBA is undergoing | 
|  | 5138 | * initialization the interrupt handler will not process the | 
|  | 5139 | * interrupt. | 
|  | 5140 | * The error attention, link attention and els ring attention | 
|  | 5141 | * events are handled by the worker thread. The interrupt | 
|  | 5142 | * handler signals the worker thread and returns for these | 
|  | 5143 | * events. | 
|  | 5144 | * The SCSI ring event and mailbox events are handled in the | 
|  | 5145 | * interrupt context. | 
|  | 5146 | * This function is called without any lock held. It gets the | 
|  | 5147 | * hbalock to access and update SLI data structures. | 
|  | 5148 | * This function returns IRQ_HANDLED when interrupt is handled | 
|  | 5149 | * else it returns IRQ_NONE. | 
|  | 5150 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5151 | irqreturn_t | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5152 | lpfc_intr_handler(int irq, void *dev_id) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5153 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5154 | struct lpfc_hba  *phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5155 | uint32_t ha_copy; | 
|  | 5156 | uint32_t work_ha_copy; | 
|  | 5157 | unsigned long status; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | uint32_t control; | 
|  | 5159 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5160 | MAILBOX_t *mbox, *pmbox; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5161 | struct lpfc_vport *vport; | 
|  | 5162 | struct lpfc_nodelist *ndlp; | 
|  | 5163 | struct lpfc_dmabuf *mp; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5164 | LPFC_MBOXQ_t *pmb; | 
|  | 5165 | int rc; | 
|  | 5166 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5167 | /* | 
|  | 5168 | * Get the driver's phba structure from the dev_id and | 
|  | 5169 | * assume the HBA is not interrupting. | 
|  | 5170 | */ | 
|  | 5171 | phba = (struct lpfc_hba *) dev_id; | 
|  | 5172 |  | 
|  | 5173 | if (unlikely(!phba)) | 
|  | 5174 | return IRQ_NONE; | 
|  | 5175 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 5176 | /* If the pci channel is offline, ignore all the interrupts. */ | 
|  | 5177 | if (unlikely(pci_channel_offline(phba->pcidev))) | 
|  | 5178 | return IRQ_NONE; | 
|  | 5179 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5180 | phba->sli.slistat.sli_intr++; | 
|  | 5181 |  | 
|  | 5182 | /* | 
|  | 5183 | * Call the HBA to see if it is interrupting.  If not, don't claim | 
|  | 5184 | * the interrupt | 
|  | 5185 | */ | 
|  | 5186 |  | 
|  | 5187 | /* Ignore all interrupts during initialization. */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5188 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5189 | return IRQ_NONE; | 
|  | 5190 |  | 
|  | 5191 | /* | 
|  | 5192 | * Read host attention register to determine interrupt source | 
|  | 5193 | * Clear Attention Sources, except Error Attention (to | 
|  | 5194 | * preserve status) and Link Attention | 
|  | 5195 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5196 | spin_lock(&phba->hbalock); | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5197 | if (phba->sli3_options & LPFC_SLI3_INB_ENABLED && | 
|  | 5198 | (phba->inb_last_counter != *phba->inb_counter)) { | 
|  | 5199 | phba->inb_last_counter = *phba->inb_counter; | 
|  | 5200 | ha_copy = le32_to_cpu(*phba->inb_ha_copy); | 
|  | 5201 | } else | 
|  | 5202 | ha_copy = readl(phba->HAregaddr); | 
|  | 5203 | if (unlikely(!ha_copy)) { | 
|  | 5204 | spin_unlock(&phba->hbalock); | 
|  | 5205 | return IRQ_NONE; | 
|  | 5206 | } | 
| James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 5207 | /* If somebody is waiting to handle an eratt don't process it | 
|  | 5208 | * here.  The brdkill function will do this. | 
|  | 5209 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5210 | if (phba->link_flag & LS_IGNORE_ERATT) | 
| James Smart | ebdbe65 | 2007-04-25 09:53:15 -0400 | [diff] [blame] | 5211 | ha_copy &= ~HA_ERATT; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5212 | writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); | 
|  | 5213 | readl(phba->HAregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5214 | spin_unlock(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5215 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | work_ha_copy = ha_copy & phba->work_ha_mask; | 
|  | 5217 |  | 
|  | 5218 | if (unlikely(work_ha_copy)) { | 
|  | 5219 | if (work_ha_copy & HA_LATT) { | 
|  | 5220 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | 
|  | 5221 | /* | 
|  | 5222 | * Turn off Link Attention interrupts | 
|  | 5223 | * until CLEAR_LA done | 
|  | 5224 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5225 | spin_lock(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; | 
|  | 5227 | control = readl(phba->HCregaddr); | 
|  | 5228 | control &= ~HC_LAINT_ENA; | 
|  | 5229 | writel(control, phba->HCregaddr); | 
|  | 5230 | readl(phba->HCregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | spin_unlock(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | } | 
|  | 5233 | else | 
|  | 5234 | work_ha_copy &= ~HA_LATT; | 
|  | 5235 | } | 
|  | 5236 |  | 
|  | 5237 | if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5238 | /* | 
|  | 5239 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | 
|  | 5240 | * the only slow ring. | 
|  | 5241 | */ | 
|  | 5242 | status = (work_ha_copy & | 
|  | 5243 | (HA_RXMASK  << (4*LPFC_ELS_RING))); | 
|  | 5244 | status >>= (4*LPFC_ELS_RING); | 
|  | 5245 | if (status & HA_RXMASK) { | 
|  | 5246 | spin_lock(&phba->hbalock); | 
|  | 5247 | control = readl(phba->HCregaddr); | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5248 |  | 
|  | 5249 | lpfc_debugfs_slow_ring_trc(phba, | 
|  | 5250 | "ISR slow ring:   ctl:x%x stat:x%x isrcnt:x%x", | 
|  | 5251 | control, status, | 
|  | 5252 | (uint32_t)phba->sli.slistat.sli_intr); | 
|  | 5253 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5254 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5255 | lpfc_debugfs_slow_ring_trc(phba, | 
|  | 5256 | "ISR Disable ring:" | 
|  | 5257 | "pwork:x%x hawork:x%x wait:x%x", | 
|  | 5258 | phba->work_ha, work_ha_copy, | 
|  | 5259 | (uint32_t)((unsigned long) | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5260 | &phba->work_waitq)); | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5261 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5262 | control &= | 
|  | 5263 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | writel(control, phba->HCregaddr); | 
|  | 5265 | readl(phba->HCregaddr); /* flush */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | } | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5267 | else { | 
|  | 5268 | lpfc_debugfs_slow_ring_trc(phba, | 
|  | 5269 | "ISR slow ring:   pwork:" | 
|  | 5270 | "x%x hawork:x%x wait:x%x", | 
|  | 5271 | phba->work_ha, work_ha_copy, | 
|  | 5272 | (uint32_t)((unsigned long) | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5273 | &phba->work_waitq)); | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5274 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5275 | spin_unlock(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | } | 
|  | 5277 | } | 
|  | 5278 |  | 
|  | 5279 | if (work_ha_copy & HA_ERATT) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | /* | 
|  | 5281 | * There was a link/board error.  Read the | 
|  | 5282 | * status register to retrieve the error event | 
|  | 5283 | * and process it. | 
|  | 5284 | */ | 
|  | 5285 | phba->sli.slistat.err_attn_event++; | 
|  | 5286 | /* Save status info */ | 
|  | 5287 | phba->work_hs = readl(phba->HSregaddr); | 
|  | 5288 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); | 
|  | 5289 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | 
|  | 5290 |  | 
|  | 5291 | /* Clear Chip error bit */ | 
|  | 5292 | writel(HA_ERATT, phba->HAregaddr); | 
|  | 5293 | readl(phba->HAregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5294 | phba->pport->stopped = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5295 | } | 
|  | 5296 |  | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5297 | spin_lock(&phba->hbalock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5298 | if ((work_ha_copy & HA_MBATT) && | 
|  | 5299 | (phba->sli.mbox_active)) { | 
|  | 5300 | pmb = phba->sli.mbox_active; | 
|  | 5301 | pmbox = &pmb->mb; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5302 | mbox = phba->mbox; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5303 | vport = pmb->vport; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5304 |  | 
|  | 5305 | /* First check out the status word */ | 
|  | 5306 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | 
|  | 5307 | if (pmbox->mbxOwner != OWN_HOST) { | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5308 | spin_unlock(&phba->hbalock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5309 | /* | 
|  | 5310 | * Stray Mailbox Interrupt, mbxCommand <cmd> | 
|  | 5311 | * mbxStatus <status> | 
|  | 5312 | */ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5313 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5314 | LOG_SLI, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5315 | "(%d):0304 Stray Mailbox " | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5316 | "Interrupt mbxCommand x%x " | 
|  | 5317 | "mbxStatus x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5318 | (vport ? vport->vpi : 0), | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5319 | pmbox->mbxCommand, | 
|  | 5320 | pmbox->mbxStatus); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5321 | /* clear mailbox attention bit */ | 
|  | 5322 | work_ha_copy &= ~HA_MBATT; | 
|  | 5323 | } else { | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5324 | phba->sli.mbox_active = NULL; | 
|  | 5325 | spin_unlock(&phba->hbalock); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5326 | phba->last_completion_time = jiffies; | 
|  | 5327 | del_timer(&phba->sli.mbox_tmo); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5328 | if (pmb->mbox_cmpl) { | 
|  | 5329 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | 
|  | 5330 | MAILBOX_CMD_SIZE); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5331 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5332 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | 
|  | 5333 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | 
|  | 5334 |  | 
|  | 5335 | lpfc_debugfs_disc_trc(vport, | 
|  | 5336 | LPFC_DISC_TRC_MBOX_VPORT, | 
|  | 5337 | "MBOX dflt rpi: : " | 
|  | 5338 | "status:x%x rpi:x%x", | 
|  | 5339 | (uint32_t)pmbox->mbxStatus, | 
|  | 5340 | pmbox->un.varWords[0], 0); | 
|  | 5341 |  | 
|  | 5342 | if (!pmbox->mbxStatus) { | 
|  | 5343 | mp = (struct lpfc_dmabuf *) | 
|  | 5344 | (pmb->context1); | 
|  | 5345 | ndlp = (struct lpfc_nodelist *) | 
|  | 5346 | pmb->context2; | 
|  | 5347 |  | 
|  | 5348 | /* Reg_LOGIN of dflt RPI was | 
|  | 5349 | * successful. new lets get | 
|  | 5350 | * rid of the RPI using the | 
|  | 5351 | * same mbox buffer. | 
|  | 5352 | */ | 
|  | 5353 | lpfc_unreg_login(phba, | 
|  | 5354 | vport->vpi, | 
|  | 5355 | pmbox->un.varWords[0], | 
|  | 5356 | pmb); | 
|  | 5357 | pmb->mbox_cmpl = | 
|  | 5358 | lpfc_mbx_cmpl_dflt_rpi; | 
|  | 5359 | pmb->context1 = mp; | 
|  | 5360 | pmb->context2 = ndlp; | 
|  | 5361 | pmb->vport = vport; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5362 | rc = lpfc_sli_issue_mbox(phba, | 
|  | 5363 | pmb, | 
|  | 5364 | MBX_NOWAIT); | 
|  | 5365 | if (rc != MBX_BUSY) | 
|  | 5366 | lpfc_printf_log(phba, | 
|  | 5367 | KERN_ERR, | 
|  | 5368 | LOG_MBOX | LOG_SLI, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5369 | "0350 rc should have" | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5370 | "been MBX_BUSY"); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5371 | goto send_current_mbox; | 
|  | 5372 | } | 
|  | 5373 | } | 
|  | 5374 | spin_lock(&phba->pport->work_port_lock); | 
|  | 5375 | phba->pport->work_port_events &= | 
|  | 5376 | ~WORKER_MBOX_TMO; | 
|  | 5377 | spin_unlock(&phba->pport->work_port_lock); | 
|  | 5378 | lpfc_mbox_cmpl_put(phba, pmb); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5379 | } | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5380 | } else | 
|  | 5381 | spin_unlock(&phba->hbalock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5382 | if ((work_ha_copy & HA_MBATT) && | 
|  | 5383 | (phba->sli.mbox_active == NULL)) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5384 | send_current_mbox: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5385 | /* Process next mailbox command if there is one */ | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5386 | do { | 
|  | 5387 | rc = lpfc_sli_issue_mbox(phba, NULL, | 
|  | 5388 | MBX_NOWAIT); | 
|  | 5389 | } while (rc == MBX_NOT_FINISHED); | 
|  | 5390 | if (rc != MBX_SUCCESS) | 
|  | 5391 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | 
|  | 5392 | LOG_SLI, "0349 rc should be " | 
|  | 5393 | "MBX_SUCCESS"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5394 | } | 
|  | 5395 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | spin_lock(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | phba->work_ha |= work_ha_copy; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5398 | spin_unlock(&phba->hbalock); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5399 | lpfc_worker_wake_up(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5400 | } | 
|  | 5401 |  | 
|  | 5402 | ha_copy &= ~(phba->work_ha_mask); | 
|  | 5403 |  | 
|  | 5404 | /* | 
|  | 5405 | * Process all events on FCP ring.  Take the optimized path for | 
|  | 5406 | * FCP IO.  Any other IO is slow path and is handled by | 
|  | 5407 | * the worker thread. | 
|  | 5408 | */ | 
|  | 5409 | status = (ha_copy & (HA_RXMASK  << (4*LPFC_FCP_RING))); | 
|  | 5410 | status >>= (4*LPFC_FCP_RING); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5411 | if (status & HA_RXMASK) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | lpfc_sli_handle_fast_ring_event(phba, | 
|  | 5413 | &phba->sli.ring[LPFC_FCP_RING], | 
|  | 5414 | status); | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5415 |  | 
|  | 5416 | if (phba->cfg_multi_ring_support == 2) { | 
|  | 5417 | /* | 
|  | 5418 | * Process all events on extra ring.  Take the optimized path | 
|  | 5419 | * for extra ring IO.  Any other IO is slow path and is handled | 
|  | 5420 | * by the worker thread. | 
|  | 5421 | */ | 
|  | 5422 | status = (ha_copy & (HA_RXMASK  << (4*LPFC_EXTRA_RING))); | 
|  | 5423 | status >>= (4*LPFC_EXTRA_RING); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5424 | if (status & HA_RXMASK) { | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5425 | lpfc_sli_handle_fast_ring_event(phba, | 
|  | 5426 | &phba->sli.ring[LPFC_EXTRA_RING], | 
|  | 5427 | status); | 
|  | 5428 | } | 
|  | 5429 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5430 | return IRQ_HANDLED; | 
|  | 5431 |  | 
|  | 5432 | } /* lpfc_intr_handler */ |