| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_cmnd.h> |
| 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 31 | #include <scsi/scsi_transport_fc.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_scsi.h" |
| 38 | #include "lpfc.h" |
| 39 | #include "lpfc_crtn.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 42 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 46 | * This allows multiple uses of lpfc_msgBlk0311 |
| 47 | * w/o perturbing log msg utility. |
| 48 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | lpfc_printf_log(phba, \ |
| 51 | KERN_INFO, \ |
| 52 | LOG_MBOX | LOG_SLI, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 53 | "(%d):0311 Mailbox command x%x cannot " \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | "issue Data: x%x x%x x%x\n", \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 55 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 56 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | |
| 62 | /* There are only four IOCB completion types. */ |
| 63 | typedef enum _lpfc_iocb_type { |
| 64 | LPFC_UNKNOWN_IOCB, |
| 65 | LPFC_UNSOL_IOCB, |
| 66 | LPFC_SOL_IOCB, |
| 67 | LPFC_ABORT_IOCB |
| 68 | } lpfc_iocb_type; |
| 69 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 70 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 71 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 72 | * @phba: Pointer to HBA context object. |
| 73 | * @pring: Pointer to driver SLI ring object. |
| 74 | * |
| 75 | * This function returns pointer to next command iocb entry |
| 76 | * in the command ring. The caller must hold hbalock to prevent |
| 77 | * other threads consume the next command iocb. |
| 78 | * SLI-2/SLI-3 provide different sized iocbs. |
| 79 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 80 | static inline IOCB_t * |
| 81 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 82 | { |
| 83 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 84 | pring->cmdidx * phba->iocb_cmd_size); |
| 85 | } |
| 86 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 87 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 88 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 89 | * @phba: Pointer to HBA context object. |
| 90 | * @pring: Pointer to driver SLI ring object. |
| 91 | * |
| 92 | * This function returns pointer to next response iocb entry |
| 93 | * in the response ring. The caller must hold hbalock to make sure |
| 94 | * that no other thread consume the next response iocb. |
| 95 | * SLI-2/SLI-3 provide different sized iocbs. |
| 96 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 97 | static inline IOCB_t * |
| 98 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 99 | { |
| 100 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 101 | pring->rspidx * phba->iocb_rsp_size); |
| 102 | } |
| 103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 105 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 106 | * @phba: Pointer to HBA context object. |
| 107 | * |
| 108 | * This function is called with hbalock held. This function |
| 109 | * allocates a new driver iocb object from the iocb pool. If the |
| 110 | * allocation is successful, it returns pointer to the newly |
| 111 | * allocated iocb object else it returns NULL. |
| 112 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 113 | static struct lpfc_iocbq * |
| 114 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 115 | { |
| 116 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 117 | struct lpfc_iocbq * iocbq = NULL; |
| 118 | |
| 119 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 120 | return iocbq; |
| 121 | } |
| 122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 124 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 125 | * @phba: Pointer to HBA context object. |
| 126 | * |
| 127 | * This function is called with no lock held. This function |
| 128 | * allocates a new driver iocb object from the iocb pool. If the |
| 129 | * allocation is successful, it returns pointer to the newly |
| 130 | * allocated iocb object else it returns NULL. |
| 131 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 132 | struct lpfc_iocbq * |
| 133 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 135 | struct lpfc_iocbq * iocbq = NULL; |
| 136 | unsigned long iflags; |
| 137 | |
| 138 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 139 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 140 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 141 | return iocbq; |
| 142 | } |
| 143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 145 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 146 | * @phba: Pointer to HBA context object. |
| 147 | * @iocbq: Pointer to driver iocb object. |
| 148 | * |
| 149 | * This function is called with hbalock held to release driver |
| 150 | * iocb object to the iocb pool. The iotag in the iocb object |
| 151 | * does not change for each use of the iocb object. This function |
| 152 | * clears all other fields of the iocb object when it is freed. |
| 153 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 154 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 155 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 156 | { |
| 157 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * Clean all volatile data fields, preserve iotag and node struct. |
| 161 | */ |
| 162 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 163 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 164 | } |
| 165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 167 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 168 | * @phba: Pointer to HBA context object. |
| 169 | * @iocbq: Pointer to driver iocb object. |
| 170 | * |
| 171 | * This function is called with no lock held to release the iocb to |
| 172 | * iocb pool. |
| 173 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 174 | void |
| 175 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 176 | { |
| 177 | unsigned long iflags; |
| 178 | |
| 179 | /* |
| 180 | * Clean all volatile data fields, preserve iotag and node struct. |
| 181 | */ |
| 182 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 183 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 185 | } |
| 186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 187 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 188 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 189 | * @phba: Pointer to HBA context object. |
| 190 | * @iocblist: List of IOCBs. |
| 191 | * @ulpstatus: ULP status in IOCB command field. |
| 192 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 193 | * |
| 194 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 195 | * on the list by invoking the complete callback function associated with the |
| 196 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 197 | * fields. |
| 198 | **/ |
| 199 | void |
| 200 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 201 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 202 | { |
| 203 | struct lpfc_iocbq *piocb; |
| 204 | |
| 205 | while (!list_empty(iocblist)) { |
| 206 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 207 | |
| 208 | if (!piocb->iocb_cmpl) |
| 209 | lpfc_sli_release_iocbq(phba, piocb); |
| 210 | else { |
| 211 | piocb->iocb.ulpStatus = ulpstatus; |
| 212 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 213 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 214 | } |
| 215 | } |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 220 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 221 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 222 | * |
| 223 | * This function is called by ring event handler function to get the iocb type. |
| 224 | * This function translates the iocb command to an iocb command type used to |
| 225 | * decide the final disposition of each completed IOCB. |
| 226 | * The function returns |
| 227 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 228 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 229 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 230 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 231 | * |
| 232 | * The caller is not required to hold any lock. |
| 233 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | static lpfc_iocb_type |
| 235 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 236 | { |
| 237 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 238 | |
| 239 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 240 | return 0; |
| 241 | |
| 242 | switch (iocb_cmnd) { |
| 243 | case CMD_XMIT_SEQUENCE_CR: |
| 244 | case CMD_XMIT_SEQUENCE_CX: |
| 245 | case CMD_XMIT_BCAST_CN: |
| 246 | case CMD_XMIT_BCAST_CX: |
| 247 | case CMD_ELS_REQUEST_CR: |
| 248 | case CMD_ELS_REQUEST_CX: |
| 249 | case CMD_CREATE_XRI_CR: |
| 250 | case CMD_CREATE_XRI_CX: |
| 251 | case CMD_GET_RPI_CN: |
| 252 | case CMD_XMIT_ELS_RSP_CX: |
| 253 | case CMD_GET_RPI_CR: |
| 254 | case CMD_FCP_IWRITE_CR: |
| 255 | case CMD_FCP_IWRITE_CX: |
| 256 | case CMD_FCP_IREAD_CR: |
| 257 | case CMD_FCP_IREAD_CX: |
| 258 | case CMD_FCP_ICMND_CR: |
| 259 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 260 | case CMD_FCP_TSEND_CX: |
| 261 | case CMD_FCP_TRSP_CX: |
| 262 | case CMD_FCP_TRECEIVE_CX: |
| 263 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 264 | case CMD_ADAPTER_MSG: |
| 265 | case CMD_ADAPTER_DUMP: |
| 266 | case CMD_XMIT_SEQUENCE64_CR: |
| 267 | case CMD_XMIT_SEQUENCE64_CX: |
| 268 | case CMD_XMIT_BCAST64_CN: |
| 269 | case CMD_XMIT_BCAST64_CX: |
| 270 | case CMD_ELS_REQUEST64_CR: |
| 271 | case CMD_ELS_REQUEST64_CX: |
| 272 | case CMD_FCP_IWRITE64_CR: |
| 273 | case CMD_FCP_IWRITE64_CX: |
| 274 | case CMD_FCP_IREAD64_CR: |
| 275 | case CMD_FCP_IREAD64_CX: |
| 276 | case CMD_FCP_ICMND64_CR: |
| 277 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 278 | case CMD_FCP_TSEND64_CX: |
| 279 | case CMD_FCP_TRSP64_CX: |
| 280 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 281 | case CMD_GEN_REQUEST64_CR: |
| 282 | case CMD_GEN_REQUEST64_CX: |
| 283 | case CMD_XMIT_ELS_RSP64_CX: |
| 284 | type = LPFC_SOL_IOCB; |
| 285 | break; |
| 286 | case CMD_ABORT_XRI_CN: |
| 287 | case CMD_ABORT_XRI_CX: |
| 288 | case CMD_CLOSE_XRI_CN: |
| 289 | case CMD_CLOSE_XRI_CX: |
| 290 | case CMD_XRI_ABORTED_CX: |
| 291 | case CMD_ABORT_MXRI64_CN: |
| 292 | type = LPFC_ABORT_IOCB; |
| 293 | break; |
| 294 | case CMD_RCV_SEQUENCE_CX: |
| 295 | case CMD_RCV_ELS_REQ_CX: |
| 296 | case CMD_RCV_SEQUENCE64_CX: |
| 297 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 298 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 299 | case CMD_IOCB_RCV_SEQ64_CX: |
| 300 | case CMD_IOCB_RCV_ELS64_CX: |
| 301 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 302 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | type = LPFC_UNSOL_IOCB; |
| 304 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 305 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 306 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 307 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 308 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 309 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 310 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 311 | case CMD_IOCB_RET_HBQE64_CN: |
| 312 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 313 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 314 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 315 | case CMD_IOCB_LOGENTRY_CN: |
| 316 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 317 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 318 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 319 | type = LPFC_UNKNOWN_IOCB; |
| 320 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | default: |
| 322 | type = LPFC_UNKNOWN_IOCB; |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | return type; |
| 327 | } |
| 328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 330 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 331 | * @phba: Pointer to HBA context object. |
| 332 | * |
| 333 | * This function is called from SLI initialization code |
| 334 | * to configure every ring of the HBA's SLI interface. The |
| 335 | * caller is not required to hold any lock. This function issues |
| 336 | * a config_ring mailbox command for each ring. |
| 337 | * This function returns zero if successful else returns a negative |
| 338 | * error code. |
| 339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 340 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 341 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 342 | { |
| 343 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 344 | LPFC_MBOXQ_t *pmb; |
| 345 | MAILBOX_t *pmbox; |
| 346 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 347 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 348 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 349 | if (!pmb) |
| 350 | return -ENOMEM; |
| 351 | pmbox = &pmb->mb; |
| 352 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 353 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | lpfc_config_ring(phba, i, pmb); |
| 355 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 356 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 358 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 359 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 360 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 361 | rc, pmbox->mbxCommand, |
| 362 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 363 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 364 | ret = -ENXIO; |
| 365 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 366 | } |
| 367 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 368 | mempool_free(pmb, phba->mbox_mem_pool); |
| 369 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | } |
| 371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 372 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 373 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 374 | * @phba: Pointer to HBA context object. |
| 375 | * @pring: Pointer to driver SLI ring object. |
| 376 | * @piocb: Pointer to the driver iocb object. |
| 377 | * |
| 378 | * This function is called with hbalock held. The function adds the |
| 379 | * new iocb to txcmplq of the given ring. This function always returns |
| 380 | * 0. If this function is called for ELS ring, this function checks if |
| 381 | * there is a vport associated with the ELS command. This function also |
| 382 | * starts els_tmofunc timer if this is an ELS command. |
| 383 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 385 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 386 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 389 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 390 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 391 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 392 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 393 | if (!piocb->vport) |
| 394 | BUG(); |
| 395 | else |
| 396 | mod_timer(&piocb->vport->els_tmofunc, |
| 397 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 398 | } |
| 399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 400 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 401 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 402 | } |
| 403 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 404 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 405 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 406 | * @phba: Pointer to HBA context object. |
| 407 | * @pring: Pointer to driver SLI ring object. |
| 408 | * |
| 409 | * This function is called with hbalock held to get next |
| 410 | * iocb in txq of the given ring. If there is any iocb in |
| 411 | * the txq, the function returns first iocb in the list after |
| 412 | * removing the iocb from the list, else it returns NULL. |
| 413 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 415 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | struct lpfc_iocbq *cmd_iocb; |
| 418 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 419 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 420 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 422 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | } |
| 424 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 425 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 426 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 427 | * @phba: Pointer to HBA context object. |
| 428 | * @pring: Pointer to driver SLI ring object. |
| 429 | * |
| 430 | * This function is called with hbalock held and the caller must post the |
| 431 | * iocb without releasing the lock. If the caller releases the lock, |
| 432 | * iocb slot returned by the function is not guaranteed to be available. |
| 433 | * The function returns pointer to the next available iocb slot if there |
| 434 | * is available slot in the ring, else it returns NULL. |
| 435 | * If the get index of the ring is ahead of the put index, the function |
| 436 | * will post an error attention event to the worker thread to take the |
| 437 | * HBA to offline state. |
| 438 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | static IOCB_t * |
| 440 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 441 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 442 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 445 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 446 | pring->next_cmdidx = 0; |
| 447 | |
| 448 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 449 | |
| 450 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 451 | |
| 452 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 454 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 455 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 456 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 457 | pring->local_getidx, max_cmd_idx); |
| 458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | /* |
| 461 | * All error attention handlers are posted to |
| 462 | * worker thread |
| 463 | */ |
| 464 | phba->work_ha |= HA_ERATT; |
| 465 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 466 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 467 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 468 | |
| 469 | return NULL; |
| 470 | } |
| 471 | |
| 472 | if (pring->local_getidx == pring->next_cmdidx) |
| 473 | return NULL; |
| 474 | } |
| 475 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 476 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 477 | } |
| 478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 480 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 481 | * @phba: Pointer to HBA context object. |
| 482 | * @iocbq: Pointer to driver iocb object. |
| 483 | * |
| 484 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 485 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 486 | * array and assigns a new iotag. |
| 487 | * The function returns the allocated iotag if successful, else returns zero. |
| 488 | * Zero is not a valid iotag. |
| 489 | * The caller is not required to hold any lock. |
| 490 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 491 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 492 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 494 | struct lpfc_iocbq **new_arr; |
| 495 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 496 | size_t new_len; |
| 497 | struct lpfc_sli *psli = &phba->sli; |
| 498 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 500 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 501 | iotag = psli->last_iotag; |
| 502 | if(++iotag < psli->iocbq_lookup_len) { |
| 503 | psli->last_iotag = iotag; |
| 504 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 505 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 506 | iocbq->iotag = iotag; |
| 507 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 508 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 509 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 510 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | spin_unlock_irq(&phba->hbalock); |
| 512 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 513 | GFP_KERNEL); |
| 514 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 516 | old_arr = psli->iocbq_lookup; |
| 517 | if (new_len <= psli->iocbq_lookup_len) { |
| 518 | /* highly unprobable case */ |
| 519 | kfree(new_arr); |
| 520 | iotag = psli->last_iotag; |
| 521 | if(++iotag < psli->iocbq_lookup_len) { |
| 522 | psli->last_iotag = iotag; |
| 523 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 524 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 525 | iocbq->iotag = iotag; |
| 526 | return iotag; |
| 527 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 528 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | if (psli->iocbq_lookup) |
| 532 | memcpy(new_arr, old_arr, |
| 533 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 534 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 535 | psli->iocbq_lookup = new_arr; |
| 536 | psli->iocbq_lookup_len = new_len; |
| 537 | psli->last_iotag = iotag; |
| 538 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 539 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 540 | iocbq->iotag = iotag; |
| 541 | kfree(old_arr); |
| 542 | return iotag; |
| 543 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 544 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 545 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 546 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 547 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 548 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 549 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 550 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 551 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | } |
| 553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 555 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 556 | * @phba: Pointer to HBA context object. |
| 557 | * @pring: Pointer to driver SLI ring object. |
| 558 | * @iocb: Pointer to iocb slot in the ring. |
| 559 | * @nextiocb: Pointer to driver iocb object which need to be |
| 560 | * posted to firmware. |
| 561 | * |
| 562 | * This function is called with hbalock held to post a new iocb to |
| 563 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 564 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 565 | * a completion call back for this iocb else the function will free the |
| 566 | * iocb object. |
| 567 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 568 | static void |
| 569 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 570 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 571 | { |
| 572 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 573 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 575 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 576 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 577 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 578 | if (pring->ringno == LPFC_ELS_RING) { |
| 579 | lpfc_debugfs_slow_ring_trc(phba, |
| 580 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 581 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 582 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 583 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 584 | } |
| 585 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | /* |
| 587 | * Issue iocb command to adapter |
| 588 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 589 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 590 | wmb(); |
| 591 | pring->stats.iocb_cmd++; |
| 592 | |
| 593 | /* |
| 594 | * If there is no completion routine to call, we can release the |
| 595 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 596 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 597 | */ |
| 598 | if (nextiocb->iocb_cmpl) |
| 599 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 600 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | |
| 603 | /* |
| 604 | * Let the HBA know what IOCB slot will be the next one the |
| 605 | * driver will put a command into. |
| 606 | */ |
| 607 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 608 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | } |
| 610 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 611 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 612 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 613 | * @phba: Pointer to HBA context object. |
| 614 | * @pring: Pointer to driver SLI ring object. |
| 615 | * |
| 616 | * The caller is not required to hold any lock for calling this function. |
| 617 | * This function updates the chip attention bits for the ring to inform firmware |
| 618 | * that there are pending work to be done for this ring and requests an |
| 619 | * interrupt when there is space available in the ring. This function is |
| 620 | * called when the driver is unable to post more iocbs to the ring due |
| 621 | * to unavailability of space in the ring. |
| 622 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 624 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | { |
| 626 | int ringno = pring->ringno; |
| 627 | |
| 628 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 629 | |
| 630 | wmb(); |
| 631 | |
| 632 | /* |
| 633 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 634 | * The HBA will tell us when an IOCB entry is available. |
| 635 | */ |
| 636 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 637 | readl(phba->CAregaddr); /* flush */ |
| 638 | |
| 639 | pring->stats.iocb_cmd_full++; |
| 640 | } |
| 641 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 642 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 643 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 644 | * @phba: Pointer to HBA context object. |
| 645 | * @pring: Pointer to driver SLI ring object. |
| 646 | * |
| 647 | * This function updates the chip attention register bit for the |
| 648 | * given ring to inform HBA that there is more work to be done |
| 649 | * in this ring. The caller is not required to hold any lock. |
| 650 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 652 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | { |
| 654 | int ringno = pring->ringno; |
| 655 | |
| 656 | /* |
| 657 | * Tell the HBA that there is work to do in this ring. |
| 658 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 659 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 660 | wmb(); |
| 661 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 662 | readl(phba->CAregaddr); /* flush */ |
| 663 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 664 | } |
| 665 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 666 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 667 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 668 | * @phba: Pointer to HBA context object. |
| 669 | * @pring: Pointer to driver SLI ring object. |
| 670 | * |
| 671 | * This function is called with hbalock held to post pending iocbs |
| 672 | * in the txq to the firmware. This function is called when driver |
| 673 | * detects space available in the ring. |
| 674 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | { |
| 678 | IOCB_t *iocb; |
| 679 | struct lpfc_iocbq *nextiocb; |
| 680 | |
| 681 | /* |
| 682 | * Check to see if: |
| 683 | * (a) there is anything on the txq to send |
| 684 | * (b) link is up |
| 685 | * (c) link attention events can be processed (fcp ring only) |
| 686 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 687 | */ |
| 688 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 689 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 690 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 691 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 692 | |
| 693 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 694 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 695 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 696 | |
| 697 | if (iocb) |
| 698 | lpfc_sli_update_ring(phba, pring); |
| 699 | else |
| 700 | lpfc_sli_update_full_ring(phba, pring); |
| 701 | } |
| 702 | |
| 703 | return; |
| 704 | } |
| 705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 707 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 708 | * @phba: Pointer to HBA context object. |
| 709 | * @hbqno: HBQ number. |
| 710 | * |
| 711 | * This function is called with hbalock held to get the next |
| 712 | * available slot for the given HBQ. If there is free slot |
| 713 | * available for the HBQ it will return pointer to the next available |
| 714 | * HBQ entry else it will return NULL. |
| 715 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 716 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 717 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 718 | { |
| 719 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 720 | |
| 721 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 722 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 723 | hbqp->next_hbqPutIdx = 0; |
| 724 | |
| 725 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 726 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 727 | uint32_t getidx = le32_to_cpu(raw_index); |
| 728 | |
| 729 | hbqp->local_hbqGetIdx = getidx; |
| 730 | |
| 731 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 732 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 733 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 734 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 735 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 736 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 737 | hbqp->entry_count); |
| 738 | |
| 739 | phba->link_state = LPFC_HBA_ERROR; |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 744 | return NULL; |
| 745 | } |
| 746 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 747 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 748 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 749 | } |
| 750 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 751 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 752 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 753 | * @phba: Pointer to HBA context object. |
| 754 | * |
| 755 | * This function is called with no lock held to free all the |
| 756 | * hbq buffers while uninitializing the SLI interface. It also |
| 757 | * frees the HBQ buffers returned by the firmware but not yet |
| 758 | * processed by the upper layers. |
| 759 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 760 | void |
| 761 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 762 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 763 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 764 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 765 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 766 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 767 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 768 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 769 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 770 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 771 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 772 | for (i = 0; i < hbq_count; ++i) { |
| 773 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 774 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 775 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 776 | list_del(&hbq_buf->dbuf.list); |
| 777 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 778 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 779 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 780 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 781 | /* Return all HBQ buffer that are in-fly */ |
| 782 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 783 | &phba->hbqbuf_in_list, list) { |
| 784 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 785 | list_del(&hbq_buf->dbuf.list); |
| 786 | if (hbq_buf->tag == -1) { |
| 787 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 788 | (phba, hbq_buf); |
| 789 | } else { |
| 790 | hbqno = hbq_buf->tag >> 16; |
| 791 | if (hbqno >= LPFC_MAX_HBQS) |
| 792 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 793 | (phba, hbq_buf); |
| 794 | else |
| 795 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 796 | hbq_buf); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* Mark the HBQs not in use */ |
| 801 | phba->hbq_in_use = 0; |
| 802 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 803 | } |
| 804 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 805 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 806 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 807 | * @phba: Pointer to HBA context object. |
| 808 | * @hbqno: HBQ number. |
| 809 | * @hbq_buf: Pointer to HBQ buffer. |
| 810 | * |
| 811 | * This function is called with the hbalock held to post a |
| 812 | * hbq buffer to the firmware. If the function finds an empty |
| 813 | * slot in the HBQ, it will post the buffer. The function will return |
| 814 | * pointer to the hbq entry if it successfully post the buffer |
| 815 | * else it will return NULL. |
| 816 | **/ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 817 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 818 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 820 | { |
| 821 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 822 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 823 | |
| 824 | /* Get next HBQ entry slot to use */ |
| 825 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 826 | if (hbqe) { |
| 827 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 828 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 829 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 830 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 831 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 832 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 833 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 834 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 835 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 836 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 837 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 839 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 840 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 841 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 842 | return hbqe; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 843 | } |
| 844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 845 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 846 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 847 | .rn = 1, |
| 848 | .entry_count = 200, |
| 849 | .mask_count = 0, |
| 850 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 851 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 852 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 853 | .init_count = 40, |
| 854 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 855 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 857 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 858 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 859 | .rn = 1, |
| 860 | .entry_count = 200, |
| 861 | .mask_count = 0, |
| 862 | .profile = 0, |
| 863 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 864 | .buffer_count = 0, |
| 865 | .init_count = 0, |
| 866 | .add_count = 5, |
| 867 | }; |
| 868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 869 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 870 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 871 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 872 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 873 | }; |
| 874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 876 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 877 | * @phba: Pointer to HBA context object. |
| 878 | * @hbqno: HBQ number. |
| 879 | * @count: Number of HBQ buffers to be posted. |
| 880 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 881 | * This function is called with no lock held to post more hbq buffers to the |
| 882 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 883 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 884 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 885 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 886 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 887 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 888 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 889 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 890 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 891 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 892 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 893 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 894 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 895 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 896 | lpfc_hbq_defs[hbqno]->entry_count) |
| 897 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 898 | phba->hbqs[hbqno].buffer_count; |
| 899 | if (!count) |
| 900 | return 0; |
| 901 | /* Allocate HBQ entries */ |
| 902 | for (i = 0; i < count; i++) { |
| 903 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 904 | if (!hbq_buffer) |
| 905 | break; |
| 906 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 907 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 908 | /* Check whether HBQ is still in use */ |
| 909 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 910 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 911 | goto err; |
| 912 | while (!list_empty(&hbq_buf_list)) { |
| 913 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 914 | dbuf.list); |
| 915 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 916 | (hbqno << 16)); |
| 917 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 918 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 919 | posted++; |
| 920 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 921 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 922 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 923 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 924 | return posted; |
| 925 | err: |
| 926 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 927 | while (!list_empty(&hbq_buf_list)) { |
| 928 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 929 | dbuf.list); |
| 930 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 931 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 932 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 933 | } |
| 934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 935 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 936 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 937 | * @phba: Pointer to HBA context object. |
| 938 | * @qno: HBQ number. |
| 939 | * |
| 940 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 941 | * is called with no lock held. The function returns the number of HBQ entries |
| 942 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 943 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 944 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 945 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 946 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 947 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 948 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 949 | } |
| 950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 952 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 953 | * @phba: Pointer to HBA context object. |
| 954 | * @qno: HBQ queue number. |
| 955 | * |
| 956 | * This function is called from SLI initialization code path with |
| 957 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 958 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 959 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 960 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 962 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 964 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 965 | } |
| 966 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 967 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 968 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 969 | * @phba: Pointer to HBA context object. |
| 970 | * @tag: Tag of the hbq buffer. |
| 971 | * |
| 972 | * This function is called with hbalock held. This function searches |
| 973 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 974 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 975 | * it returns NULL. |
| 976 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 977 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 978 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 979 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 980 | struct lpfc_dmabuf *d_buf; |
| 981 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 982 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 983 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 984 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 985 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 986 | return NULL; |
| 987 | |
| 988 | 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] | 989 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 990 | if (hbq_buf->tag == tag) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 991 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 992 | } |
| 993 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 994 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 995 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 996 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 997 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 998 | } |
| 999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1001 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1002 | * @phba: Pointer to HBA context object. |
| 1003 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1004 | * |
| 1005 | * This function is called with hbalock. This function gives back |
| 1006 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1007 | * post the buffer, it will free the buffer. |
| 1008 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1009 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1010 | 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] | 1011 | { |
| 1012 | uint32_t hbqno; |
| 1013 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1014 | if (hbq_buffer) { |
| 1015 | hbqno = hbq_buffer->tag >> 16; |
| 1016 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
| 1017 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1018 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1023 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1024 | * @mbxCommand: mailbox command code. |
| 1025 | * |
| 1026 | * This function is called by the mailbox event handler function to verify |
| 1027 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1028 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1029 | * and the mailbox event handler will take the HBA offline. |
| 1030 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | static int |
| 1032 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1033 | { |
| 1034 | uint8_t ret; |
| 1035 | |
| 1036 | switch (mbxCommand) { |
| 1037 | case MBX_LOAD_SM: |
| 1038 | case MBX_READ_NV: |
| 1039 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1040 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | case MBX_RUN_BIU_DIAG: |
| 1042 | case MBX_INIT_LINK: |
| 1043 | case MBX_DOWN_LINK: |
| 1044 | case MBX_CONFIG_LINK: |
| 1045 | case MBX_CONFIG_RING: |
| 1046 | case MBX_RESET_RING: |
| 1047 | case MBX_READ_CONFIG: |
| 1048 | case MBX_READ_RCONFIG: |
| 1049 | case MBX_READ_SPARM: |
| 1050 | case MBX_READ_STATUS: |
| 1051 | case MBX_READ_RPI: |
| 1052 | case MBX_READ_XRI: |
| 1053 | case MBX_READ_REV: |
| 1054 | case MBX_READ_LNK_STAT: |
| 1055 | case MBX_REG_LOGIN: |
| 1056 | case MBX_UNREG_LOGIN: |
| 1057 | case MBX_READ_LA: |
| 1058 | case MBX_CLEAR_LA: |
| 1059 | case MBX_DUMP_MEMORY: |
| 1060 | case MBX_DUMP_CONTEXT: |
| 1061 | case MBX_RUN_DIAGS: |
| 1062 | case MBX_RESTART: |
| 1063 | case MBX_UPDATE_CFG: |
| 1064 | case MBX_DOWN_LOAD: |
| 1065 | case MBX_DEL_LD_ENTRY: |
| 1066 | case MBX_RUN_PROGRAM: |
| 1067 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1068 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1070 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1072 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | case MBX_LOAD_AREA: |
| 1074 | case MBX_RUN_BIU_DIAG64: |
| 1075 | case MBX_CONFIG_PORT: |
| 1076 | case MBX_READ_SPARM64: |
| 1077 | case MBX_READ_RPI64: |
| 1078 | case MBX_REG_LOGIN64: |
| 1079 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1080 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | case MBX_SET_DEBUG: |
| 1082 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1083 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1084 | case MBX_REG_VPI: |
| 1085 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1086 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1087 | case MBX_PORT_CAPABILITIES: |
| 1088 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | ret = mbxCommand; |
| 1090 | break; |
| 1091 | default: |
| 1092 | ret = MBX_SHUTDOWN; |
| 1093 | break; |
| 1094 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1095 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1097 | |
| 1098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1099 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1100 | * @phba: Pointer to HBA context object. |
| 1101 | * @pmboxq: Pointer to mailbox command. |
| 1102 | * |
| 1103 | * This is completion handler function for mailbox commands issued from |
| 1104 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1105 | * mailbox event handler function with no lock held. This function |
| 1106 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1107 | * of the mailbox. |
| 1108 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | { |
| 1112 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1113 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | |
| 1115 | /* |
| 1116 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1117 | * continued running. |
| 1118 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1119 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1120 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1122 | if (pdone_q) |
| 1123 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1124 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | return; |
| 1126 | } |
| 1127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1128 | |
| 1129 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1130 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1131 | * @phba: Pointer to HBA context object. |
| 1132 | * @pmb: Pointer to mailbox object. |
| 1133 | * |
| 1134 | * This function is the default mailbox completion handler. It |
| 1135 | * frees the memory resources associated with the completed mailbox |
| 1136 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1137 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1138 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1139 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1140 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | { |
| 1142 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1143 | uint16_t rpi; |
| 1144 | int rc; |
| 1145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1147 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1148 | if (mp) { |
| 1149 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1150 | kfree(mp); |
| 1151 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1152 | |
| 1153 | /* |
| 1154 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1155 | * is in re-discovery driver need to cleanup the RPI. |
| 1156 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1157 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1158 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1159 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1160 | |
| 1161 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1162 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1163 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1164 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1165 | if (rc != MBX_NOT_FINISHED) |
| 1166 | return; |
| 1167 | } |
| 1168 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1169 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1170 | return; |
| 1171 | } |
| 1172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1173 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1174 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1175 | * @phba: Pointer to HBA context object. |
| 1176 | * |
| 1177 | * This function is called with no lock held. This function processes all |
| 1178 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1179 | * service routine processes mailbox completion interrupt and adds completed |
| 1180 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1181 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1182 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1183 | * function returns the mailbox commands to the upper layer by calling the |
| 1184 | * completion handler function of each mailbox. |
| 1185 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1187 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1189 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1191 | int rc; |
| 1192 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | |
| 1194 | phba->sli.slistat.mbox_event++; |
| 1195 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1196 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1197 | spin_lock_irq(&phba->hbalock); |
| 1198 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1199 | spin_unlock_irq(&phba->hbalock); |
| 1200 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1202 | do { |
| 1203 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1204 | if (pmb == NULL) |
| 1205 | break; |
| 1206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1209 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1210 | if (pmb->vport) { |
| 1211 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1212 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1213 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1214 | (uint32_t)pmbox->mbxCommand, |
| 1215 | pmbox->un.varWords[0], |
| 1216 | pmbox->un.varWords[1]); |
| 1217 | } |
| 1218 | else { |
| 1219 | lpfc_debugfs_disc_trc(phba->pport, |
| 1220 | LPFC_DISC_TRC_MBOX, |
| 1221 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1222 | (uint32_t)pmbox->mbxCommand, |
| 1223 | pmbox->un.varWords[0], |
| 1224 | pmbox->un.varWords[1]); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | /* |
| 1229 | * It is a fatal error if unknown mbox command completion. |
| 1230 | */ |
| 1231 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1232 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1234 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1235 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1236 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1237 | pmb->vport ? pmb->vport->vpi : 0, |
| 1238 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1239 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1240 | phba->work_hs = HS_FFER3; |
| 1241 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1242 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | } |
| 1244 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | if (pmbox->mbxStatus) { |
| 1246 | phba->sli.slistat.mbox_stat_err++; |
| 1247 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1248 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1249 | lpfc_printf_log(phba, KERN_INFO, |
| 1250 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1251 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1252 | "error - RETRYing Data: x%x " |
| 1253 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1254 | pmb->vport ? pmb->vport->vpi :0, |
| 1255 | pmbox->mbxCommand, |
| 1256 | pmbox->mbxStatus, |
| 1257 | pmbox->un.varWords[0], |
| 1258 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | pmbox->mbxStatus = 0; |
| 1260 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1261 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1262 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1263 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1265 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1266 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1271 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1272 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | "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] | 1274 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | pmbox->mbxCommand, |
| 1276 | pmb->mbox_cmpl, |
| 1277 | *((uint32_t *) pmbox), |
| 1278 | pmbox->un.varWords[0], |
| 1279 | pmbox->un.varWords[1], |
| 1280 | pmbox->un.varWords[2], |
| 1281 | pmbox->un.varWords[3], |
| 1282 | pmbox->un.varWords[4], |
| 1283 | pmbox->un.varWords[5], |
| 1284 | pmbox->un.varWords[6], |
| 1285 | pmbox->un.varWords[7]); |
| 1286 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1287 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1289 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1290 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1294 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1295 | * @phba: Pointer to HBA context object. |
| 1296 | * @pring: Pointer to driver SLI ring object. |
| 1297 | * @tag: buffer tag. |
| 1298 | * |
| 1299 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1300 | * is set in the tag the buffer is posted for a particular exchange, |
| 1301 | * the function will return the buffer without replacing the buffer. |
| 1302 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1303 | * returns the buffer and also posts another buffer to the firmware. |
| 1304 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1305 | static struct lpfc_dmabuf * |
| 1306 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1307 | struct lpfc_sli_ring *pring, |
| 1308 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1309 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1310 | struct hbq_dmabuf *hbq_entry; |
| 1311 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1312 | if (tag & QUE_BUFTAG_BIT) |
| 1313 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1314 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 1315 | if (!hbq_entry) |
| 1316 | return NULL; |
| 1317 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1318 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1319 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1320 | |
| 1321 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1322 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1323 | * @phba: Pointer to HBA context object. |
| 1324 | * @pring: Pointer to driver SLI ring object. |
| 1325 | * @saveq: Pointer to the unsolicited iocb. |
| 1326 | * |
| 1327 | * This function is called with no lock held by the ring event handler |
| 1328 | * when there is an unsolicited iocb posted to the response ring by the |
| 1329 | * firmware. This function gets the buffer associated with the iocbs |
| 1330 | * and calls the event handler for the ring. This function handles both |
| 1331 | * qring buffers and hbq buffers. |
| 1332 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1333 | * upper layer functions will free the iocb objects. |
| 1334 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | static int |
| 1336 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1337 | struct lpfc_iocbq *saveq) |
| 1338 | { |
| 1339 | IOCB_t * irsp; |
| 1340 | WORD5 * w5p; |
| 1341 | uint32_t Rctl, Type; |
| 1342 | uint32_t match, i; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1343 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1344 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | |
| 1346 | match = 0; |
| 1347 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1348 | |
| 1349 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1350 | if (pring->lpfc_sli_rcv_async_status) |
| 1351 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1352 | else |
| 1353 | lpfc_printf_log(phba, |
| 1354 | KERN_WARNING, |
| 1355 | LOG_SLI, |
| 1356 | "0316 Ring %d handler: unexpected " |
| 1357 | "ASYNC_STATUS iocb received evt_code " |
| 1358 | "0x%x\n", |
| 1359 | pring->ringno, |
| 1360 | irsp->un.asyncstat.evt_code); |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1364 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1365 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1366 | if (irsp->ulpBdeCount > 0) { |
| 1367 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1368 | irsp->un.ulpWord[3]); |
| 1369 | lpfc_in_buf_free(phba, dmzbuf); |
| 1370 | } |
| 1371 | |
| 1372 | if (irsp->ulpBdeCount > 1) { |
| 1373 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1374 | irsp->unsli3.sli3Words[3]); |
| 1375 | lpfc_in_buf_free(phba, dmzbuf); |
| 1376 | } |
| 1377 | |
| 1378 | if (irsp->ulpBdeCount > 2) { |
| 1379 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1380 | irsp->unsli3.sli3Words[7]); |
| 1381 | lpfc_in_buf_free(phba, dmzbuf); |
| 1382 | } |
| 1383 | |
| 1384 | return 1; |
| 1385 | } |
| 1386 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1387 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1388 | if (irsp->ulpBdeCount != 0) { |
| 1389 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1390 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1391 | if (!saveq->context2) |
| 1392 | lpfc_printf_log(phba, |
| 1393 | KERN_ERR, |
| 1394 | LOG_SLI, |
| 1395 | "0341 Ring %d Cannot find buffer for " |
| 1396 | "an unsolicited iocb. tag 0x%x\n", |
| 1397 | pring->ringno, |
| 1398 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1399 | } |
| 1400 | if (irsp->ulpBdeCount == 2) { |
| 1401 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1402 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1403 | if (!saveq->context3) |
| 1404 | lpfc_printf_log(phba, |
| 1405 | KERN_ERR, |
| 1406 | LOG_SLI, |
| 1407 | "0342 Ring %d Cannot find buffer for an" |
| 1408 | " unsolicited iocb. tag 0x%x\n", |
| 1409 | pring->ringno, |
| 1410 | irsp->unsli3.sli3Words[7]); |
| 1411 | } |
| 1412 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1413 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1414 | if (irsp->ulpBdeCount != 0) { |
| 1415 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1416 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1417 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1418 | lpfc_printf_log(phba, |
| 1419 | KERN_ERR, |
| 1420 | LOG_SLI, |
| 1421 | "0343 Ring %d Cannot find " |
| 1422 | "buffer for an unsolicited iocb" |
| 1423 | ". tag 0x%x\n", pring->ringno, |
| 1424 | irsp->un.ulpWord[3]); |
| 1425 | } |
| 1426 | if (irsp->ulpBdeCount == 2) { |
| 1427 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1428 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1429 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1430 | lpfc_printf_log(phba, |
| 1431 | KERN_ERR, |
| 1432 | LOG_SLI, |
| 1433 | "0344 Ring %d Cannot find " |
| 1434 | "buffer for an unsolicited " |
| 1435 | "iocb. tag 0x%x\n", |
| 1436 | pring->ringno, |
| 1437 | irsp->unsli3.sli3Words[7]); |
| 1438 | } |
| 1439 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1440 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1441 | if (irsp->ulpBdeCount != 0 && |
| 1442 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1443 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1444 | int found = 0; |
| 1445 | |
| 1446 | /* search continue save q for same XRI */ |
| 1447 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1448 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1449 | list_add_tail(&saveq->list, &iocbq->list); |
| 1450 | found = 1; |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | if (!found) |
| 1455 | list_add_tail(&saveq->clist, |
| 1456 | &pring->iocb_continue_saveq); |
| 1457 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1458 | list_del_init(&iocbq->clist); |
| 1459 | saveq = iocbq; |
| 1460 | irsp = &(saveq->iocb); |
| 1461 | } else |
| 1462 | return 0; |
| 1463 | } |
| 1464 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1465 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1466 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1467 | Rctl = FC_ELS_REQ; |
| 1468 | Type = FC_ELS_DATA; |
| 1469 | } else { |
| 1470 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1471 | Rctl = w5p->hcsw.Rctl; |
| 1472 | Type = w5p->hcsw.Type; |
| 1473 | |
| 1474 | /* Firmware Workaround */ |
| 1475 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1476 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1477 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1478 | Rctl = FC_ELS_REQ; |
| 1479 | Type = FC_ELS_DATA; |
| 1480 | w5p->hcsw.Rctl = Rctl; |
| 1481 | w5p->hcsw.Type = Type; |
| 1482 | } |
| 1483 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1484 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | /* unSolicited Responses */ |
| 1486 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1487 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1488 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1489 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | match = 1; |
| 1491 | } else { |
| 1492 | /* We must search, based on rctl / type |
| 1493 | for the right routine */ |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1494 | for (i = 0; i < pring->num_mask; i++) { |
| 1495 | if ((pring->prt[i].rctl == Rctl) |
| 1496 | && (pring->prt[i].type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1497 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1498 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1499 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | match = 1; |
| 1501 | break; |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | if (match == 0) { |
| 1506 | /* Unexpected Rctl / Type received */ |
| 1507 | /* Ring <ringno> handler: unexpected |
| 1508 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1509 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1510 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1511 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1512 | pring->ringno, Rctl, Type); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1514 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1515 | } |
| 1516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1518 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1519 | * @phba: Pointer to HBA context object. |
| 1520 | * @pring: Pointer to driver SLI ring object. |
| 1521 | * @prspiocb: Pointer to response iocb object. |
| 1522 | * |
| 1523 | * This function looks up the iocb_lookup table to get the command iocb |
| 1524 | * corresponding to the given response iocb using the iotag of the |
| 1525 | * response iocb. This function is called with the hbalock held. |
| 1526 | * This function returns the command iocb object if it finds the command |
| 1527 | * iocb else returns NULL. |
| 1528 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1529 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1530 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1531 | struct lpfc_sli_ring *pring, |
| 1532 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1533 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1535 | uint16_t iotag; |
| 1536 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1537 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1539 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1540 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1541 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1542 | pring->txcmplq_cnt--; |
| 1543 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | } |
| 1545 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1547 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1548 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1549 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1550 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | return NULL; |
| 1552 | } |
| 1553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1555 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1556 | * @phba: Pointer to HBA context object. |
| 1557 | * @pring: Pointer to driver SLI ring object. |
| 1558 | * @saveq: Pointer to the response iocb to be processed. |
| 1559 | * |
| 1560 | * This function is called by the ring event handler for non-fcp |
| 1561 | * rings when there is a new response iocb in the response ring. |
| 1562 | * The caller is not required to hold any locks. This function |
| 1563 | * gets the command iocb associated with the response iocb and |
| 1564 | * calls the completion handler for the command iocb. If there |
| 1565 | * is no completion handler, the function will free the resources |
| 1566 | * associated with command iocb. If the response iocb is for |
| 1567 | * an already aborted command iocb, the status of the completion |
| 1568 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1569 | * This function always returns 1. |
| 1570 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1573 | struct lpfc_iocbq *saveq) |
| 1574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1575 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1576 | int rc = 1; |
| 1577 | unsigned long iflag; |
| 1578 | |
| 1579 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1580 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1581 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1582 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | if (cmdiocbp) { |
| 1585 | if (cmdiocbp->iocb_cmpl) { |
| 1586 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1587 | * If an ELS command failed send an event to mgmt |
| 1588 | * application. |
| 1589 | */ |
| 1590 | if (saveq->iocb.ulpStatus && |
| 1591 | (pring->ringno == LPFC_ELS_RING) && |
| 1592 | (cmdiocbp->iocb.ulpCommand == |
| 1593 | CMD_ELS_REQUEST64_CR)) |
| 1594 | lpfc_send_els_failure_event(phba, |
| 1595 | cmdiocbp, saveq); |
| 1596 | |
| 1597 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | * Post all ELS completions to the worker thread. |
| 1599 | * All other are passed to the completion callback. |
| 1600 | */ |
| 1601 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1602 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1603 | cmdiocbp->iocb_flag &= |
| 1604 | ~LPFC_DRIVER_ABORTED; |
| 1605 | saveq->iocb.ulpStatus = |
| 1606 | IOSTAT_LOCAL_REJECT; |
| 1607 | saveq->iocb.un.ulpWord[4] = |
| 1608 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1609 | |
| 1610 | /* Firmware could still be in progress |
| 1611 | * of DMAing payload, so don't free data |
| 1612 | * buffer till after a hbeat. |
| 1613 | */ |
| 1614 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1615 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1618 | } else |
| 1619 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | } else { |
| 1621 | /* |
| 1622 | * Unknown initiating command based on the response iotag. |
| 1623 | * This could be the case on the ELS ring because of |
| 1624 | * lpfc_els_abort(). |
| 1625 | */ |
| 1626 | if (pring->ringno != LPFC_ELS_RING) { |
| 1627 | /* |
| 1628 | * Ring <ringno> handler: unexpected completion IoTag |
| 1629 | * <IoTag> |
| 1630 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 1631 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1632 | "0322 Ring %d handler: " |
| 1633 | "unexpected completion IoTag x%x " |
| 1634 | "Data: x%x x%x x%x x%x\n", |
| 1635 | pring->ringno, |
| 1636 | saveq->iocb.ulpIoTag, |
| 1637 | saveq->iocb.ulpStatus, |
| 1638 | saveq->iocb.un.ulpWord[4], |
| 1639 | saveq->iocb.ulpCommand, |
| 1640 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | } |
| 1642 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1643 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | return rc; |
| 1645 | } |
| 1646 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1648 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1649 | * @phba: Pointer to HBA context object. |
| 1650 | * @pring: Pointer to driver SLI ring object. |
| 1651 | * |
| 1652 | * This function is called from the iocb ring event handlers when |
| 1653 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1654 | * an error attention condition to the worker thread and the worker |
| 1655 | * thread will transition the HBA to offline state. |
| 1656 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | static void |
| 1658 | 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] | 1659 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1660 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1661 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1662 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1663 | * rsp ring <portRspMax> |
| 1664 | */ |
| 1665 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1666 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1667 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1668 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1669 | pring->numRiocb); |
| 1670 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1671 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1672 | |
| 1673 | /* |
| 1674 | * All error attention handlers are posted to |
| 1675 | * worker thread |
| 1676 | */ |
| 1677 | phba->work_ha |= HA_ERATT; |
| 1678 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1679 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1680 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1681 | |
| 1682 | return; |
| 1683 | } |
| 1684 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1685 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1686 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1687 | * @ptr: Pointer to address of HBA context object. |
| 1688 | * |
| 1689 | * This function is invoked by the Error Attention polling timer when the |
| 1690 | * timer times out. It will check the SLI Error Attention register for |
| 1691 | * possible attention events. If so, it will post an Error Attention event |
| 1692 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1693 | * Error Attention polling timer for the next poll. |
| 1694 | **/ |
| 1695 | void lpfc_poll_eratt(unsigned long ptr) |
| 1696 | { |
| 1697 | struct lpfc_hba *phba; |
| 1698 | uint32_t eratt = 0; |
| 1699 | |
| 1700 | phba = (struct lpfc_hba *)ptr; |
| 1701 | |
| 1702 | /* Check chip HA register for error event */ |
| 1703 | eratt = lpfc_sli_check_eratt(phba); |
| 1704 | |
| 1705 | if (eratt) |
| 1706 | /* Tell the worker thread there is work to do */ |
| 1707 | lpfc_worker_wake_up(phba); |
| 1708 | else |
| 1709 | /* Restart the timer for next eratt poll */ |
| 1710 | mod_timer(&phba->eratt_poll, jiffies + |
| 1711 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
| 1715 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1716 | * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1717 | * @phba: Pointer to HBA context object. |
| 1718 | * |
| 1719 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1720 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1721 | * is enabled. |
| 1722 | * |
| 1723 | * The caller does not hold any lock. |
| 1724 | * The function processes each response iocb in the response ring until it |
| 1725 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1726 | * LE bit set. The function will call the completion handler of the command iocb |
| 1727 | * if the response iocb indicates a completion for a command iocb or it is |
| 1728 | * an abort completion. |
| 1729 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1731 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | struct lpfc_sli *psli = &phba->sli; |
| 1733 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1734 | IOCB_t *irsp = NULL; |
| 1735 | IOCB_t *entry = NULL; |
| 1736 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1737 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1738 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1739 | uint32_t status; |
| 1740 | uint32_t portRspPut, portRspMax; |
| 1741 | int type; |
| 1742 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1743 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1745 | |
| 1746 | pring->stats.iocb_event++; |
| 1747 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1748 | /* |
| 1749 | * The next available response entry should never exceed the maximum |
| 1750 | * entries. If it does, treat it as an adapter hardware error. |
| 1751 | */ |
| 1752 | portRspMax = pring->numRiocb; |
| 1753 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1754 | if (unlikely(portRspPut >= portRspMax)) { |
| 1755 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | rmb(); |
| 1760 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1761 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1762 | if (++pring->rspidx >= portRspMax) |
| 1763 | pring->rspidx = 0; |
| 1764 | |
| 1765 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1766 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1768 | irsp = &rspiocbq.iocb; |
| 1769 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1770 | pring->stats.iocb_rsp++; |
| 1771 | rsp_cmpl++; |
| 1772 | |
| 1773 | if (unlikely(irsp->ulpStatus)) { |
| 1774 | /* Rsp ring <ringno> error: IOCB */ |
| 1775 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1776 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1777 | "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] | 1778 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1779 | irsp->un.ulpWord[0], |
| 1780 | irsp->un.ulpWord[1], |
| 1781 | irsp->un.ulpWord[2], |
| 1782 | irsp->un.ulpWord[3], |
| 1783 | irsp->un.ulpWord[4], |
| 1784 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1785 | *(uint32_t *)&irsp->un1, |
| 1786 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | switch (type) { |
| 1790 | case LPFC_ABORT_IOCB: |
| 1791 | case LPFC_SOL_IOCB: |
| 1792 | /* |
| 1793 | * Idle exchange closed via ABTS from port. No iocb |
| 1794 | * resources need to be recovered. |
| 1795 | */ |
| 1796 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1797 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1798 | "0314 IOCB cmd 0x%x " |
| 1799 | "processed. Skipping " |
| 1800 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1801 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1802 | break; |
| 1803 | } |
| 1804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1805 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1806 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1807 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1809 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1810 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1811 | &rspiocbq); |
| 1812 | } |
| 1813 | break; |
| 1814 | default: |
| 1815 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1816 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1817 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1818 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1819 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1820 | dev_warn(&((phba->pcidev)->dev), |
| 1821 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1822 | phba->brd_no, adaptermsg); |
| 1823 | } else { |
| 1824 | /* Unknown IOCB command */ |
| 1825 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1826 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1827 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1828 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1829 | irsp->ulpStatus, |
| 1830 | irsp->ulpIoTag, |
| 1831 | irsp->ulpContext); |
| 1832 | } |
| 1833 | break; |
| 1834 | } |
| 1835 | |
| 1836 | /* |
| 1837 | * The response IOCB has been processed. Update the ring |
| 1838 | * pointer in SLIM. If the port response put pointer has not |
| 1839 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1840 | * response put pointer. |
| 1841 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1842 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1843 | |
| 1844 | if (pring->rspidx == portRspPut) |
| 1845 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1846 | } |
| 1847 | |
| 1848 | ha_copy = readl(phba->HAregaddr); |
| 1849 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1850 | |
| 1851 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1852 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1853 | pring->stats.iocb_rsp_full++; |
| 1854 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1855 | writel(status, phba->CAregaddr); |
| 1856 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1858 | } |
| 1859 | if ((ha_copy & HA_R0CE_RSP) && |
| 1860 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1861 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1862 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1863 | pring->stats.iocb_cmd_empty++; |
| 1864 | |
| 1865 | /* Force update of the local copy of cmdGetInx */ |
| 1866 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1867 | lpfc_sli_resume_iocb(phba, pring); |
| 1868 | |
| 1869 | if ((pring->lpfc_sli_cmd_available)) |
| 1870 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1871 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1872 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | return; |
| 1876 | } |
| 1877 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1878 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1879 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1880 | * @phba: Pointer to HBA context object. |
| 1881 | * @pring: Pointer to driver SLI ring object. |
| 1882 | * @mask: Host attention register mask for this ring. |
| 1883 | * |
| 1884 | * This function is called from the interrupt context when there is a ring |
| 1885 | * event for the fcp ring. The caller does not hold any lock. |
| 1886 | * The function processes each response iocb in the response ring until it |
| 1887 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1888 | * LE bit set. The function will call the completion handler of the command iocb |
| 1889 | * if the response iocb indicates a completion for a command iocb or it is |
| 1890 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1891 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1893 | * to check it explicitly. This function always returns 1. |
| 1894 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1895 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1896 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1897 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1899 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1901 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1903 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | uint32_t status; |
| 1905 | uint32_t portRspPut, portRspMax; |
| 1906 | int rc = 1; |
| 1907 | lpfc_iocb_type type; |
| 1908 | unsigned long iflag; |
| 1909 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1911 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | pring->stats.iocb_event++; |
| 1913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | /* |
| 1915 | * The next available response entry should never exceed the maximum |
| 1916 | * entries. If it does, treat it as an adapter hardware error. |
| 1917 | */ |
| 1918 | portRspMax = pring->numRiocb; |
| 1919 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1920 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1921 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | return 1; |
| 1924 | } |
| 1925 | |
| 1926 | rmb(); |
| 1927 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1928 | /* |
| 1929 | * Fetch an entry off the ring and copy it into a local data |
| 1930 | * structure. The copy involves a byte-swap since the |
| 1931 | * network byte order and pci byte orders are different. |
| 1932 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1933 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1934 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1935 | |
| 1936 | if (++pring->rspidx >= portRspMax) |
| 1937 | pring->rspidx = 0; |
| 1938 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1939 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1940 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1942 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1943 | irsp = &rspiocbq.iocb; |
| 1944 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1946 | pring->stats.iocb_rsp++; |
| 1947 | rsp_cmpl++; |
| 1948 | |
| 1949 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | /* |
| 1951 | * If resource errors reported from HBA, reduce |
| 1952 | * queuedepths of the SCSI device. |
| 1953 | */ |
| 1954 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1955 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1956 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 1957 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1958 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1959 | } |
| 1960 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | /* Rsp ring <ringno> error: IOCB */ |
| 1962 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1963 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1964 | "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] | 1965 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1966 | irsp->un.ulpWord[0], |
| 1967 | irsp->un.ulpWord[1], |
| 1968 | irsp->un.ulpWord[2], |
| 1969 | irsp->un.ulpWord[3], |
| 1970 | irsp->un.ulpWord[4], |
| 1971 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1972 | *(uint32_t *)&irsp->un1, |
| 1973 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | switch (type) { |
| 1977 | case LPFC_ABORT_IOCB: |
| 1978 | case LPFC_SOL_IOCB: |
| 1979 | /* |
| 1980 | * Idle exchange closed via ABTS from port. No iocb |
| 1981 | * resources need to be recovered. |
| 1982 | */ |
| 1983 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1984 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1985 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1986 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1987 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1988 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | break; |
| 1990 | } |
| 1991 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1992 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1993 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1995 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 1996 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1997 | &rspiocbq); |
| 1998 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1999 | spin_unlock_irqrestore(&phba->hbalock, |
| 2000 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2001 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2002 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2003 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2004 | iflag); |
| 2005 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | } |
| 2007 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2008 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2010 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2011 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2012 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | default: |
| 2014 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2015 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2016 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2017 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2018 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2019 | dev_warn(&((phba->pcidev)->dev), |
| 2020 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | phba->brd_no, adaptermsg); |
| 2022 | } else { |
| 2023 | /* Unknown IOCB command */ |
| 2024 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2025 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2026 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2027 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2028 | irsp->ulpStatus, |
| 2029 | irsp->ulpIoTag, |
| 2030 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2031 | } |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | /* |
| 2036 | * The response IOCB has been processed. Update the ring |
| 2037 | * pointer in SLIM. If the port response put pointer has not |
| 2038 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2039 | * response put pointer. |
| 2040 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2041 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | |
| 2043 | if (pring->rspidx == portRspPut) |
| 2044 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2045 | } |
| 2046 | |
| 2047 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2048 | pring->stats.iocb_rsp_full++; |
| 2049 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2050 | writel(status, phba->CAregaddr); |
| 2051 | readl(phba->CAregaddr); |
| 2052 | } |
| 2053 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2054 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2055 | pring->stats.iocb_cmd_empty++; |
| 2056 | |
| 2057 | /* Force update of the local copy of cmdGetInx */ |
| 2058 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2059 | lpfc_sli_resume_iocb(phba, pring); |
| 2060 | |
| 2061 | if ((pring->lpfc_sli_cmd_available)) |
| 2062 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2063 | |
| 2064 | } |
| 2065 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2066 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | return rc; |
| 2068 | } |
| 2069 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2070 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2071 | * lpfc_sli_handle_slow_ring_event - Handle ring events for non-FCP rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2072 | * @phba: Pointer to HBA context object. |
| 2073 | * @pring: Pointer to driver SLI ring object. |
| 2074 | * @mask: Host attention register mask for this ring. |
| 2075 | * |
| 2076 | * This function is called from the worker thread when there is a ring |
| 2077 | * event for non-fcp rings. The caller does not hold any lock . |
| 2078 | * The function processes each response iocb in the response ring until it |
| 2079 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2080 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the |
| 2081 | * response iocb indicates a completion of a command iocb. The function |
| 2082 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited |
| 2083 | * iocb. The function frees the resources or calls the completion handler if |
| 2084 | * this iocb is an abort completion. The function returns 0 when the allocated |
| 2085 | * iocbs are not freed, otherwise returns 1. |
| 2086 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2088 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2089 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2091 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | IOCB_t *entry; |
| 2093 | IOCB_t *irsp = NULL; |
| 2094 | struct lpfc_iocbq *rspiocbp = NULL; |
| 2095 | struct lpfc_iocbq *next_iocb; |
| 2096 | struct lpfc_iocbq *cmdiocbp; |
| 2097 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | uint8_t iocb_cmd_type; |
| 2099 | lpfc_iocb_type type; |
| 2100 | uint32_t status, free_saveq; |
| 2101 | uint32_t portRspPut, portRspMax; |
| 2102 | int rc = 1; |
| 2103 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2105 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | pring->stats.iocb_event++; |
| 2108 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | /* |
| 2110 | * The next available response entry should never exceed the maximum |
| 2111 | * entries. If it does, treat it as an adapter hardware error. |
| 2112 | */ |
| 2113 | portRspMax = pring->numRiocb; |
| 2114 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2115 | if (portRspPut >= portRspMax) { |
| 2116 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2117 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | * rsp ring <portRspMax> |
| 2119 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2120 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2121 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2122 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2123 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | phba->link_state = LPFC_HBA_ERROR; |
| 2126 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | |
| 2128 | phba->work_hs = HS_FFER3; |
| 2129 | lpfc_handle_eratt(phba); |
| 2130 | |
| 2131 | return 1; |
| 2132 | } |
| 2133 | |
| 2134 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | while (pring->rspidx != portRspPut) { |
| 2136 | /* |
| 2137 | * Build a completion list and call the appropriate handler. |
| 2138 | * The process is to get the next available response iocb, get |
| 2139 | * a free iocb from the list, copy the response data into the |
| 2140 | * free iocb, insert to the continuation list, and update the |
| 2141 | * next response index to slim. This process makes response |
| 2142 | * iocb's in the ring available to DMA as fast as possible but |
| 2143 | * pays a penalty for a copy operation. Since the iocb is |
| 2144 | * only 32 bytes, this penalty is considered small relative to |
| 2145 | * the PCI reads for register values and a slim write. When |
| 2146 | * the ulpLe field is set, the entire Command has been |
| 2147 | * received. |
| 2148 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2149 | entry = lpfc_resp_iocb(phba, pring); |
| 2150 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2151 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | if (rspiocbp == NULL) { |
| 2154 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2155 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | break; |
| 2157 | } |
| 2158 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2159 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2160 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | irsp = &rspiocbp->iocb; |
| 2162 | |
| 2163 | if (++pring->rspidx >= portRspMax) |
| 2164 | pring->rspidx = 0; |
| 2165 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2166 | if (pring->ringno == LPFC_ELS_RING) { |
| 2167 | lpfc_debugfs_slow_ring_trc(phba, |
| 2168 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2169 | *(((uint32_t *) irsp) + 4), |
| 2170 | *(((uint32_t *) irsp) + 6), |
| 2171 | *(((uint32_t *) irsp) + 7)); |
| 2172 | } |
| 2173 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2174 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2176 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | |
| 2178 | pring->iocb_continueq_cnt++; |
| 2179 | if (irsp->ulpLe) { |
| 2180 | /* |
| 2181 | * By default, the driver expects to free all resources |
| 2182 | * associated with this iocb completion. |
| 2183 | */ |
| 2184 | free_saveq = 1; |
| 2185 | saveq = list_get_first(&pring->iocb_continueq, |
| 2186 | struct lpfc_iocbq, list); |
| 2187 | irsp = &(saveq->iocb); |
| 2188 | list_del_init(&pring->iocb_continueq); |
| 2189 | pring->iocb_continueq_cnt = 0; |
| 2190 | |
| 2191 | pring->stats.iocb_rsp++; |
| 2192 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | /* |
| 2194 | * If resource errors reported from HBA, reduce |
| 2195 | * queuedepths of the SCSI device. |
| 2196 | */ |
| 2197 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2198 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2199 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2200 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2201 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2202 | } |
| 2203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | if (irsp->ulpStatus) { |
| 2205 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2206 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2207 | "0328 Rsp Ring %d error: " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2208 | "IOCB Data: " |
| 2209 | "x%x x%x x%x x%x " |
| 2210 | "x%x x%x x%x x%x " |
| 2211 | "x%x x%x x%x x%x " |
| 2212 | "x%x x%x x%x x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2213 | pring->ringno, |
| 2214 | irsp->un.ulpWord[0], |
| 2215 | irsp->un.ulpWord[1], |
| 2216 | irsp->un.ulpWord[2], |
| 2217 | irsp->un.ulpWord[3], |
| 2218 | irsp->un.ulpWord[4], |
| 2219 | irsp->un.ulpWord[5], |
| 2220 | *(((uint32_t *) irsp) + 6), |
| 2221 | *(((uint32_t *) irsp) + 7), |
| 2222 | *(((uint32_t *) irsp) + 8), |
| 2223 | *(((uint32_t *) irsp) + 9), |
| 2224 | *(((uint32_t *) irsp) + 10), |
| 2225 | *(((uint32_t *) irsp) + 11), |
| 2226 | *(((uint32_t *) irsp) + 12), |
| 2227 | *(((uint32_t *) irsp) + 13), |
| 2228 | *(((uint32_t *) irsp) + 14), |
| 2229 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /* |
| 2233 | * Fetch the IOCB command type and call the correct |
| 2234 | * completion routine. Solicited and Unsolicited |
| 2235 | * IOCBs on the ELS ring get freed back to the |
| 2236 | * lpfc_iocb_list by the discovery kernel thread. |
| 2237 | */ |
| 2238 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2239 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2240 | if (type == LPFC_SOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2241 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2243 | saveq); |
| 2244 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2246 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2248 | saveq); |
| 2249 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2250 | if (!rc) |
| 2251 | free_saveq = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | } else if (type == LPFC_ABORT_IOCB) { |
| 2253 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 2254 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2255 | lpfc_sli_iocbq_lookup(phba, pring, |
| 2256 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | /* Call the specified completion |
| 2258 | routine */ |
| 2259 | if (cmdiocbp->iocb_cmpl) { |
| 2260 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2261 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | iflag); |
| 2263 | (cmdiocbp->iocb_cmpl) (phba, |
| 2264 | cmdiocbp, saveq); |
| 2265 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2266 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2268 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2270 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | } |
| 2272 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 2273 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2274 | |
| 2275 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2276 | |
| 2277 | memset(adaptermsg, 0, |
| 2278 | LPFC_MAX_ADPTMSG); |
| 2279 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2280 | MAX_MSG_DATA); |
| 2281 | dev_warn(&((phba->pcidev)->dev), |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2282 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | phba->brd_no, adaptermsg); |
| 2284 | } else { |
| 2285 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2286 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2287 | "0335 Unknown IOCB " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | "command Data: x%x " |
| 2289 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2290 | irsp->ulpCommand, |
| 2291 | irsp->ulpStatus, |
| 2292 | irsp->ulpIoTag, |
| 2293 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2298 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2299 | &saveq->list, list) { |
| 2300 | list_del(&rspiocbp->list); |
| 2301 | __lpfc_sli_release_iocbq(phba, |
| 2302 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | /* |
| 2310 | * If the port response put pointer has not been updated, sync |
| 2311 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2312 | * response put pointer. |
| 2313 | */ |
| 2314 | if (pring->rspidx == portRspPut) { |
| 2315 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2316 | } |
| 2317 | } /* while (pring->rspidx != portRspPut) */ |
| 2318 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2319 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2320 | /* At least one response entry has been freed */ |
| 2321 | pring->stats.iocb_rsp_full++; |
| 2322 | /* SET RxRE_RSP in Chip Att register */ |
| 2323 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2324 | writel(status, phba->CAregaddr); |
| 2325 | readl(phba->CAregaddr); /* flush */ |
| 2326 | } |
| 2327 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2328 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2329 | pring->stats.iocb_cmd_empty++; |
| 2330 | |
| 2331 | /* Force update of the local copy of cmdGetInx */ |
| 2332 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2333 | lpfc_sli_resume_iocb(phba, pring); |
| 2334 | |
| 2335 | if ((pring->lpfc_sli_cmd_available)) |
| 2336 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2337 | |
| 2338 | } |
| 2339 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2340 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | return rc; |
| 2342 | } |
| 2343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2344 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2345 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2346 | * @phba: Pointer to HBA context object. |
| 2347 | * @pring: Pointer to driver SLI ring object. |
| 2348 | * |
| 2349 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2350 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2351 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2352 | * the return of this function. The caller is not required to hold any locks. |
| 2353 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2354 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2356 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2357 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2360 | if (pring->ringno == LPFC_ELS_RING) { |
| 2361 | lpfc_fabric_abort_hba(phba); |
| 2362 | } |
| 2363 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | /* Error everything on txq and txcmplq |
| 2365 | * First do the txq. |
| 2366 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2367 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2368 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | |
| 2371 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2372 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2373 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2374 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2375 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2376 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 2377 | /* Cancel all the IOCBs from the completions list */ |
| 2378 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 2379 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | } |
| 2381 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2382 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2383 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2384 | * @phba: Pointer to HBA context object. |
| 2385 | * |
| 2386 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2387 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2388 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2389 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2390 | * slot has been permanently disabled. |
| 2391 | **/ |
| 2392 | void |
| 2393 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2394 | { |
| 2395 | LIST_HEAD(txq); |
| 2396 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2397 | struct lpfc_sli *psli = &phba->sli; |
| 2398 | struct lpfc_sli_ring *pring; |
| 2399 | |
| 2400 | /* Currently, only one fcp ring */ |
| 2401 | pring = &psli->ring[psli->fcp_ring]; |
| 2402 | |
| 2403 | spin_lock_irq(&phba->hbalock); |
| 2404 | /* Retrieve everything on txq */ |
| 2405 | list_splice_init(&pring->txq, &txq); |
| 2406 | pring->txq_cnt = 0; |
| 2407 | |
| 2408 | /* Retrieve everything on the txcmplq */ |
| 2409 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2410 | pring->txcmplq_cnt = 0; |
| 2411 | spin_unlock_irq(&phba->hbalock); |
| 2412 | |
| 2413 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 2414 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 2415 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2416 | |
| 2417 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 2418 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 2419 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2423 | * lpfc_sli_brdready - Check for host status bits |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2424 | * @phba: Pointer to HBA context object. |
| 2425 | * @mask: Bit mask to be checked. |
| 2426 | * |
| 2427 | * This function reads the host status register and compares |
| 2428 | * with the provided bit mask to check if HBA completed |
| 2429 | * the restart. This function will wait in a loop for the |
| 2430 | * HBA to complete restart. If the HBA does not restart within |
| 2431 | * 15 iterations, the function will reset the HBA again. The |
| 2432 | * function returns 1 when HBA fail to restart otherwise returns |
| 2433 | * zero. |
| 2434 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2435 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2438 | uint32_t status; |
| 2439 | int i = 0; |
| 2440 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2442 | /* Read the HBA Host Status Register */ |
| 2443 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2445 | /* |
| 2446 | * Check status register every 100ms for 5 retries, then every |
| 2447 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2448 | * every 2.5 sec for 4. |
| 2449 | * Break our of the loop if errors occurred during init. |
| 2450 | */ |
| 2451 | while (((status & mask) != mask) && |
| 2452 | !(status & HS_FFERM) && |
| 2453 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2455 | if (i <= 5) |
| 2456 | msleep(10); |
| 2457 | else if (i <= 10) |
| 2458 | msleep(500); |
| 2459 | else |
| 2460 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2462 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2463 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2464 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2465 | lpfc_sli_brdrestart(phba); |
| 2466 | } |
| 2467 | /* Read the HBA Host Status Register */ |
| 2468 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2470 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2471 | /* Check to see if any errors occurred during init */ |
| 2472 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2474 | retval = 1; |
| 2475 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2477 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | } |
| 2479 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2480 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2483 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2484 | * @phba: Pointer to HBA context object. |
| 2485 | * |
| 2486 | * This function is called before resetting an HBA. This |
| 2487 | * function requests HBA to quiesce DMAs before a reset. |
| 2488 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2490 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2491 | uint32_t __iomem *resp_buf; |
| 2492 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2493 | volatile uint32_t mbox; |
| 2494 | uint32_t hc_copy; |
| 2495 | int i; |
| 2496 | uint8_t hdrtype; |
| 2497 | |
| 2498 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2499 | if (hdrtype != 0x80 || |
| 2500 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2501 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2502 | return; |
| 2503 | |
| 2504 | /* |
| 2505 | * Tell the other part of the chip to suspend temporarily all |
| 2506 | * its DMA activity. |
| 2507 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2508 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2509 | |
| 2510 | /* Disable the error attention */ |
| 2511 | hc_copy = readl(phba->HCregaddr); |
| 2512 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2513 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2515 | |
| 2516 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2517 | /* Clear Chip error bit */ |
| 2518 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2519 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | mbox = 0; |
| 2523 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2524 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2525 | |
| 2526 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2527 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2528 | writel(mbox, mbox_buf); |
| 2529 | |
| 2530 | for (i = 0; |
| 2531 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2532 | mdelay(1); |
| 2533 | |
| 2534 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2535 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2537 | goto restore_hc; |
| 2538 | else |
| 2539 | goto clear_errat; |
| 2540 | } |
| 2541 | |
| 2542 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2543 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2544 | mdelay(1); |
| 2545 | |
| 2546 | clear_errat: |
| 2547 | |
| 2548 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2549 | mdelay(1); |
| 2550 | |
| 2551 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2552 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2553 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2558 | writel(hc_copy, phba->HCregaddr); |
| 2559 | readl(phba->HCregaddr); /* flush */ |
| 2560 | } |
| 2561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2563 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2564 | * @phba: Pointer to HBA context object. |
| 2565 | * |
| 2566 | * This function issues a kill_board mailbox command and waits for |
| 2567 | * the error attention interrupt. This function is called for stopping |
| 2568 | * the firmware processing. The caller is not required to hold any |
| 2569 | * locks. This function calls lpfc_hba_down_post function to free |
| 2570 | * any pending commands after the kill. The function will return 1 when it |
| 2571 | * fails to kill the board else will return 0. |
| 2572 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2573 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2576 | struct lpfc_sli *psli; |
| 2577 | LPFC_MBOXQ_t *pmb; |
| 2578 | uint32_t status; |
| 2579 | uint32_t ha_copy; |
| 2580 | int retval; |
| 2581 | int i = 0; |
| 2582 | |
| 2583 | psli = &phba->sli; |
| 2584 | |
| 2585 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2586 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2587 | "0329 Kill HBA Data: x%x x%x\n", |
| 2588 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2589 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2590 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2591 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2592 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2593 | |
| 2594 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2596 | status = readl(phba->HCregaddr); |
| 2597 | status &= ~HC_ERINT_ENA; |
| 2598 | writel(status, phba->HCregaddr); |
| 2599 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2601 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2602 | |
| 2603 | lpfc_kill_board(phba, pmb); |
| 2604 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2605 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2606 | |
| 2607 | if (retval != MBX_SUCCESS) { |
| 2608 | if (retval != MBX_BUSY) |
| 2609 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2610 | spin_lock_irq(&phba->hbalock); |
| 2611 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2612 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2613 | return 1; |
| 2614 | } |
| 2615 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2616 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2617 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2618 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2619 | |
| 2620 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2621 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2622 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2623 | * board is now undefined. |
| 2624 | */ |
| 2625 | ha_copy = readl(phba->HAregaddr); |
| 2626 | |
| 2627 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2628 | mdelay(100); |
| 2629 | ha_copy = readl(phba->HAregaddr); |
| 2630 | } |
| 2631 | |
| 2632 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2633 | if (ha_copy & HA_ERATT) { |
| 2634 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2636 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2638 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2639 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2640 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2641 | |
| 2642 | psli->mbox_active = NULL; |
| 2643 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2645 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2647 | } |
| 2648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2649 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2650 | * lpfc_sli_brdreset - Reset the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2651 | * @phba: Pointer to HBA context object. |
| 2652 | * |
| 2653 | * This function resets the HBA by writing HC_INITFF to the control |
| 2654 | * register. After the HBA resets, this function resets all the iocb ring |
| 2655 | * indices. This function disables PCI layer parity checking during |
| 2656 | * the reset. |
| 2657 | * This function returns 0 always. |
| 2658 | * The caller is not required to hold any locks. |
| 2659 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2660 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2661 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2662 | { |
| 2663 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2665 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2668 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2670 | /* Reset HBA */ |
| 2671 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2672 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | |
| 2675 | /* perform board reset */ |
| 2676 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | phba->pport->fc_myDID = 0; |
| 2678 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2680 | /* Turn off parity checking and serr during the physical reset */ |
| 2681 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2682 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2683 | (cfg_value & |
| 2684 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2685 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2686 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2687 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2688 | writel(HC_INITFF, phba->HCregaddr); |
| 2689 | mdelay(1); |
| 2690 | readl(phba->HCregaddr); /* flush */ |
| 2691 | writel(0, phba->HCregaddr); |
| 2692 | readl(phba->HCregaddr); /* flush */ |
| 2693 | |
| 2694 | /* Restore PCI cmd register */ |
| 2695 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | |
| 2697 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2698 | for (i = 0; i < psli->num_rings; i++) { |
| 2699 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | pring->flag = 0; |
| 2701 | pring->rspidx = 0; |
| 2702 | pring->next_cmdidx = 0; |
| 2703 | pring->local_getidx = 0; |
| 2704 | pring->cmdidx = 0; |
| 2705 | pring->missbufcnt = 0; |
| 2706 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2708 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2709 | return 0; |
| 2710 | } |
| 2711 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2712 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2713 | * lpfc_sli_brdrestart - Restart the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2714 | * @phba: Pointer to HBA context object. |
| 2715 | * |
| 2716 | * This function is called in the SLI initialization code path to |
| 2717 | * restart the HBA. The caller is not required to hold any lock. |
| 2718 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2719 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2720 | * function to free any pending commands. The function enables |
| 2721 | * POST only during the first initialization. The function returns zero. |
| 2722 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2723 | * command before the return of this function. |
| 2724 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2725 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2726 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2727 | { |
| 2728 | MAILBOX_t *mb; |
| 2729 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2730 | volatile uint32_t word0; |
| 2731 | void __iomem *to_slim; |
| 2732 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2733 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2734 | |
| 2735 | psli = &phba->sli; |
| 2736 | |
| 2737 | /* Restart HBA */ |
| 2738 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2739 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2741 | |
| 2742 | word0 = 0; |
| 2743 | mb = (MAILBOX_t *) &word0; |
| 2744 | mb->mbxCommand = MBX_RESTART; |
| 2745 | mb->mbxHc = 1; |
| 2746 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2747 | lpfc_reset_barrier(phba); |
| 2748 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2749 | to_slim = phba->MBslimaddr; |
| 2750 | writel(*(uint32_t *) mb, to_slim); |
| 2751 | readl(to_slim); /* flush */ |
| 2752 | |
| 2753 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2754 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2755 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2756 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2757 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2758 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2759 | writel(*(uint32_t *) mb, to_slim); |
| 2760 | readl(to_slim); /* flush */ |
| 2761 | |
| 2762 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2763 | phba->pport->stopped = 0; |
| 2764 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2765 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2766 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2767 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2768 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2769 | psli->stats_start = get_seconds(); |
| 2770 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2771 | /* Give the INITFF and Post time to settle. */ |
| 2772 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2774 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | |
| 2776 | return 0; |
| 2777 | } |
| 2778 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2780 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2781 | * @phba: Pointer to HBA context object. |
| 2782 | * |
| 2783 | * This function is called after a HBA restart to wait for successful |
| 2784 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2785 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2786 | * iteration, the function will restart the HBA again. The function returns |
| 2787 | * zero if HBA successfully restarted else returns negative error code. |
| 2788 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | static int |
| 2790 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2791 | { |
| 2792 | uint32_t status, i = 0; |
| 2793 | |
| 2794 | /* Read the HBA Host Status Register */ |
| 2795 | status = readl(phba->HSregaddr); |
| 2796 | |
| 2797 | /* Check status register to see what current state is */ |
| 2798 | i = 0; |
| 2799 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2800 | |
| 2801 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2802 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2803 | * 4. |
| 2804 | */ |
| 2805 | if (i++ >= 20) { |
| 2806 | /* Adapter failed to init, timeout, status reg |
| 2807 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2808 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2809 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2810 | "timeout, status reg x%x, " |
| 2811 | "FW Data: A8 x%x AC x%x\n", status, |
| 2812 | readl(phba->MBslimaddr + 0xa8), |
| 2813 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2814 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | return -ETIMEDOUT; |
| 2816 | } |
| 2817 | |
| 2818 | /* Check to see if any errors occurred during init */ |
| 2819 | if (status & HS_FFERM) { |
| 2820 | /* ERROR: During chipset initialization */ |
| 2821 | /* Adapter failed to init, chipset, status reg |
| 2822 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2824 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2825 | "chipset, status reg x%x, " |
| 2826 | "FW Data: A8 x%x AC x%x\n", status, |
| 2827 | readl(phba->MBslimaddr + 0xa8), |
| 2828 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2829 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | return -EIO; |
| 2831 | } |
| 2832 | |
| 2833 | if (i <= 5) { |
| 2834 | msleep(10); |
| 2835 | } else if (i <= 10) { |
| 2836 | msleep(500); |
| 2837 | } else { |
| 2838 | msleep(2500); |
| 2839 | } |
| 2840 | |
| 2841 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2842 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2843 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2844 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | } |
| 2846 | /* Read the HBA Host Status Register */ |
| 2847 | status = readl(phba->HSregaddr); |
| 2848 | } |
| 2849 | |
| 2850 | /* Check to see if any errors occurred during init */ |
| 2851 | if (status & HS_FFERM) { |
| 2852 | /* ERROR: During chipset initialization */ |
| 2853 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2855 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2856 | "status reg x%x, " |
| 2857 | "FW Data: A8 x%x AC x%x\n", status, |
| 2858 | readl(phba->MBslimaddr + 0xa8), |
| 2859 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2860 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | return -EIO; |
| 2862 | } |
| 2863 | |
| 2864 | /* Clear all interrupt enable conditions */ |
| 2865 | writel(0, phba->HCregaddr); |
| 2866 | readl(phba->HCregaddr); /* flush */ |
| 2867 | |
| 2868 | /* setup host attn register */ |
| 2869 | writel(0xffffffff, phba->HAregaddr); |
| 2870 | readl(phba->HAregaddr); /* flush */ |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2875 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2876 | * |
| 2877 | * This function calculates and returns the number of HBQs required to be |
| 2878 | * configured. |
| 2879 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2880 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2881 | lpfc_sli_hbq_count(void) |
| 2882 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2883 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2884 | } |
| 2885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2886 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2887 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2888 | * |
| 2889 | * This function adds the number of hbq entries in every HBQ to get |
| 2890 | * the total number of hbq entries required for the HBA and returns |
| 2891 | * the total count. |
| 2892 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2893 | static int |
| 2894 | lpfc_sli_hbq_entry_count(void) |
| 2895 | { |
| 2896 | int hbq_count = lpfc_sli_hbq_count(); |
| 2897 | int count = 0; |
| 2898 | int i; |
| 2899 | |
| 2900 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2901 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2902 | return count; |
| 2903 | } |
| 2904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2906 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2907 | * |
| 2908 | * This function calculates amount of memory required for all hbq entries |
| 2909 | * to be configured and returns the total memory required. |
| 2910 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2911 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2912 | lpfc_sli_hbq_size(void) |
| 2913 | { |
| 2914 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2915 | } |
| 2916 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2917 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2918 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2919 | * @phba: Pointer to HBA context object. |
| 2920 | * |
| 2921 | * This function is called during the SLI initialization to configure |
| 2922 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 2923 | * required to hold any locks. This function will return zero if successful |
| 2924 | * else it will return negative error code. |
| 2925 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2926 | static int |
| 2927 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2928 | { |
| 2929 | int hbq_count = lpfc_sli_hbq_count(); |
| 2930 | LPFC_MBOXQ_t *pmb; |
| 2931 | MAILBOX_t *pmbox; |
| 2932 | uint32_t hbqno; |
| 2933 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2934 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2935 | /* Get a Mailbox buffer to setup mailbox |
| 2936 | * commands for HBA initialization |
| 2937 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2938 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2939 | |
| 2940 | if (!pmb) |
| 2941 | return -ENOMEM; |
| 2942 | |
| 2943 | pmbox = &pmb->mb; |
| 2944 | |
| 2945 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 2946 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2947 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2948 | |
| 2949 | hbq_entry_index = 0; |
| 2950 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2951 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 2952 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 2953 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 2954 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2956 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 2957 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2958 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 2959 | |
| 2960 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 2961 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 2962 | mbxStatus <status>, ring <num> */ |
| 2963 | |
| 2964 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2965 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2966 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2967 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2968 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2969 | pmbox->mbxStatus, hbqno); |
| 2970 | |
| 2971 | phba->link_state = LPFC_HBA_ERROR; |
| 2972 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2973 | return ENXIO; |
| 2974 | } |
| 2975 | } |
| 2976 | phba->hbq_count = hbq_count; |
| 2977 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2978 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2979 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2980 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2981 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 2982 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2983 | return 0; |
| 2984 | } |
| 2985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2987 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2988 | * @phba: Pointer to HBA context object. |
| 2989 | * @sli_mode: sli mode - 2/3 |
| 2990 | * |
| 2991 | * This function is called by the sli intialization code path |
| 2992 | * to issue config_port mailbox command. This function restarts the |
| 2993 | * HBA firmware and issues a config_port mailbox command to configure |
| 2994 | * the SLI interface in the sli mode specified by sli_mode |
| 2995 | * variable. The caller is not required to hold any locks. |
| 2996 | * The function returns 0 if successful, else returns negative error |
| 2997 | * code. |
| 2998 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2999 | int |
| 3000 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | { |
| 3002 | LPFC_MBOXQ_t *pmb; |
| 3003 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3004 | |
| 3005 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3006 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3007 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | return -ENOMEM; |
| 3009 | } |
| 3010 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3011 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3014 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3015 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3016 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3017 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3018 | rc = lpfc_sli_chipset_init(phba); |
| 3019 | if (rc) |
| 3020 | break; |
| 3021 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3023 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3024 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | resetcount++; |
| 3026 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3027 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3028 | * value of 0 means the call was successful. Any other |
| 3029 | * nonzero value is a failure, but if ERESTART is returned, |
| 3030 | * the driver may reset the HBA and try again. |
| 3031 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | rc = lpfc_config_port_prep(phba); |
| 3033 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3034 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3036 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3037 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | lpfc_config_port(phba, pmb); |
| 3040 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3041 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3042 | LPFC_SLI3_HBQ_ENABLED | |
| 3043 | LPFC_SLI3_CRP_ENABLED | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3044 | LPFC_SLI3_INB_ENABLED | |
| 3045 | LPFC_SLI3_BG_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3046 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3048 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3049 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3050 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3051 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3053 | spin_unlock_irq(&phba->hbalock); |
| 3054 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3055 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3056 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3057 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3058 | if (!done) { |
| 3059 | rc = -EINVAL; |
| 3060 | goto do_prep_failed; |
| 3061 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3062 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3063 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3064 | rc = -ENXIO; |
| 3065 | goto do_prep_failed; |
| 3066 | } |
| 3067 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3068 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3069 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3070 | } else |
| 3071 | phba->max_vpi = 0; |
| 3072 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3073 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3074 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3075 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3076 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3077 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3078 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3079 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3080 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3081 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3082 | phba->inb_last_counter = |
| 3083 | phba->mbox->us.s3_inb_pgp.counter; |
| 3084 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3085 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3086 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3087 | phba->inb_ha_copy = NULL; |
| 3088 | phba->inb_counter = NULL; |
| 3089 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3090 | |
| 3091 | if (phba->cfg_enable_bg) { |
| 3092 | if (pmb->mb.un.varCfgPort.gbg) |
| 3093 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 3094 | else |
| 3095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3096 | "0443 Adapter did not grant " |
| 3097 | "BlockGuard\n"); |
| 3098 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3099 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3100 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3101 | phba->port_gp = phba->mbox->us.s2.port; |
| 3102 | phba->inb_ha_copy = NULL; |
| 3103 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3104 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3105 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3106 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3107 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3108 | return rc; |
| 3109 | } |
| 3110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3111 | |
| 3112 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3113 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3114 | * @phba: Pointer to HBA context object. |
| 3115 | * |
| 3116 | * This function is the main SLI intialization function. This function |
| 3117 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3118 | * error attention handler code. Caller is not required to hold any |
| 3119 | * locks. This function issues config_port mailbox command to configure |
| 3120 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3121 | * calls the config_port_post function to issue init_link mailbox |
| 3122 | * command and to start the discovery. The function will return zero |
| 3123 | * if successful, else it will return negative error code. |
| 3124 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3125 | int |
| 3126 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3127 | { |
| 3128 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3129 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3130 | |
| 3131 | switch (lpfc_sli_mode) { |
| 3132 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3133 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3135 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3136 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3137 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3138 | break; |
| 3139 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3140 | mode = 2; |
| 3141 | break; |
| 3142 | case 0: |
| 3143 | case 3: |
| 3144 | break; |
| 3145 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3146 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3147 | "1819 Unrecognized lpfc_sli_mode " |
| 3148 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3149 | |
| 3150 | break; |
| 3151 | } |
| 3152 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3153 | rc = lpfc_sli_config_port(phba, mode); |
| 3154 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3155 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3157 | "1820 Unable to select SLI-3. " |
| 3158 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3159 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3160 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3161 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | goto lpfc_sli_hba_setup_error; |
| 3163 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3164 | if (phba->sli_rev == 3) { |
| 3165 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3166 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3167 | } else { |
| 3168 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3169 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3170 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3174 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3175 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3176 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | |
| 3178 | if (rc) |
| 3179 | goto lpfc_sli_hba_setup_error; |
| 3180 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3181 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3182 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3183 | rc = lpfc_sli_hbq_setup(phba); |
| 3184 | if (rc) |
| 3185 | goto lpfc_sli_hba_setup_error; |
| 3186 | } |
| 3187 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3189 | |
| 3190 | rc = lpfc_config_port_post(phba); |
| 3191 | if (rc) |
| 3192 | goto lpfc_sli_hba_setup_error; |
| 3193 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3194 | return rc; |
| 3195 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3196 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3197 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3198 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3199 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3200 | return rc; |
| 3201 | } |
| 3202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3203 | |
| 3204 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3205 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3206 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3208 | * This is the callback function for mailbox timer. The mailbox |
| 3209 | * timer is armed when a new mailbox command is issued and the timer |
| 3210 | * is deleted when the mailbox complete. The function is called by |
| 3211 | * the kernel timer code when a mailbox does not complete within |
| 3212 | * expected time. This function wakes up the worker thread to |
| 3213 | * process the mailbox timeout and returns. All the processing is |
| 3214 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3215 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | void |
| 3217 | lpfc_mbox_timeout(unsigned long ptr) |
| 3218 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3219 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3220 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3221 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3223 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3224 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3225 | if (!tmo_posted) |
| 3226 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3227 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3228 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3229 | if (!tmo_posted) |
| 3230 | lpfc_worker_wake_up(phba); |
| 3231 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | } |
| 3233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3234 | |
| 3235 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3236 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3237 | * @phba: Pointer to HBA context object. |
| 3238 | * |
| 3239 | * This function is called from worker thread when a mailbox command times out. |
| 3240 | * The caller is not required to hold any locks. This function will reset the |
| 3241 | * HBA and recover all the pending commands. |
| 3242 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | void |
| 3244 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3245 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3246 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3247 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3248 | struct lpfc_sli *psli = &phba->sli; |
| 3249 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3251 | /* Check the pmbox pointer first. There is a race condition |
| 3252 | * between the mbox timeout handler getting executed in the |
| 3253 | * worklist and the mailbox actually completing. When this |
| 3254 | * race condition occurs, the mbox_active will be NULL. |
| 3255 | */ |
| 3256 | spin_lock_irq(&phba->hbalock); |
| 3257 | if (pmbox == NULL) { |
| 3258 | lpfc_printf_log(phba, KERN_WARNING, |
| 3259 | LOG_MBOX | LOG_SLI, |
| 3260 | "0353 Active Mailbox cleared - mailbox timeout " |
| 3261 | "exiting\n"); |
| 3262 | spin_unlock_irq(&phba->hbalock); |
| 3263 | return; |
| 3264 | } |
| 3265 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3267 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3268 | "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] | 3269 | mb->mbxCommand, |
| 3270 | phba->pport->port_state, |
| 3271 | phba->sli.sli_flag, |
| 3272 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3273 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3274 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3275 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3276 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3277 | * it to fail all oustanding SCSI IO. |
| 3278 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3279 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3280 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3281 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3282 | spin_lock_irq(&phba->hbalock); |
| 3283 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3284 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3286 | |
| 3287 | pring = &psli->ring[psli->fcp_ring]; |
| 3288 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3289 | |
| 3290 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3291 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3292 | /* |
| 3293 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 3294 | * on oustanding mailbox commands. |
| 3295 | */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3296 | /* If resets are disabled then set error state and return. */ |
| 3297 | if (!phba->cfg_enable_hba_reset) { |
| 3298 | phba->link_state = LPFC_HBA_ERROR; |
| 3299 | return; |
| 3300 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3301 | lpfc_offline_prep(phba); |
| 3302 | lpfc_offline(phba); |
| 3303 | lpfc_sli_brdrestart(phba); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3304 | lpfc_online(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3305 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | return; |
| 3307 | } |
| 3308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3310 | * lpfc_sli_issue_mbox - Issue a mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3311 | * @phba: Pointer to HBA context object. |
| 3312 | * @pmbox: Pointer to mailbox object. |
| 3313 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3314 | * |
| 3315 | * This function is called by discovery code and HBA management code |
| 3316 | * to submit a mailbox command to firmware. This function gets the |
| 3317 | * hbalock to protect the data structures. |
| 3318 | * The mailbox command can be submitted in polling mode, in which case |
| 3319 | * this function will wait in a polling loop for the completion of the |
| 3320 | * mailbox. |
| 3321 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3322 | * function will submit the command and returns immediately without waiting |
| 3323 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3324 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3325 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3326 | * mailbox is issued in polling mode and there is already a mailbox |
| 3327 | * pending, then the function will return an error. If the mailbox is issued |
| 3328 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3329 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3330 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3331 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3332 | * return codes the caller owns the mailbox command after the return of |
| 3333 | * the function. |
| 3334 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3336 | 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] | 3337 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | uint32_t status, evtctr; |
| 3341 | uint32_t ha_copy; |
| 3342 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3343 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3345 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3347 | int processing_queue = 0; |
| 3348 | |
| 3349 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3350 | if (!pmbox) { |
| 3351 | /* processing mbox queue from intr_handler */ |
| 3352 | processing_queue = 1; |
| 3353 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3354 | pmbox = lpfc_mbox_get(phba); |
| 3355 | if (!pmbox) { |
| 3356 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3357 | return MBX_SUCCESS; |
| 3358 | } |
| 3359 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3360 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3361 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3362 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3363 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3364 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3365 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3366 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3367 | "1806 Mbox x%x failed. No vport\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3368 | pmbox->mb.mbxCommand); |
| 3369 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3370 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3371 | } |
| 3372 | } |
| 3373 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3374 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3375 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3376 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3377 | goto out_not_finished; |
| 3378 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3379 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3380 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 3381 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 3382 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3383 | goto out_not_finished; |
| 3384 | } |
| 3385 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3387 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | mb = &pmbox->mb; |
| 3389 | status = MBX_SUCCESS; |
| 3390 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3392 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3393 | |
| 3394 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3395 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3396 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3397 | } |
| 3398 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3399 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3400 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3401 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3402 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3403 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3404 | } |
| 3405 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3407 | /* Polling for a mbox command when another one is already active |
| 3408 | * is not allowed in SLI. Also, the driver must have established |
| 3409 | * SLI2 mode to queue and process multiple mbox commands. |
| 3410 | */ |
| 3411 | |
| 3412 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3413 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | |
| 3415 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3416 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3417 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3421 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3423 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3424 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | } |
| 3426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | /* Another mailbox command is still being processed, queue this |
| 3428 | * command to be processed later. |
| 3429 | */ |
| 3430 | lpfc_mbox_put(phba, pmbox); |
| 3431 | |
| 3432 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3433 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3434 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3435 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3437 | mb->mbxCommand, phba->pport->port_state, |
| 3438 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | |
| 3440 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3443 | if (pmbox->vport) { |
| 3444 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3445 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3446 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3447 | (uint32_t)mb->mbxCommand, |
| 3448 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3449 | } |
| 3450 | else { |
| 3451 | lpfc_debugfs_disc_trc(phba->pport, |
| 3452 | LPFC_DISC_TRC_MBOX, |
| 3453 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3454 | (uint32_t)mb->mbxCommand, |
| 3455 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3456 | } |
| 3457 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | } |
| 3460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3462 | |
| 3463 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3464 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3465 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 3466 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3468 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3470 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3471 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | } |
| 3473 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3474 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3475 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3479 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3480 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3481 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3482 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3483 | mb->mbxCommand, phba->pport->port_state, |
| 3484 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3486 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3487 | if (pmbox->vport) { |
| 3488 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3489 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3490 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3491 | (uint32_t)mb->mbxCommand, |
| 3492 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3493 | } |
| 3494 | else { |
| 3495 | lpfc_debugfs_disc_trc(phba->pport, |
| 3496 | LPFC_DISC_TRC_MBOX, |
| 3497 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3498 | (uint32_t)mb->mbxCommand, |
| 3499 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3500 | } |
| 3501 | } |
| 3502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | psli->slistat.mbox_cmd++; |
| 3504 | evtctr = psli->slistat.mbox_event; |
| 3505 | |
| 3506 | /* next set own bit for the adapter and copy over command word */ |
| 3507 | mb->mbxOwner = OWN_CHIP; |
| 3508 | |
| 3509 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3511 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3513 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3515 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3519 | word */ |
| 3520 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3521 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3522 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3523 | |
| 3524 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3525 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | to_slim = phba->MBslimaddr; |
| 3527 | writel(ldata, to_slim); |
| 3528 | readl(to_slim); /* flush */ |
| 3529 | |
| 3530 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3531 | /* switch over to host mailbox */ |
| 3532 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | |
| 3538 | switch (flag) { |
| 3539 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3540 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3541 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3542 | /* Interrupt board to do it */ |
| 3543 | writel(CA_MBATT, phba->CAregaddr); |
| 3544 | readl(phba->CAregaddr); /* flush */ |
| 3545 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | break; |
| 3547 | |
| 3548 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3549 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3551 | /* Interrupt board to do it */ |
| 3552 | writel(CA_MBATT, phba->CAregaddr); |
| 3553 | readl(phba->CAregaddr); /* flush */ |
| 3554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3556 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3557 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | word0 = le32_to_cpu(word0); |
| 3559 | } else { |
| 3560 | /* First read mbox status word */ |
| 3561 | word0 = readl(phba->MBslimaddr); |
| 3562 | } |
| 3563 | |
| 3564 | /* Read the HBA Host Attention Register */ |
| 3565 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3566 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3567 | mb->mbxCommand) * |
| 3568 | 1000) + jiffies; |
| 3569 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3571 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3572 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3573 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3574 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3578 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /* Check if we took a mbox interrupt while we were |
| 3582 | polling */ |
| 3583 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3584 | && (evtctr != psli->slistat.mbox_event)) |
| 3585 | break; |
| 3586 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3587 | if (i++ > 10) { |
| 3588 | spin_unlock_irqrestore(&phba->hbalock, |
| 3589 | drvr_flag); |
| 3590 | msleep(1); |
| 3591 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | |
| 3594 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3595 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3596 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | word0 = le32_to_cpu(word0); |
| 3598 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3599 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3600 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | /* Check real SLIM for any errors */ |
| 3602 | slimword0 = readl(phba->MBslimaddr); |
| 3603 | slimmb = (MAILBOX_t *) & slimword0; |
| 3604 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3605 | && slimmb->mbxStatus) { |
| 3606 | psli->sli_flag &= |
| 3607 | ~LPFC_SLI2_ACTIVE; |
| 3608 | word0 = slimword0; |
| 3609 | } |
| 3610 | } |
| 3611 | } else { |
| 3612 | /* First copy command data */ |
| 3613 | word0 = readl(phba->MBslimaddr); |
| 3614 | } |
| 3615 | /* Read the HBA Host Attention Register */ |
| 3616 | ha_copy = readl(phba->HAregaddr); |
| 3617 | } |
| 3618 | |
| 3619 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3621 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | } else { |
| 3623 | /* First copy command data */ |
| 3624 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3625 | MAILBOX_CMD_SIZE); |
| 3626 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3627 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3630 | mb->un.varDmp.word_cnt); |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | writel(HA_MBATT, phba->HAregaddr); |
| 3635 | readl(phba->HAregaddr); /* flush */ |
| 3636 | |
| 3637 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3638 | status = mb->mbxStatus; |
| 3639 | } |
| 3640 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3641 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3642 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3643 | |
| 3644 | out_not_finished: |
| 3645 | if (processing_queue) { |
| 3646 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3647 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3648 | } |
| 3649 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | } |
| 3651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3653 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3654 | * @phba: Pointer to HBA context object. |
| 3655 | * @pring: Pointer to driver SLI ring object. |
| 3656 | * @piocb: Pointer to address of newly added command iocb. |
| 3657 | * |
| 3658 | * This function is called with hbalock held to add a command |
| 3659 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3660 | * to the ring. |
| 3661 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3662 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3663 | __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] | 3664 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | { |
| 3666 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3667 | list_add_tail(&piocb->list, &pring->txq); |
| 3668 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | } |
| 3670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3672 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3673 | * @phba: Pointer to HBA context object. |
| 3674 | * @pring: Pointer to driver SLI ring object. |
| 3675 | * @piocb: Pointer to address of newly added command iocb. |
| 3676 | * |
| 3677 | * This function is called with hbalock held before a new |
| 3678 | * iocb is submitted to the firmware. This function checks |
| 3679 | * txq to flush the iocbs in txq to Firmware before |
| 3680 | * submitting new iocbs to the Firmware. |
| 3681 | * If there are iocbs in the txq which need to be submitted |
| 3682 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3683 | * of the txq after dequeuing it from txq. |
| 3684 | * If there is no iocb in the txq then the function will return |
| 3685 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3686 | * *piocb to find if there are more commands in the txq. |
| 3687 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | static struct lpfc_iocbq * |
| 3689 | 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] | 3690 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | { |
| 3692 | struct lpfc_iocbq * nextiocb; |
| 3693 | |
| 3694 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3695 | if (!nextiocb) { |
| 3696 | nextiocb = *piocb; |
| 3697 | *piocb = NULL; |
| 3698 | } |
| 3699 | |
| 3700 | return nextiocb; |
| 3701 | } |
| 3702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3704 | * __lpfc_sli_issue_iocb - Lockless version of lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3705 | * @phba: Pointer to HBA context object. |
| 3706 | * @pring: Pointer to driver SLI ring object. |
| 3707 | * @piocb: Pointer to command iocb. |
| 3708 | * @flag: Flag indicating if this command can be put into txq. |
| 3709 | * |
| 3710 | * __lpfc_sli_issue_iocb is used by other functions in the driver |
| 3711 | * to issue an iocb command to the HBA. If the PCI slot is recovering |
| 3712 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3713 | * flag is turned on, the function returns IOCB_ERROR. |
| 3714 | * When the link is down, this function allows only iocbs for |
| 3715 | * posting buffers. |
| 3716 | * This function finds next available slot in the command ring and |
| 3717 | * posts the command to the available slot and writes the port |
| 3718 | * attention register to request HBA start processing new iocb. |
| 3719 | * If there is no slot available in the ring and |
| 3720 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the |
| 3721 | * txq, otherwise the function returns IOCB_BUSY. |
| 3722 | * |
| 3723 | * This function is called with hbalock held. |
| 3724 | * The function will return success after it successfully submit the |
| 3725 | * iocb to firmware or after adding to the txq. |
| 3726 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3727 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3728 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3730 | { |
| 3731 | struct lpfc_iocbq *nextiocb; |
| 3732 | IOCB_t *iocb; |
| 3733 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3734 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3735 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3736 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3737 | lpfc_printf_log(phba, KERN_ERR, |
| 3738 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3739 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3740 | piocb->iocb.ulpCommand); |
| 3741 | dump_stack(); |
| 3742 | return IOCB_ERROR; |
| 3743 | } |
| 3744 | |
| 3745 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3746 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3747 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3748 | return IOCB_ERROR; |
| 3749 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3750 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 3751 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 3752 | return IOCB_ERROR; |
| 3753 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | /* |
| 3755 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3756 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | return IOCB_ERROR; |
| 3759 | |
| 3760 | /* |
| 3761 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3762 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3764 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | goto iocb_busy; |
| 3766 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3767 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3769 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | * can be issued if the link is not up. |
| 3771 | */ |
| 3772 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3773 | case CMD_GEN_REQUEST64_CR: |
| 3774 | case CMD_GEN_REQUEST64_CX: |
| 3775 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 3776 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 3777 | FC_FCP_CMND) || |
| 3778 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 3779 | MENLO_TRANSPORT_TYPE)) |
| 3780 | |
| 3781 | goto iocb_busy; |
| 3782 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | case CMD_QUE_RING_BUF_CN: |
| 3784 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | /* |
| 3786 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3787 | * completion, iocb_cmpl MUST be 0. |
| 3788 | */ |
| 3789 | if (piocb->iocb_cmpl) |
| 3790 | piocb->iocb_cmpl = NULL; |
| 3791 | /*FALLTHROUGH*/ |
| 3792 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3793 | case CMD_CLOSE_XRI_CN: |
| 3794 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | break; |
| 3796 | default: |
| 3797 | goto iocb_busy; |
| 3798 | } |
| 3799 | |
| 3800 | /* |
| 3801 | * For FCP commands, we must be in a state where we can process link |
| 3802 | * attention events. |
| 3803 | */ |
| 3804 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3805 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3807 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3810 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3811 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3812 | |
| 3813 | if (iocb) |
| 3814 | lpfc_sli_update_ring(phba, pring); |
| 3815 | else |
| 3816 | lpfc_sli_update_full_ring(phba, pring); |
| 3817 | |
| 3818 | if (!piocb) |
| 3819 | return IOCB_SUCCESS; |
| 3820 | |
| 3821 | goto out_busy; |
| 3822 | |
| 3823 | iocb_busy: |
| 3824 | pring->stats.iocb_cmd_delay++; |
| 3825 | |
| 3826 | out_busy: |
| 3827 | |
| 3828 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3829 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | return IOCB_SUCCESS; |
| 3831 | } |
| 3832 | |
| 3833 | return IOCB_BUSY; |
| 3834 | } |
| 3835 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3838 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3839 | * @phba: Pointer to HBA context object. |
| 3840 | * @pring: Pointer to driver SLI ring object. |
| 3841 | * @piocb: Pointer to command iocb. |
| 3842 | * @flag: Flag indicating if this command can be put into txq. |
| 3843 | * |
| 3844 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 3845 | * function. This function gets the hbalock and calls |
| 3846 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 3847 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 3848 | * functions which do not hold hbalock. |
| 3849 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3850 | int |
| 3851 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3852 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3853 | { |
| 3854 | unsigned long iflags; |
| 3855 | int rc; |
| 3856 | |
| 3857 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 3858 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 3859 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 3860 | |
| 3861 | return rc; |
| 3862 | } |
| 3863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3865 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3866 | * @phba: Pointer to HBA context object. |
| 3867 | * |
| 3868 | * This function is called while driver attaches with the |
| 3869 | * HBA to setup the extra ring. The extra ring is used |
| 3870 | * only when driver needs to support target mode functionality |
| 3871 | * or IP over FC functionalities. |
| 3872 | * |
| 3873 | * This function is called with no lock held. |
| 3874 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3875 | static int |
| 3876 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 3877 | { |
| 3878 | struct lpfc_sli *psli; |
| 3879 | struct lpfc_sli_ring *pring; |
| 3880 | |
| 3881 | psli = &phba->sli; |
| 3882 | |
| 3883 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3884 | |
| 3885 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3886 | pring = &psli->ring[psli->fcp_ring]; |
| 3887 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3888 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3889 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3890 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3891 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3892 | /* and give them to the extra ring */ |
| 3893 | pring = &psli->ring[psli->extra_ring]; |
| 3894 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3895 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3896 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3897 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3898 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3899 | |
| 3900 | /* Setup default profile for this ring */ |
| 3901 | pring->iotag_max = 4096; |
| 3902 | pring->num_mask = 1; |
| 3903 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3904 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 3905 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3906 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 3907 | return 0; |
| 3908 | } |
| 3909 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3910 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3911 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3912 | * @phba: Pointer to HBA context object. |
| 3913 | * @pring: Pointer to driver SLI ring object. |
| 3914 | * @iocbq: Pointer to iocb object. |
| 3915 | * |
| 3916 | * This function is called by the slow ring event handler |
| 3917 | * function when there is an ASYNC event iocb in the ring. |
| 3918 | * This function is called with no lock held. |
| 3919 | * Currently this function handles only temperature related |
| 3920 | * ASYNC events. The function decodes the temperature sensor |
| 3921 | * event message and posts events for the management applications. |
| 3922 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3923 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3924 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 3925 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 3926 | { |
| 3927 | IOCB_t *icmd; |
| 3928 | uint16_t evt_code; |
| 3929 | uint16_t temp; |
| 3930 | struct temp_event temp_event_data; |
| 3931 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3932 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3933 | |
| 3934 | icmd = &iocbq->iocb; |
| 3935 | evt_code = icmd->un.asyncstat.evt_code; |
| 3936 | temp = icmd->ulpContext; |
| 3937 | |
| 3938 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 3939 | (evt_code != ASYNC_TEMP_SAFE)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3940 | iocb_w = (uint32_t *) icmd; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3941 | lpfc_printf_log(phba, |
| 3942 | KERN_ERR, |
| 3943 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3944 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3945 | " evt_code 0x%x \n" |
| 3946 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 3947 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 3948 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 3949 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3950 | pring->ringno, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 3951 | icmd->un.asyncstat.evt_code, |
| 3952 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 3953 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 3954 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 3955 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 3956 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3957 | return; |
| 3958 | } |
| 3959 | temp_event_data.data = (uint32_t)temp; |
| 3960 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 3961 | if (evt_code == ASYNC_TEMP_WARN) { |
| 3962 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 3963 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3964 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3965 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3966 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3967 | "corrective action. temperature : %d Celsius\n", |
| 3968 | temp); |
| 3969 | } |
| 3970 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 3971 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 3972 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3973 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3974 | LOG_TEMP, |
| 3975 | "0340 Adapter temperature is OK now. " |
| 3976 | "temperature : %d Celsius\n", |
| 3977 | temp); |
| 3978 | } |
| 3979 | |
| 3980 | /* Send temperature change event to applications */ |
| 3981 | shost = lpfc_shost_from_vport(phba->pport); |
| 3982 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3983 | sizeof(temp_event_data), (char *) &temp_event_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3984 | LPFC_NL_VENDOR_ID); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3985 | |
| 3986 | } |
| 3987 | |
| 3988 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3989 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3990 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3991 | * @phba: Pointer to HBA context object. |
| 3992 | * |
| 3993 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 3994 | * number of iocbs per ring and iotags. This function is |
| 3995 | * called while driver attach to the HBA and before the |
| 3996 | * interrupts are enabled. So there is no need for locking. |
| 3997 | * |
| 3998 | * This function always returns 0. |
| 3999 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | int |
| 4001 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 4002 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4003 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4004 | struct lpfc_sli *psli = &phba->sli; |
| 4005 | struct lpfc_sli_ring *pring; |
| 4006 | |
| 4007 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 4008 | psli->sli_flag = 0; |
| 4009 | psli->fcp_ring = LPFC_FCP_RING; |
| 4010 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4011 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4013 | psli->iocbq_lookup = NULL; |
| 4014 | psli->iocbq_lookup_len = 0; |
| 4015 | psli->last_iotag = 0; |
| 4016 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | for (i = 0; i < psli->num_rings; i++) { |
| 4018 | pring = &psli->ring[i]; |
| 4019 | switch (i) { |
| 4020 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 4021 | /* numCiocb and numRiocb are used in config_port */ |
| 4022 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 4023 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 4024 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4025 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4026 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4027 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4028 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4029 | SLI3_IOCB_CMD_SIZE : |
| 4030 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4031 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4032 | SLI3_IOCB_RSP_SIZE : |
| 4033 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | pring->iotag_ctr = 0; |
| 4035 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4036 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | pring->fast_iotag = pring->iotag_max; |
| 4038 | pring->num_mask = 0; |
| 4039 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4040 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | /* numCiocb and numRiocb are used in config_port */ |
| 4042 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 4043 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4044 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4045 | SLI3_IOCB_CMD_SIZE : |
| 4046 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4047 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | SLI3_IOCB_RSP_SIZE : |
| 4049 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4050 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | pring->num_mask = 0; |
| 4052 | break; |
| 4053 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 4054 | /* numCiocb and numRiocb are used in config_port */ |
| 4055 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 4056 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4057 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4058 | SLI3_IOCB_CMD_SIZE : |
| 4059 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4060 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4061 | SLI3_IOCB_RSP_SIZE : |
| 4062 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | pring->fast_iotag = 0; |
| 4064 | pring->iotag_ctr = 0; |
| 4065 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4066 | pring->lpfc_sli_rcv_async_status = |
| 4067 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | pring->num_mask = 4; |
| 4069 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 4070 | pring->prt[0].rctl = FC_ELS_REQ; |
| 4071 | pring->prt[0].type = FC_ELS_DATA; |
| 4072 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 4075 | pring->prt[1].rctl = FC_ELS_RSP; |
| 4076 | pring->prt[1].type = FC_ELS_DATA; |
| 4077 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4078 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 4080 | /* NameServer Inquiry */ |
| 4081 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 4082 | /* NameServer */ |
| 4083 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 4084 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4085 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 4087 | /* NameServer response */ |
| 4088 | pring->prt[3].rctl = FC_SOL_CTL; |
| 4089 | /* NameServer */ |
| 4090 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 4091 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4092 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | break; |
| 4094 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4095 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4096 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4098 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4100 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 4101 | "SLI2 SLIM Data: x%x x%lx\n", |
| 4102 | phba->brd_no, totiocbsize, |
| 4103 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4105 | if (phba->cfg_multi_ring_support == 2) |
| 4106 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | |
| 4108 | return 0; |
| 4109 | } |
| 4110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4111 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4112 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4113 | * @phba: Pointer to HBA context object. |
| 4114 | * |
| 4115 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4116 | * ring. This function also initializes ring indices of each ring. |
| 4117 | * This function is called during the initialization of the SLI |
| 4118 | * interface of an HBA. |
| 4119 | * This function is called with no lock held and always returns |
| 4120 | * 1. |
| 4121 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4122 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4123 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | { |
| 4125 | struct lpfc_sli *psli; |
| 4126 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4127 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4128 | |
| 4129 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4130 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4132 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4134 | for (i = 0; i < psli->num_rings; i++) { |
| 4135 | pring = &psli->ring[i]; |
| 4136 | pring->ringno = i; |
| 4137 | pring->next_cmdidx = 0; |
| 4138 | pring->local_getidx = 0; |
| 4139 | pring->cmdidx = 0; |
| 4140 | INIT_LIST_HEAD(&pring->txq); |
| 4141 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4142 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4143 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4146 | spin_unlock_irq(&phba->hbalock); |
| 4147 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | } |
| 4149 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4150 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4151 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4152 | * @vport: Pointer to virtual port object. |
| 4153 | * |
| 4154 | * lpfc_sli_host_down is called to clean up the resources |
| 4155 | * associated with a vport before destroying virtual |
| 4156 | * port data structures. |
| 4157 | * This function does following operations: |
| 4158 | * - Free discovery resources associated with this virtual |
| 4159 | * port. |
| 4160 | * - Free iocbs associated with this virtual port in |
| 4161 | * the txq. |
| 4162 | * - Send abort for all iocb commands associated with this |
| 4163 | * vport in txcmplq. |
| 4164 | * |
| 4165 | * This function is called with no lock held and always returns 1. |
| 4166 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4168 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4169 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4170 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4171 | struct lpfc_hba *phba = vport->phba; |
| 4172 | struct lpfc_sli *psli = &phba->sli; |
| 4173 | struct lpfc_sli_ring *pring; |
| 4174 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4175 | int i; |
| 4176 | unsigned long flags = 0; |
| 4177 | uint16_t prev_pring_flag; |
| 4178 | |
| 4179 | lpfc_cleanup_discovery_resources(vport); |
| 4180 | |
| 4181 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4182 | for (i = 0; i < psli->num_rings; i++) { |
| 4183 | pring = &psli->ring[i]; |
| 4184 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4185 | /* Only slow rings */ |
| 4186 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4187 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4188 | /* Set the lpfc data pending flag */ |
| 4189 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4190 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4191 | /* |
| 4192 | * Error everything on the txq since these iocbs have not been |
| 4193 | * given to the FW yet. |
| 4194 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4195 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4196 | if (iocb->vport != vport) |
| 4197 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4198 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4199 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | /* Next issue ABTS for everything on the txcmplq */ |
| 4203 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4204 | list) { |
| 4205 | if (iocb->vport != vport) |
| 4206 | continue; |
| 4207 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4208 | } |
| 4209 | |
| 4210 | pring->flag = prev_pring_flag; |
| 4211 | } |
| 4212 | |
| 4213 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4214 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 4215 | /* Cancel all the IOCBs from the completions list */ |
| 4216 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4217 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4218 | return 1; |
| 4219 | } |
| 4220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4222 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4223 | * @phba: Pointer to HBA context object. |
| 4224 | * |
| 4225 | * This function cleans up all iocb, buffers, mailbox commands |
| 4226 | * while shutting down the HBA. This function is called with no |
| 4227 | * lock held and always returns 1. |
| 4228 | * This function does the following to cleanup driver resources: |
| 4229 | * - Free discovery resources for each virtual port |
| 4230 | * - Cleanup any pending fabric iocbs |
| 4231 | * - Iterate through the iocb txq and free each entry |
| 4232 | * in the list. |
| 4233 | * - Free up any buffer posted to the HBA |
| 4234 | * - Free mailbox commands in the mailbox queue. |
| 4235 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4236 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4237 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4238 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4239 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4240 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4241 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4242 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | LPFC_MBOXQ_t *pmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | int i; |
| 4245 | unsigned long flags = 0; |
| 4246 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | lpfc_hba_down_prep(phba); |
| 4248 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4249 | lpfc_fabric_abort_hba(phba); |
| 4250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4251 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | for (i = 0; i < psli->num_rings; i++) { |
| 4253 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4254 | /* Only slow rings */ |
| 4255 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4256 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4257 | /* Set the lpfc data pending flag */ |
| 4258 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4259 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | |
| 4261 | /* |
| 4262 | * Error everything on the txq since these iocbs have not been |
| 4263 | * given to the FW yet. |
| 4264 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4265 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | pring->txq_cnt = 0; |
| 4267 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 4271 | /* Cancel all the IOCBs from the completions list */ |
| 4272 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4273 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4274 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4275 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4276 | list_splice_init(&phba->elsbuf, &completions); |
| 4277 | phba->elsbuf_cnt = 0; |
| 4278 | phba->elsbuf_prev_cnt = 0; |
| 4279 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4280 | |
| 4281 | while (!list_empty(&completions)) { |
| 4282 | list_remove_head(&completions, buf_ptr, |
| 4283 | struct lpfc_dmabuf, list); |
| 4284 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4285 | kfree(buf_ptr); |
| 4286 | } |
| 4287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | /* Return any active mbox cmds */ |
| 4289 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4290 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4291 | |
| 4292 | spin_lock(&phba->pport->work_port_lock); |
| 4293 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4294 | spin_unlock(&phba->pport->work_port_lock); |
| 4295 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4296 | /* Return any pending or completed mbox cmds */ |
| 4297 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4298 | if (psli->mbox_active) { |
| 4299 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4303 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4304 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4305 | |
| 4306 | while (!list_empty(&completions)) { |
| 4307 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4309 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | return 1; |
| 4313 | } |
| 4314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4316 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4317 | * @srcp: Source memory pointer. |
| 4318 | * @destp: Destination memory pointer. |
| 4319 | * @cnt: Number of words required to be copied. |
| 4320 | * |
| 4321 | * This function is used for copying data between driver memory |
| 4322 | * and the SLI memory. This function also changes the endianness |
| 4323 | * of each word if native endianness is different from SLI |
| 4324 | * endianness. This function can be called with or without |
| 4325 | * lock. |
| 4326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | void |
| 4328 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4329 | { |
| 4330 | uint32_t *src = srcp; |
| 4331 | uint32_t *dest = destp; |
| 4332 | uint32_t ldata; |
| 4333 | int i; |
| 4334 | |
| 4335 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4336 | ldata = *src; |
| 4337 | ldata = le32_to_cpu(ldata); |
| 4338 | *dest = ldata; |
| 4339 | src++; |
| 4340 | dest++; |
| 4341 | } |
| 4342 | } |
| 4343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4344 | |
| 4345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4346 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4347 | * @phba: Pointer to HBA context object. |
| 4348 | * @pring: Pointer to driver SLI ring object. |
| 4349 | * @mp: Pointer to driver buffer object. |
| 4350 | * |
| 4351 | * This function is called with no lock held. |
| 4352 | * It always return zero after adding the buffer to the postbufq |
| 4353 | * buffer list. |
| 4354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4357 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | { |
| 4359 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4360 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4361 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | return 0; |
| 4366 | } |
| 4367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4369 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4370 | * @phba: Pointer to HBA context object. |
| 4371 | * |
| 4372 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4373 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4374 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4375 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4376 | * The function returns the allocated tag. The function is called with |
| 4377 | * no locks held. |
| 4378 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4379 | uint32_t |
| 4380 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4381 | { |
| 4382 | spin_lock_irq(&phba->hbalock); |
| 4383 | phba->buffer_tag_count++; |
| 4384 | /* |
| 4385 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4386 | * a tag assigned by HBQ. |
| 4387 | */ |
| 4388 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4389 | spin_unlock_irq(&phba->hbalock); |
| 4390 | return phba->buffer_tag_count; |
| 4391 | } |
| 4392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4393 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4394 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4395 | * @phba: Pointer to HBA context object. |
| 4396 | * @pring: Pointer to driver SLI ring object. |
| 4397 | * @tag: Buffer tag. |
| 4398 | * |
| 4399 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4400 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4401 | * iocb is posted to the response ring with the tag of the buffer. |
| 4402 | * This function searches the pring->postbufq list using the tag |
| 4403 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4404 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4405 | * buffer is returned to the caller else NULL is returned. |
| 4406 | * This function is called with no lock held. |
| 4407 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4408 | struct lpfc_dmabuf * |
| 4409 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4410 | uint32_t tag) |
| 4411 | { |
| 4412 | struct lpfc_dmabuf *mp, *next_mp; |
| 4413 | struct list_head *slp = &pring->postbufq; |
| 4414 | |
| 4415 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4416 | spin_lock_irq(&phba->hbalock); |
| 4417 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4418 | if (mp->buffer_tag == tag) { |
| 4419 | list_del_init(&mp->list); |
| 4420 | pring->postbufq_cnt--; |
| 4421 | spin_unlock_irq(&phba->hbalock); |
| 4422 | return mp; |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | spin_unlock_irq(&phba->hbalock); |
| 4427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4428 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4429 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4430 | pring->ringno, (unsigned long) tag, |
| 4431 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4432 | |
| 4433 | return NULL; |
| 4434 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4436 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4437 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4438 | * @phba: Pointer to HBA context object. |
| 4439 | * @pring: Pointer to driver SLI ring object. |
| 4440 | * @phys: DMA address of the buffer. |
| 4441 | * |
| 4442 | * This function searches the buffer list using the dma_address |
| 4443 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4444 | * corresponding to the dma_address. The function returns the |
| 4445 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4446 | * This function is called by the ct and els unsolicited event |
| 4447 | * handlers to get the buffer associated with the unsolicited |
| 4448 | * event. |
| 4449 | * |
| 4450 | * This function is called with no lock held. |
| 4451 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | struct lpfc_dmabuf * |
| 4453 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4454 | dma_addr_t phys) |
| 4455 | { |
| 4456 | struct lpfc_dmabuf *mp, *next_mp; |
| 4457 | struct list_head *slp = &pring->postbufq; |
| 4458 | |
| 4459 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4461 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4462 | if (mp->phys == phys) { |
| 4463 | list_del_init(&mp->list); |
| 4464 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4465 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | return mp; |
| 4467 | } |
| 4468 | } |
| 4469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4470 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4472 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4474 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4476 | return NULL; |
| 4477 | } |
| 4478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4480 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4481 | * @phba: Pointer to HBA context object. |
| 4482 | * @cmdiocb: Pointer to driver command iocb object. |
| 4483 | * @rspiocb: Pointer to driver response iocb object. |
| 4484 | * |
| 4485 | * This function is the completion handler for the abort iocbs for |
| 4486 | * ELS commands. This function is called from the ELS ring event |
| 4487 | * handler with no lock held. This function frees memory resources |
| 4488 | * associated with the abort iocb. |
| 4489 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4492 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4495 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4496 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4497 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4498 | |
| 4499 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4500 | |
| 4501 | if (irsp->ulpStatus) { |
| 4502 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4503 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4504 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4506 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4507 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4508 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4509 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4510 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4511 | "with tag %x context %x, abort status %x, " |
| 4512 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4513 | abort_iocb, abort_iotag, abort_context, |
| 4514 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4515 | |
| 4516 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4517 | * If the iocb is not found in Firmware queue the iocb |
| 4518 | * might have completed already. Do not free it again. |
| 4519 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4520 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4521 | spin_unlock_irq(&phba->hbalock); |
| 4522 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4523 | return; |
| 4524 | } |
| 4525 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4526 | * make sure we have the right iocbq before taking it |
| 4527 | * off the txcmplq and try to call completion routine. |
| 4528 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | if (!abort_iocb || |
| 4530 | abort_iocb->iocb.ulpContext != abort_context || |
| 4531 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4532 | spin_unlock_irq(&phba->hbalock); |
| 4533 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4534 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4535 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4537 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4538 | /* Firmware could still be in progress of DMAing |
| 4539 | * payload, so don't free data buffer till after |
| 4540 | * a hbeat. |
| 4541 | */ |
| 4542 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4543 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4544 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4545 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4546 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4547 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4548 | } |
| 4549 | } |
| 4550 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4551 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | return; |
| 4553 | } |
| 4554 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4555 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4556 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4557 | * @phba: Pointer to HBA context object. |
| 4558 | * @cmdiocb: Pointer to driver command iocb object. |
| 4559 | * @rspiocb: Pointer to driver response iocb object. |
| 4560 | * |
| 4561 | * The function is called from SLI ring event handler with no |
| 4562 | * lock held. This function is the completion handler for ELS commands |
| 4563 | * which are aborted. The function frees memory resources used for |
| 4564 | * the aborted ELS commands. |
| 4565 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4566 | static void |
| 4567 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4568 | struct lpfc_iocbq *rspiocb) |
| 4569 | { |
| 4570 | IOCB_t *irsp = &rspiocb->iocb; |
| 4571 | |
| 4572 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4573 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4574 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4575 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4576 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4577 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4578 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4579 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4580 | else |
| 4581 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4582 | return; |
| 4583 | } |
| 4584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4585 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4586 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4587 | * @phba: Pointer to HBA context object. |
| 4588 | * @pring: Pointer to driver SLI ring object. |
| 4589 | * @cmdiocb: Pointer to driver command iocb object. |
| 4590 | * |
| 4591 | * This function issues an abort iocb for the provided command |
| 4592 | * iocb. This function is called with hbalock held. |
| 4593 | * The function returns 0 when it fails due to memory allocation |
| 4594 | * failure or when the command iocb is an abort request. |
| 4595 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4597 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4598 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4600 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4601 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4602 | IOCB_t *icmd = NULL; |
| 4603 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4604 | int retval = IOCB_ERROR; |
| 4605 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4606 | /* |
| 4607 | * There are certain command types we don't want to abort. And we |
| 4608 | * don't want to abort commands that are already in the process of |
| 4609 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4610 | */ |
| 4611 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4612 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4613 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4614 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4615 | return 0; |
| 4616 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4617 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4618 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4619 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4620 | if ((vport->load_flag & FC_UNLOADING) && |
| 4621 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4622 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4623 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4624 | else |
| 4625 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4626 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4627 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | |
| 4629 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4630 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | if (abtsiocbp == NULL) |
| 4632 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4634 | /* This signals the response to set the correct status |
| 4635 | * before calling the completion handler. |
| 4636 | */ |
| 4637 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4639 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4640 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4641 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4642 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4644 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4647 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4648 | else |
| 4649 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4650 | |
| 4651 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4652 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4653 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4654 | "0339 Abort xri x%x, original iotag x%x, " |
| 4655 | "abort cmd iotag x%x\n", |
| 4656 | iabt->un.acxri.abortContextTag, |
| 4657 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4658 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4659 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4660 | if (retval) |
| 4661 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4662 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4663 | /* |
| 4664 | * Caller to this routine should check for IOCB_ERROR |
| 4665 | * and handle it properly. This routine no longer removes |
| 4666 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4667 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4668 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4669 | } |
| 4670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4672 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4673 | * @iocbq: Pointer to driver iocb object. |
| 4674 | * @vport: Pointer to driver virtual port object. |
| 4675 | * @tgt_id: SCSI ID of the target. |
| 4676 | * @lun_id: LUN ID of the scsi device. |
| 4677 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4678 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4679 | * This function acts as an iocb filter for functions which abort or count |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4680 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4681 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4682 | * 1 if the filtering criteria is not met. |
| 4683 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4684 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4685 | * lun_id parameter. |
| 4686 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4687 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4688 | * parameters. |
| 4689 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4690 | * given iocb is for the SCSI host associated with the given vport. |
| 4691 | * This function is called with no locks held. |
| 4692 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4694 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4695 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4696 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4697 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4698 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4699 | int rc = 1; |
| 4700 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4701 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4702 | return rc; |
| 4703 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4704 | if (iocbq->vport != vport) |
| 4705 | return rc; |
| 4706 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4707 | 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] | 4708 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4709 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4710 | return rc; |
| 4711 | |
| 4712 | switch (ctx_cmd) { |
| 4713 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4714 | if ((lpfc_cmd->rdata->pnode) && |
| 4715 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4716 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4717 | rc = 0; |
| 4718 | break; |
| 4719 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4720 | if ((lpfc_cmd->rdata->pnode) && |
| 4721 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | rc = 0; |
| 4723 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | case LPFC_CTX_HOST: |
| 4725 | rc = 0; |
| 4726 | break; |
| 4727 | default: |
| 4728 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4729 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4730 | break; |
| 4731 | } |
| 4732 | |
| 4733 | return rc; |
| 4734 | } |
| 4735 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4736 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4737 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4738 | * @vport: Pointer to virtual port. |
| 4739 | * @tgt_id: SCSI ID of the target. |
| 4740 | * @lun_id: LUN ID of the scsi device. |
| 4741 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4742 | * |
| 4743 | * This function returns number of FCP commands pending for the vport. |
| 4744 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4745 | * commands pending on the vport associated with SCSI device specified |
| 4746 | * by tgt_id and lun_id parameters. |
| 4747 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4748 | * commands pending on the vport associated with SCSI target specified |
| 4749 | * by tgt_id parameter. |
| 4750 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4751 | * commands pending on the vport. |
| 4752 | * This function returns the number of iocbs which satisfy the filter. |
| 4753 | * This function is called without any lock held. |
| 4754 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4756 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4757 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4759 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4760 | struct lpfc_iocbq *iocbq; |
| 4761 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4762 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4763 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4764 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4766 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4767 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4768 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4770 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4771 | return sum; |
| 4772 | } |
| 4773 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4774 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4775 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4776 | * @phba: Pointer to HBA context object |
| 4777 | * @cmdiocb: Pointer to command iocb object. |
| 4778 | * @rspiocb: Pointer to response iocb object. |
| 4779 | * |
| 4780 | * This function is called when an aborted FCP iocb completes. This |
| 4781 | * function is called by the ring event handler with no lock held. |
| 4782 | * This function frees the iocb. |
| 4783 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4784 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4786 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4787 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4788 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4789 | return; |
| 4790 | } |
| 4791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4793 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4794 | * @vport: Pointer to virtual port. |
| 4795 | * @pring: Pointer to driver SLI ring object. |
| 4796 | * @tgt_id: SCSI ID of the target. |
| 4797 | * @lun_id: LUN ID of the scsi device. |
| 4798 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4799 | * |
| 4800 | * This function sends an abort command for every SCSI command |
| 4801 | * associated with the given virtual port pending on the ring |
| 4802 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 4803 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 4804 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 4805 | * parameters |
| 4806 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 4807 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 4808 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 4809 | * FCP iocbs associated with virtual port. |
| 4810 | * This function returns number of iocbs it failed to abort. |
| 4811 | * This function is called with no locks held. |
| 4812 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4813 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4814 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 4815 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4816 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4817 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4818 | struct lpfc_iocbq *iocbq; |
| 4819 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4822 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4823 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4824 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 4825 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4826 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4827 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4828 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4829 | continue; |
| 4830 | |
| 4831 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4832 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4833 | if (abtsiocb == NULL) { |
| 4834 | errcnt++; |
| 4835 | continue; |
| 4836 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4837 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4838 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4839 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4840 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 4841 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 4842 | abtsiocb->iocb.ulpLe = 1; |
| 4843 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4844 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4846 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 4848 | else |
| 4849 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 4850 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4851 | /* Setup callback routine and issue the command. */ |
| 4852 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 4854 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4855 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | errcnt++; |
| 4857 | continue; |
| 4858 | } |
| 4859 | } |
| 4860 | |
| 4861 | return errcnt; |
| 4862 | } |
| 4863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4865 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4866 | * @phba: Pointer to HBA context object. |
| 4867 | * @cmdiocbq: Pointer to command iocb. |
| 4868 | * @rspiocbq: Pointer to response iocb. |
| 4869 | * |
| 4870 | * This function is the completion handler for iocbs issued using |
| 4871 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 4872 | * ring event handler function without any lock held. This function |
| 4873 | * can be called from both worker thread context and interrupt |
| 4874 | * context. This function also can be called from other thread which |
| 4875 | * cleans up the SLI layer objects. |
| 4876 | * This function copy the contents of the response iocb to the |
| 4877 | * response iocb memory object provided by the caller of |
| 4878 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4879 | * sleeps for the iocb completion. |
| 4880 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4881 | static void |
| 4882 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 4883 | struct lpfc_iocbq *cmdiocbq, |
| 4884 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4886 | wait_queue_head_t *pdone_q; |
| 4887 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4889 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4890 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 4891 | if (cmdiocbq->context2 && rspiocbq) |
| 4892 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 4893 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 4894 | |
| 4895 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4896 | if (pdone_q) |
| 4897 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4898 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | return; |
| 4900 | } |
| 4901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4902 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4903 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4904 | * @phba: Pointer to HBA context object.. |
| 4905 | * @pring: Pointer to sli ring. |
| 4906 | * @piocb: Pointer to command iocb. |
| 4907 | * @prspiocbq: Pointer to response iocb. |
| 4908 | * @timeout: Timeout in number of seconds. |
| 4909 | * |
| 4910 | * This function issues the iocb to firmware and waits for the |
| 4911 | * iocb to complete. If the iocb command is not |
| 4912 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 4913 | * Caller should not free the iocb resources if this function |
| 4914 | * returns IOCB_TIMEDOUT. |
| 4915 | * The function waits for the iocb completion using an |
| 4916 | * non-interruptible wait. |
| 4917 | * This function will sleep while waiting for iocb completion. |
| 4918 | * So, this function should not be called from any context which |
| 4919 | * does not allow sleeping. Due to the same reason, this function |
| 4920 | * cannot be called with interrupt disabled. |
| 4921 | * This function assumes that the iocb completions occur while |
| 4922 | * this function sleep. So, this function cannot be called from |
| 4923 | * the thread which process iocb completion for this ring. |
| 4924 | * This function clears the iocb_flag of the iocb object before |
| 4925 | * issuing the iocb and the iocb completion handler sets this |
| 4926 | * flag and wakes this thread when the iocb completes. |
| 4927 | * The contents of the response iocb will be copied to prspiocbq |
| 4928 | * by the completion handler when the command completes. |
| 4929 | * This function returns IOCB_SUCCESS when success. |
| 4930 | * This function is called with no lock held. |
| 4931 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4933 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 4934 | struct lpfc_sli_ring *pring, |
| 4935 | struct lpfc_iocbq *piocb, |
| 4936 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4937 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4939 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4940 | long timeleft, timeout_req = 0; |
| 4941 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4942 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | |
| 4944 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4945 | * If the caller has provided a response iocbq buffer, then context2 |
| 4946 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4948 | if (prspiocbq) { |
| 4949 | if (piocb->context2) |
| 4950 | return IOCB_ERROR; |
| 4951 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4952 | } |
| 4953 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4954 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 4955 | piocb->context_un.wait_queue = &done_q; |
| 4956 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4958 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4959 | creg_val = readl(phba->HCregaddr); |
| 4960 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 4961 | writel(creg_val, phba->HCregaddr); |
| 4962 | readl(phba->HCregaddr); /* flush */ |
| 4963 | } |
| 4964 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4965 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 4966 | if (retval == IOCB_SUCCESS) { |
| 4967 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4968 | timeleft = wait_event_timeout(done_q, |
| 4969 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 4970 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4972 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 4973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4974 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4975 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4976 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4977 | "0338 IOCB wait timeout error - no " |
| 4978 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4979 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4980 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4981 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4982 | "0330 IOCB wake NOT set, " |
| 4983 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4984 | timeout, (timeleft / jiffies)); |
| 4985 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4986 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4987 | } else { |
| 4988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4989 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4990 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4991 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | } |
| 4993 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4994 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4995 | creg_val = readl(phba->HCregaddr); |
| 4996 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 4997 | writel(creg_val, phba->HCregaddr); |
| 4998 | readl(phba->HCregaddr); /* flush */ |
| 4999 | } |
| 5000 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5001 | if (prspiocbq) |
| 5002 | piocb->context2 = NULL; |
| 5003 | |
| 5004 | piocb->context_un.wait_queue = NULL; |
| 5005 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | return retval; |
| 5007 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5008 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5009 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5010 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5011 | * @phba: Pointer to HBA context object. |
| 5012 | * @pmboxq: Pointer to driver mailbox object. |
| 5013 | * @timeout: Timeout in number of seconds. |
| 5014 | * |
| 5015 | * This function issues the mailbox to firmware and waits for the |
| 5016 | * mailbox command to complete. If the mailbox command is not |
| 5017 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 5018 | * The function waits for the mailbox completion using an |
| 5019 | * interruptible wait. If the thread is woken up due to a |
| 5020 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 5021 | * should not free the mailbox resources, if this function returns |
| 5022 | * MBX_TIMEOUT. |
| 5023 | * This function will sleep while waiting for mailbox completion. |
| 5024 | * So, this function should not be called from any context which |
| 5025 | * does not allow sleeping. Due to the same reason, this function |
| 5026 | * cannot be called with interrupt disabled. |
| 5027 | * This function assumes that the mailbox completion occurs while |
| 5028 | * this function sleep. So, this function cannot be called from |
| 5029 | * the worker thread which processes mailbox completion. |
| 5030 | * This function is called in the context of HBA management |
| 5031 | * applications. |
| 5032 | * This function returns MBX_SUCCESS when successful. |
| 5033 | * This function is called with no lock held. |
| 5034 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5035 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5036 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | uint32_t timeout) |
| 5038 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5039 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5041 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | |
| 5043 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5044 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5045 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5047 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | /* setup wake call as IOCB callback */ |
| 5049 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 5050 | /* setup context field to pass wait_queue pointer to wake function */ |
| 5051 | pmboxq->context1 = &done_q; |
| 5052 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | /* now issue the command */ |
| 5054 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 5055 | |
| 5056 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5057 | wait_event_interruptible_timeout(done_q, |
| 5058 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 5059 | timeout * HZ); |
| 5060 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5061 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5062 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5063 | /* |
| 5064 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 5065 | * else do not free the resources. |
| 5066 | */ |
| 5067 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5068 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5069 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5070 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5071 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5072 | } |
| 5073 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5074 | } |
| 5075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | return retval; |
| 5077 | } |
| 5078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5080 | * lpfc_sli_flush_mbox_queue - mailbox queue cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5081 | * @phba: Pointer to HBA context. |
| 5082 | * |
| 5083 | * This function is called to cleanup any pending mailbox |
| 5084 | * objects in the driver queue before bringing the HBA offline. |
| 5085 | * This function is called while resetting the HBA. |
| 5086 | * The function is called without any lock held. The function |
| 5087 | * takes hbalock to update SLI data structure. |
| 5088 | * This function returns 1 when there is an active mailbox |
| 5089 | * command pending else returns 0. |
| 5090 | **/ |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5091 | int |
| 5092 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 5093 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5094 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5095 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5096 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5098 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5099 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 5100 | return 1; |
| 5101 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5102 | /* |
| 5103 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 5104 | * did finish. This way we won't get the misleading |
| 5105 | * "Stray Mailbox Interrupt" message. |
| 5106 | */ |
| 5107 | spin_lock_irq(&phba->hbalock); |
| 5108 | ha_copy = phba->work_ha; |
| 5109 | phba->work_ha &= ~HA_MBATT; |
| 5110 | spin_unlock_irq(&phba->hbalock); |
| 5111 | |
| 5112 | if (ha_copy & HA_MBATT) |
| 5113 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 5114 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5115 | |
| 5116 | msleep(1); |
| 5117 | } |
| 5118 | |
| 5119 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 5120 | } |
| 5121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5123 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5124 | * @phba: Pointer to HBA context. |
| 5125 | * |
| 5126 | * This function is called form timer soft interrupt context to check HBA's |
| 5127 | * error attention register bit for error attention events. |
| 5128 | * |
| 5129 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5130 | * Register and returns 0 otherwise. |
| 5131 | **/ |
| 5132 | int |
| 5133 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 5134 | { |
| 5135 | uint32_t ha_copy; |
| 5136 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5137 | /* If PCI channel is offline, don't process it */ |
| 5138 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5139 | return 0; |
| 5140 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5141 | /* If somebody is waiting to handle an eratt, don't process it |
| 5142 | * here. The brdkill function will do this. |
| 5143 | */ |
| 5144 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5145 | return 0; |
| 5146 | |
| 5147 | /* Check if interrupt handler handles this ERATT */ |
| 5148 | spin_lock_irq(&phba->hbalock); |
| 5149 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 5150 | /* Interrupt handler has handled ERATT */ |
| 5151 | spin_unlock_irq(&phba->hbalock); |
| 5152 | return 0; |
| 5153 | } |
| 5154 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5155 | /* |
| 5156 | * If there is deferred error attention, do not check for error |
| 5157 | * attention |
| 5158 | */ |
| 5159 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5160 | spin_unlock_irq(&phba->hbalock); |
| 5161 | return 0; |
| 5162 | } |
| 5163 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5164 | /* Read chip Host Attention (HA) register */ |
| 5165 | ha_copy = readl(phba->HAregaddr); |
| 5166 | if (ha_copy & HA_ERATT) { |
| 5167 | /* Read host status register to retrieve error event */ |
| 5168 | lpfc_sli_read_hs(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5169 | |
| 5170 | /* Check if there is a deferred error condition is active */ |
| 5171 | if ((HS_FFER1 & phba->work_hs) && |
| 5172 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 5173 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 5174 | phba->hba_flag |= DEFER_ERATT; |
| 5175 | /* Clear all interrupt enable conditions */ |
| 5176 | writel(0, phba->HCregaddr); |
| 5177 | readl(phba->HCregaddr); |
| 5178 | } |
| 5179 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5180 | /* Set the driver HA work bitmap */ |
| 5181 | phba->work_ha |= HA_ERATT; |
| 5182 | /* Indicate polling handles this ERATT */ |
| 5183 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5184 | spin_unlock_irq(&phba->hbalock); |
| 5185 | return 1; |
| 5186 | } |
| 5187 | spin_unlock_irq(&phba->hbalock); |
| 5188 | return 0; |
| 5189 | } |
| 5190 | |
| 5191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5192 | * lpfc_sp_intr_handler - The slow-path interrupt handler of lpfc driver |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5193 | * @irq: Interrupt number. |
| 5194 | * @dev_id: The device context pointer. |
| 5195 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5196 | * This function is directly called from the PCI layer as an interrupt |
| 5197 | * service routine when the device is enabled with MSI-X multi-message |
| 5198 | * interrupt mode and there are slow-path events in the HBA. However, |
| 5199 | * when the device is enabled with either MSI or Pin-IRQ interrupt mode, |
| 5200 | * this function is called as part of the device-level interrupt handler. |
| 5201 | * When the PCI slot is in error recovery or the HBA is undergoing |
| 5202 | * initialization, the interrupt handler will not process the interrupt. |
| 5203 | * The link attention and ELS ring attention events are handled by the |
| 5204 | * worker thread. The interrupt handler signals the worker thread and |
| 5205 | * and returns for these events. This function is called without any |
| 5206 | * lock held. It gets the hbalock to access and update SLI data |
| 5207 | * structures. |
| 5208 | * |
| 5209 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5210 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5211 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5212 | irqreturn_t |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5213 | lpfc_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5215 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | uint32_t ha_copy; |
| 5217 | uint32_t work_ha_copy; |
| 5218 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5219 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5220 | uint32_t control; |
| 5221 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5222 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5223 | struct lpfc_vport *vport; |
| 5224 | struct lpfc_nodelist *ndlp; |
| 5225 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5226 | LPFC_MBOXQ_t *pmb; |
| 5227 | int rc; |
| 5228 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5229 | /* |
| 5230 | * Get the driver's phba structure from the dev_id and |
| 5231 | * assume the HBA is not interrupting. |
| 5232 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5233 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | |
| 5235 | if (unlikely(!phba)) |
| 5236 | return IRQ_NONE; |
| 5237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5239 | * Stuff needs to be attented to when this function is invoked as an |
| 5240 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5241 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5242 | if (phba->intr_type == MSIX) { |
| 5243 | /* If the pci channel is offline, ignore all the interrupts */ |
| 5244 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5245 | return IRQ_NONE; |
| 5246 | /* Update device-level interrupt statistics */ |
| 5247 | phba->sli.slistat.sli_intr++; |
| 5248 | /* Ignore all interrupts during initialization. */ |
| 5249 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5250 | return IRQ_NONE; |
| 5251 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5252 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5253 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5254 | /* If somebody is waiting to handle an eratt don't process it |
| 5255 | * here. The brdkill function will do this. |
| 5256 | */ |
| 5257 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5258 | ha_copy &= ~HA_ERATT; |
| 5259 | /* Check the need for handling ERATT in interrupt handler */ |
| 5260 | if (ha_copy & HA_ERATT) { |
| 5261 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5262 | /* ERATT polling has handled ERATT */ |
| 5263 | ha_copy &= ~HA_ERATT; |
| 5264 | else |
| 5265 | /* Indicate interrupt handler handles ERATT */ |
| 5266 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5267 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5268 | |
| 5269 | /* |
| 5270 | * If there is deferred error attention, do not check for any |
| 5271 | * interrupt. |
| 5272 | */ |
| 5273 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5274 | spin_unlock_irq(&phba->hbalock); |
| 5275 | return IRQ_NONE; |
| 5276 | } |
| 5277 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5278 | /* Clear up only attention source related to slow-path */ |
| 5279 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 5280 | phba->HAregaddr); |
| 5281 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5282 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5283 | } else |
| 5284 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5285 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5287 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5288 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | if (work_ha_copy & HA_LATT) { |
| 5290 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5291 | /* |
| 5292 | * Turn off Link Attention interrupts |
| 5293 | * until CLEAR_LA done |
| 5294 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5295 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5297 | control = readl(phba->HCregaddr); |
| 5298 | control &= ~HC_LAINT_ENA; |
| 5299 | writel(control, phba->HCregaddr); |
| 5300 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5301 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | } |
| 5303 | else |
| 5304 | work_ha_copy &= ~HA_LATT; |
| 5305 | } |
| 5306 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5307 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5308 | /* |
| 5309 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5310 | * the only slow ring. |
| 5311 | */ |
| 5312 | status = (work_ha_copy & |
| 5313 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5314 | status >>= (4*LPFC_ELS_RING); |
| 5315 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5316 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5317 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5318 | |
| 5319 | lpfc_debugfs_slow_ring_trc(phba, |
| 5320 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5321 | control, status, |
| 5322 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5323 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5324 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5325 | lpfc_debugfs_slow_ring_trc(phba, |
| 5326 | "ISR Disable ring:" |
| 5327 | "pwork:x%x hawork:x%x wait:x%x", |
| 5328 | phba->work_ha, work_ha_copy, |
| 5329 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5330 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5331 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5332 | control &= |
| 5333 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5334 | writel(control, phba->HCregaddr); |
| 5335 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5336 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5337 | else { |
| 5338 | lpfc_debugfs_slow_ring_trc(phba, |
| 5339 | "ISR slow ring: pwork:" |
| 5340 | "x%x hawork:x%x wait:x%x", |
| 5341 | phba->work_ha, work_ha_copy, |
| 5342 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5343 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5344 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5345 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | } |
| 5347 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5348 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5349 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5350 | lpfc_sli_read_hs(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5351 | /* |
| 5352 | * Check if there is a deferred error condition |
| 5353 | * is active |
| 5354 | */ |
| 5355 | if ((HS_FFER1 & phba->work_hs) && |
| 5356 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 5357 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 5358 | phba->hba_flag |= DEFER_ERATT; |
| 5359 | /* Clear all interrupt enable conditions */ |
| 5360 | writel(0, phba->HCregaddr); |
| 5361 | readl(phba->HCregaddr); |
| 5362 | } |
| 5363 | } |
| 5364 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5365 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5366 | pmb = phba->sli.mbox_active; |
| 5367 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5368 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5369 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5370 | |
| 5371 | /* First check out the status word */ |
| 5372 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5373 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5374 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5375 | /* |
| 5376 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5377 | * mbxStatus <status> |
| 5378 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5379 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5380 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5381 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5382 | "Interrupt mbxCommand x%x " |
| 5383 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5384 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5385 | pmbox->mbxCommand, |
| 5386 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5387 | /* clear mailbox attention bit */ |
| 5388 | work_ha_copy &= ~HA_MBATT; |
| 5389 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5390 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5391 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5392 | phba->last_completion_time = jiffies; |
| 5393 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5394 | if (pmb->mbox_cmpl) { |
| 5395 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5396 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5397 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5398 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5399 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5400 | |
| 5401 | lpfc_debugfs_disc_trc(vport, |
| 5402 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5403 | "MBOX dflt rpi: : " |
| 5404 | "status:x%x rpi:x%x", |
| 5405 | (uint32_t)pmbox->mbxStatus, |
| 5406 | pmbox->un.varWords[0], 0); |
| 5407 | |
| 5408 | if (!pmbox->mbxStatus) { |
| 5409 | mp = (struct lpfc_dmabuf *) |
| 5410 | (pmb->context1); |
| 5411 | ndlp = (struct lpfc_nodelist *) |
| 5412 | pmb->context2; |
| 5413 | |
| 5414 | /* Reg_LOGIN of dflt RPI was |
| 5415 | * successful. new lets get |
| 5416 | * rid of the RPI using the |
| 5417 | * same mbox buffer. |
| 5418 | */ |
| 5419 | lpfc_unreg_login(phba, |
| 5420 | vport->vpi, |
| 5421 | pmbox->un.varWords[0], |
| 5422 | pmb); |
| 5423 | pmb->mbox_cmpl = |
| 5424 | lpfc_mbx_cmpl_dflt_rpi; |
| 5425 | pmb->context1 = mp; |
| 5426 | pmb->context2 = ndlp; |
| 5427 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5428 | rc = lpfc_sli_issue_mbox(phba, |
| 5429 | pmb, |
| 5430 | MBX_NOWAIT); |
| 5431 | if (rc != MBX_BUSY) |
| 5432 | lpfc_printf_log(phba, |
| 5433 | KERN_ERR, |
| 5434 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5435 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5436 | "been MBX_BUSY"); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5437 | goto send_current_mbox; |
| 5438 | } |
| 5439 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5440 | spin_lock_irqsave( |
| 5441 | &phba->pport->work_port_lock, |
| 5442 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5443 | phba->pport->work_port_events &= |
| 5444 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5445 | spin_unlock_irqrestore( |
| 5446 | &phba->pport->work_port_lock, |
| 5447 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5448 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5449 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5450 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5451 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5452 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5453 | if ((work_ha_copy & HA_MBATT) && |
| 5454 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5455 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5456 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5457 | do { |
| 5458 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5459 | MBX_NOWAIT); |
| 5460 | } while (rc == MBX_NOT_FINISHED); |
| 5461 | if (rc != MBX_SUCCESS) |
| 5462 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5463 | LOG_SLI, "0349 rc should be " |
| 5464 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5465 | } |
| 5466 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5467 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5469 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5470 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5471 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5472 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5474 | } /* lpfc_sp_intr_handler */ |
| 5475 | |
| 5476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5477 | * lpfc_fp_intr_handler - The fast-path interrupt handler of lpfc driver |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5478 | * @irq: Interrupt number. |
| 5479 | * @dev_id: The device context pointer. |
| 5480 | * |
| 5481 | * This function is directly called from the PCI layer as an interrupt |
| 5482 | * service routine when the device is enabled with MSI-X multi-message |
| 5483 | * interrupt mode and there is a fast-path FCP IOCB ring event in the |
| 5484 | * HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 5485 | * interrupt mode, this function is called as part of the device-level |
| 5486 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 5487 | * is undergoing initialization, the interrupt handler will not process |
| 5488 | * the interrupt. The SCSI FCP fast-path ring event are handled in the |
| 5489 | * intrrupt context. This function is called without any lock held. It |
| 5490 | * gets the hbalock to access and update SLI data structures. |
| 5491 | * |
| 5492 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5493 | * returns IRQ_NONE. |
| 5494 | **/ |
| 5495 | irqreturn_t |
| 5496 | lpfc_fp_intr_handler(int irq, void *dev_id) |
| 5497 | { |
| 5498 | struct lpfc_hba *phba; |
| 5499 | uint32_t ha_copy; |
| 5500 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5501 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5502 | |
| 5503 | /* Get the driver's phba structure from the dev_id and |
| 5504 | * assume the HBA is not interrupting. |
| 5505 | */ |
| 5506 | phba = (struct lpfc_hba *) dev_id; |
| 5507 | |
| 5508 | if (unlikely(!phba)) |
| 5509 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5510 | |
| 5511 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5512 | * Stuff needs to be attented to when this function is invoked as an |
| 5513 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5515 | if (phba->intr_type == MSIX) { |
| 5516 | /* If pci channel is offline, ignore all the interrupts */ |
| 5517 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5518 | return IRQ_NONE; |
| 5519 | /* Update device-level interrupt statistics */ |
| 5520 | phba->sli.slistat.sli_intr++; |
| 5521 | /* Ignore all interrupts during initialization. */ |
| 5522 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5523 | return IRQ_NONE; |
| 5524 | /* Need to read HA REG for FCP ring and other ring events */ |
| 5525 | ha_copy = readl(phba->HAregaddr); |
| 5526 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5527 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5528 | /* |
| 5529 | * If there is deferred error attention, do not check for |
| 5530 | * any interrupt. |
| 5531 | */ |
| 5532 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5533 | spin_unlock_irq(&phba->hbalock); |
| 5534 | return IRQ_NONE; |
| 5535 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5536 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 5537 | phba->HAregaddr); |
| 5538 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5539 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5540 | } else |
| 5541 | ha_copy = phba->ha_copy; |
| 5542 | |
| 5543 | /* |
| 5544 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 5545 | */ |
| 5546 | ha_copy &= ~(phba->work_ha_mask); |
| 5547 | |
| 5548 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5549 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5550 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | lpfc_sli_handle_fast_ring_event(phba, |
| 5552 | &phba->sli.ring[LPFC_FCP_RING], |
| 5553 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5554 | |
| 5555 | if (phba->cfg_multi_ring_support == 2) { |
| 5556 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5557 | * Process all events on extra ring. Take the optimized path |
| 5558 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5559 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5560 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5561 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5562 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5563 | lpfc_sli_handle_fast_ring_event(phba, |
| 5564 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5565 | status); |
| 5566 | } |
| 5567 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5568 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5569 | } /* lpfc_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5571 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5572 | * lpfc_intr_handler - The device-level interrupt handler of lpfc driver |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5573 | * @irq: Interrupt number. |
| 5574 | * @dev_id: The device context pointer. |
| 5575 | * |
| 5576 | * This function is the device-level interrupt handler called from the PCI |
| 5577 | * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is |
| 5578 | * an event in the HBA which requires driver attention. This function |
| 5579 | * invokes the slow-path interrupt attention handling function and fast-path |
| 5580 | * interrupt attention handling function in turn to process the relevant |
| 5581 | * HBA attention events. This function is called without any lock held. It |
| 5582 | * gets the hbalock to access and update SLI data structures. |
| 5583 | * |
| 5584 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 5585 | * returns IRQ_NONE. |
| 5586 | **/ |
| 5587 | irqreturn_t |
| 5588 | lpfc_intr_handler(int irq, void *dev_id) |
| 5589 | { |
| 5590 | struct lpfc_hba *phba; |
| 5591 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 5592 | unsigned long status1, status2; |
| 5593 | |
| 5594 | /* |
| 5595 | * Get the driver's phba structure from the dev_id and |
| 5596 | * assume the HBA is not interrupting. |
| 5597 | */ |
| 5598 | phba = (struct lpfc_hba *) dev_id; |
| 5599 | |
| 5600 | if (unlikely(!phba)) |
| 5601 | return IRQ_NONE; |
| 5602 | |
| 5603 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 5604 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5605 | return IRQ_NONE; |
| 5606 | |
| 5607 | /* Update device level interrupt statistics */ |
| 5608 | phba->sli.slistat.sli_intr++; |
| 5609 | |
| 5610 | /* Ignore all interrupts during initialization. */ |
| 5611 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5612 | return IRQ_NONE; |
| 5613 | |
| 5614 | spin_lock(&phba->hbalock); |
| 5615 | phba->ha_copy = readl(phba->HAregaddr); |
| 5616 | if (unlikely(!phba->ha_copy)) { |
| 5617 | spin_unlock(&phba->hbalock); |
| 5618 | return IRQ_NONE; |
| 5619 | } else if (phba->ha_copy & HA_ERATT) { |
| 5620 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5621 | /* ERATT polling has handled ERATT */ |
| 5622 | phba->ha_copy &= ~HA_ERATT; |
| 5623 | else |
| 5624 | /* Indicate interrupt handler handles ERATT */ |
| 5625 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5626 | } |
| 5627 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame^] | 5628 | /* |
| 5629 | * If there is deferred error attention, do not check for any interrupt. |
| 5630 | */ |
| 5631 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5632 | spin_unlock_irq(&phba->hbalock); |
| 5633 | return IRQ_NONE; |
| 5634 | } |
| 5635 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5636 | /* Clear attention sources except link and error attentions */ |
| 5637 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5638 | readl(phba->HAregaddr); /* flush */ |
| 5639 | spin_unlock(&phba->hbalock); |
| 5640 | |
| 5641 | /* |
| 5642 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 5643 | */ |
| 5644 | |
| 5645 | /* status of events with mailbox and link attention */ |
| 5646 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 5647 | |
| 5648 | /* status of events with ELS ring */ |
| 5649 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5650 | status2 >>= (4*LPFC_ELS_RING); |
| 5651 | |
| 5652 | if (status1 || (status2 & HA_RXMASK)) |
| 5653 | sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id); |
| 5654 | else |
| 5655 | sp_irq_rc = IRQ_NONE; |
| 5656 | |
| 5657 | /* |
| 5658 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 5659 | */ |
| 5660 | |
| 5661 | /* status of events with FCP ring */ |
| 5662 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5663 | status1 >>= (4*LPFC_FCP_RING); |
| 5664 | |
| 5665 | /* status of events with extra ring */ |
| 5666 | if (phba->cfg_multi_ring_support == 2) { |
| 5667 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5668 | status2 >>= (4*LPFC_EXTRA_RING); |
| 5669 | } else |
| 5670 | status2 = 0; |
| 5671 | |
| 5672 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
| 5673 | fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id); |
| 5674 | else |
| 5675 | fp_irq_rc = IRQ_NONE; |
| 5676 | |
| 5677 | /* Return device-level interrupt handling status */ |
| 5678 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
| 5679 | } /* lpfc_intr_handler */ |